Skip to contentSkip to conversation

kvm: Make pi_enable_wakeup_handler() easier to analyze

PATCH Applied Bart Van Assche 9 participants 37 messages Feb 23 – Feb 26 1 message not in the archive

Subsystems (26)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/62 kvm: Make pi_enable_wakeup_handler() easier to analyze

The Clang thread-safety analyzer does not support comparing expressions that use per_cpu(). Hence introduce a new local variable to capture the address of a per-cpu spinlock. This patch prepares for enabling the Clang thread-safety analyzer.

Cc Sean Christopherson <[email protected]>
Cc Paolo Bonzini <[email protected]>
---
 arch/x86/kvm/vmx/posted_intr.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
arch/x86/kvm/vmx/posted_intr.c +4 -3
index 4a6d9a17da23..f8711b7b85a8 100644
@@ -164,6 +164,7 @@ static void pi_enable_wakeup_handler(struct kvm_vcpu *vcpu)
 	struct pi_desc *pi_desc = vcpu_to_pi_desc(vcpu);
 	struct vcpu_vt *vt = to_vt(vcpu);
 	struct pi_desc old, new;
+	raw_spinlock_t *wakeup_lock;
 
 	lockdep_assert_irqs_disabled();
 
@@ -179,11 +180,11 @@ static void pi_enable_wakeup_handler(struct kvm_vcpu *vcpu)
 	 * entirety of the sched_out critical section, i.e. the wakeup handler
 	 * can't run while the scheduler locks are held.
 	 */
-	raw_spin_lock_nested(&per_cpu(wakeup_vcpus_on_cpu_lock, vcpu->cpu),
-			     PI_LOCK_SCHED_OUT);
+	wakeup_lock = &per_cpu(wakeup_vcpus_on_cpu_lock, vcpu->cpu);
+	raw_spin_lock_nested(wakeup_lock, PI_LOCK_SCHED_OUT);
 	list_add_tail(&vt->pi_wakeup_list,
 		      &per_cpu(wakeup_vcpus_on_cpu, vcpu->cpu));
-	raw_spin_unlock(&per_cpu(wakeup_vcpus_on_cpu_lock, vcpu->cpu));
+	raw_spin_unlock(wakeup_lock);
 
 	WARN(pi_test_sn(pi_desc), "PI descriptor SN field set before blocking");
 
#2 lore raw

PATCH 2/62 blk-ioc: Prepare for enabling thread-safety analysis

In reply to a message not in the archive

The Clang thread-safety analyzer does not support testing return values with "< 0". Hence change the "< 0" test into "!= 0". This is fine since the radix_tree_maybe_preload() return value is <= 0.

---
 block/blk-ioc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/blk-ioc.c +1 -1
index d15918d7fabb..0bf78aebc887 100644
@@ -364,7 +364,7 @@ static struct io_cq *ioc_create_icq(struct request_queue *q)
 	if (!icq)
 		return NULL;
 
-	if (radix_tree_maybe_preload(GFP_ATOMIC) < 0) {
+	if (radix_tree_maybe_preload(GFP_ATOMIC) != 0) {
 		kmem_cache_free(et->icq_cache, icq);
 		return NULL;
 	}
#3 lore raw

Re: [PATCH 02/62] blk-ioc: Prepare for enabling thread-safety analysis

Quoted 3 lines · Bart Van Assche

The Clang thread-safety analyzer does not support testing return values with "< 0". Hence change the "< 0" test into "!= 0". This is fine since the radix_tree_maybe_preload() return value is <= 0.

This is a series with 62 patches, of which only some and not the cover letter made it to linux-block. You're doing something seriously wrong in your patch submission.

#4 lore raw

Re: [PATCH 02/62] blk-ioc: Prepare for enabling thread-safety analysis

Quoted 3 lines · Christoph Hellwig

This is a series with 62 patches, of which only some and not the cover letter made it to linux-block. You're doing something seriously wrong in your patch submission.

The two SMTP servers that I tried (smtpauth.mailroute.net and smtp.migadu.com) gave up about halfway this patch series (quota exceeded / too many recipients).

Peter Zijlstra asked me to split this series and to send the patches from this series directly to the maintainers of the affected code rather than to send these patches as one large patch series to him.

Thanks,

Bart.

#5 lore raw

PATCH 3/62 drbd: Balance RCU calls in drbd_adm_dump_devices()

In reply to a message not in the archive

Make drbd_adm_dump_devices() call rcu_read_lock() before rcu_read_unlock() is called. This has been detected by the Clang thread-safety analyzer. Compile-tested only.

Cc Andreas Gruenbacher <[email protected]>
Fixes a55bbd375d18 ("drbd: Backport the "status" command")
---
 drivers/block/drbd/drbd_nl.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/block/drbd/drbd_nl.c +6 -2
index e201f0087a0f..728ecc431b38 100644
@@ -3378,8 +3378,10 @@ int drbd_adm_dump_devices(struct sk_buff *skb, struct netlink_callback *cb)
 		if (resource_filter) {
 			retcode = ERR_RES_NOT_KNOWN;
 			resource = drbd_find_resource(nla_data(resource_filter));
-			if (!resource)
+			if (!resource) {
+				rcu_read_lock();
 				goto put_result;
+			}
 			cb->args[0] = (long)resource;
 		}
 	}
@@ -3628,8 +3630,10 @@ int drbd_adm_dump_peer_devices(struct sk_buff *skb, struct netlink_callback *cb)
 		if (resource_filter) {
 			retcode = ERR_RES_NOT_KNOWN;
 			resource = drbd_find_resource(nla_data(resource_filter));
-			if (!resource)
+			if (!resource) {
+				rcu_read_lock();
 				goto put_result;
+			}
 		}
 		cb->args[0] = (long)resource;
 	}
maintainer Tested-by on v1 3/62
#6 lore raw

Re: [PATCH 03/62] drbd: Balance RCU calls in drbd_adm_dump_devices()

Am 23.02.26 um 22:48 schrieb Bart Van Assche:

Quoted 31 lines

Make drbd_adm_dump_devices() call rcu_read_lock() before rcu_read_unlock() is called. This has been detected by the Clang thread-safety analyzer. Compile-tested only.

Cc Andreas Gruenbacher <[email protected]>
Fixes a55bbd375d18 ("drbd: Backport the "status" command")
---
 drivers/block/drbd/drbd_nl.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/block/drbd/drbd_nl.c +3 -1
index e201f0087a0f..728ecc431b38 100644
@@ -3378,8 +3378,10 @@ int drbd_adm_dump_devices(struct sk_buff *skb, struct netlink_callback *cb)
 		if (resource_filter) {
 			retcode = ERR_RES_NOT_KNOWN;
 			resource = drbd_find_resource(nla_data(resource_filter));
-			if (!resource)
+			if (!resource) {
+				rcu_read_lock();
 				goto put_result;
+			}
 			cb->args[0] = (long)resource;
 		}
 	}
@@ -3628,8 +3630,10 @@ int drbd_adm_dump_peer_devices(struct sk_buff *skb, struct netlink_callback *cb)
 		if (resource_filter) {

drivers/block/drbd/drbd_nl.c int drbd_adm_dump_peer_devices(struct sk_buff *skb, struct netlink_callback *cb) · line 3639

Quoted 10 lines
drivers/block/drbd/drbd_nl.c +3 -1
 			retcode = ERR_RES_NOT_KNOWN;
 			resource = drbd_find_resource(nla_data(resource_filter));
-			if (!resource)
+			if (!resource) {
+				rcu_read_lock();
 				goto put_result;
+			}
 		}
 		cb->args[0] = (long)resource;
 	}

Passes our internal DRBD test suite.

Signature · 3 lines
Christoph Böhmwalder
LINBIT | Keeping the Digital World Running
DRBD HA —  Disaster Recovery — Software defined Storage
#7 lore raw

PATCH 4/62 dax/bus.c: Fix a locking bug

In reply to a message not in the archive

Only unlock dax_dev_rwsem if it has been locked. This locking bug was detected by the Clang thread-safety analyzer.

Cc Dan Williams <[email protected]>
Cc Vishal Verma <[email protected]>
Cc Dave Jiang <[email protected]>
Cc Alison Schofield <[email protected]>
Fixes c05ae9d85b47 ("dax/bus.c: replace driver-core lock usage by a local rwsem")
---
 drivers/dax/bus.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/dax/bus.c +1 -2
index c94c09622516..ebd3806c34e5 100644
@@ -1117,11 +1117,10 @@ static ssize_t size_store(struct device *dev, struct device_attribute *attr,
 	}
 	rc = down_write_killable(&dax_dev_rwsem);
 	if (rc)
-		goto err_dev;
+		goto err_region;
 
 	rc = dev_dax_resize(dax_region, dev_dax, val);
 
-err_dev:
 	up_write(&dax_dev_rwsem);
 err_region:
 	up_write(&dax_region_rwsem);
#8 lore raw

PATCH 5/62 dma-buf: Convert dma_buf_import_sync_file() to the early-return style

In reply to a message not in the archive

Before making changes in dma_buf_import_sync_file(), convert it to the early-return coding style. No functionality has been changed.

---
 drivers/dma-buf/dma-buf.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/dma-buf/dma-buf.c +6 -4
index 11711874a325..1666133ac8b8 100644
@@ -523,11 +523,13 @@ static long dma_buf_import_sync_file(struct dma_buf *dmabuf,
 		dma_resv_lock(dmabuf->resv, NULL);
 
 		ret = dma_resv_reserve_fences(dmabuf->resv, num_fences);
-		if (!ret) {
-			dma_fence_unwrap_for_each(f, &iter, fence)
-				dma_resv_add_fence(dmabuf->resv, f, usage);
-		}
+		if (ret)
+			goto unlock;
+
+		dma_fence_unwrap_for_each(f, &iter, fence)
+			dma_resv_add_fence(dmabuf->resv, f, usage);
 
+unlock:
 		dma_resv_unlock(dmabuf->resv);
 	}
 
maintainer
#9 lore raw

Re: [PATCH 05/62] dma-buf: Convert dma_buf_import_sync_file() to the early-return style

Quoted 18 lines · Bart Van Assche

Before making changes in dma_buf_import_sync_file(), convert it to the early-return coding style. No functionality has been changed.

---
 drivers/dma-buf/dma-buf.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/dma-buf/dma-buf.c +0 -0
index 11711874a325..1666133ac8b8 100644
@@ -523,11 +523,13 @@ static long dma_buf_import_sync_file(struct dma_buf *dmabuf,
                dma_resv_lock(dmabuf->resv, NULL);
 

drivers/dma-buf/dma-buf.c static long dma_buf_import_sync_file(struct dma_buf *dmabuf, · line 530

Quoted 10 lines
drivers/dma-buf/dma-buf.c +5 -4
                ret = dma_resv_reserve_fences(dmabuf->resv, num_fences);
-               if (!ret) {
-                       dma_fence_unwrap_for_each(f, &iter, fence)
-                               dma_resv_add_fence(dmabuf->resv, f, usage);
-               }
+               if (ret)
+                       goto unlock;
+
+               dma_fence_unwrap_for_each(f, &iter, fence)
+                       dma_resv_add_fence(dmabuf->resv, f, usage);

Mhm, I don't see what this is good for?

While this might look a little bit nicer we don't enforce this coding style and it adds more loc.

Regards,
Christian.

Quoted 5 lines
drivers/dma-buf/dma-buf.c +1 -0
+unlock:
                dma_resv_unlock(dmabuf->resv);
        }
 
#10 lore raw

Re: [PATCH 05/62] dma-buf: Convert dma_buf_import_sync_file() to the early-return style

Quoted 21 lines · Christian König
Quoted 7 lines · Bart Van Assche
drivers/dma-buf/dma-buf.c +0 -0
index 11711874a325..1666133ac8b8 100644
@@ -523,11 +523,13 @@ static long dma_buf_import_sync_file(struct dma_buf *dmabuf,
                 dma_resv_lock(dmabuf->resv, NULL);
 

drivers/dma-buf/dma-buf.c static long dma_buf_import_sync_file(struct dma_buf *dmabuf, · line 530

Quoted 10 lines
drivers/dma-buf/dma-buf.c +5 -4
                 ret = dma_resv_reserve_fences(dmabuf->resv, num_fences);
-               if (!ret) {
-                       dma_fence_unwrap_for_each(f, &iter, fence)
-                               dma_resv_add_fence(dmabuf->resv, f, usage);
-               }
+               if (ret)
+                       goto unlock;
+
+               dma_fence_unwrap_for_each(f, &iter, fence)
+                       dma_resv_add_fence(dmabuf->resv, f, usage);

Mhm, I don't see what this is good for?

Quoted 1 line

While this might look a little bit nicer we don't enforce this coding style and it adds more loc.

Hi Christian,

I will drop this change.

Thanks,

Bart.

#11 lore raw

PATCH 6/62 dma-buf: Handle all dma_resv_lock() errors

In reply to a message not in the archive

Instead of assuming that dma_resv_lock() only returns 0 or -EDEADLK, handle all possible dma_resv_lock() return values. This patch prepares for enabling compile-time thread-safety analysis. This will cause the compiler to check whether all dma_resv_lock() return values are handled.

---
 drivers/dma-buf/dma-resv.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/dma-buf/dma-resv.c +5 -1
index bea3e9858aca..b4710f730e9b 100644
@@ -792,6 +792,8 @@ static int __init dma_resv_lockdep(void)
 	ret = dma_resv_lock(&obj, &ctx);
 	if (ret == -EDEADLK)
 		dma_resv_lock_slow(&obj, &ctx);
+	else if (ret)
+		goto fini;
 	fs_reclaim_acquire(GFP_KERNEL);
 	/* for unmap_mapping_range on trylocked buffer objects in shrinkers */
 	i_mmap_lock_write(&mapping);
@@ -805,12 +807,14 @@ static int __init dma_resv_lockdep(void)
 #endif
 	fs_reclaim_release(GFP_KERNEL);
 	ww_mutex_unlock(&obj.lock);
+
+fini:
 	ww_acquire_fini(&ctx);
 	mmap_read_unlock(mm);
 
 	mmput(mm);
 
-	return 0;
+	return ret;
 }
 subsys_initcall(dma_resv_lockdep);
 #endif
maintainer
#12 lore raw

Re: [PATCH 06/62] dma-buf: Handle all dma_resv_lock() errors

Quoted 18 lines · Bart Van Assche

Instead of assuming that dma_resv_lock() only returns 0 or -EDEADLK, handle all possible dma_resv_lock() return values. This patch prepares for enabling compile-time thread-safety analysis. This will cause the compiler to check whether all dma_resv_lock() return values are handled.

---
 drivers/dma-buf/dma-resv.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/dma-buf/dma-resv.c +0 -0
index bea3e9858aca..b4710f730e9b 100644

drivers/dma-buf/dma-resv.c static int __init dma_resv_lockdep(void) · line 796

Quoted 5 lines
drivers/dma-buf/dma-resv.c +2 -0
@@ -792,6 +792,8 @@ static int __init dma_resv_lockdep(void)
        ret = dma_resv_lock(&obj, &ctx);
        if (ret == -EDEADLK)
                dma_resv_lock_slow(&obj, &ctx);
+       else if (ret)
+               goto fini;

Mhm, that looks a bit questionable to me. Only checking for EDEADLK was intentional.

Quoted 7 lines
drivers/dma-buf/dma-resv.c +0 -0
        fs_reclaim_acquire(GFP_KERNEL);
        /* for unmap_mapping_range on trylocked buffer objects in shrinkers */
        i_mmap_lock_write(&mapping);
@@ -805,12 +807,14 @@ static int __init dma_resv_lockdep(void)
 #endif
        fs_reclaim_release(GFP_KERNEL);
        ww_mutex_unlock(&obj.lock);

drivers/dma-buf/dma-resv.c static int __init dma_resv_lockdep(void) · line 818

Quoted 10 lines
drivers/dma-buf/dma-resv.c +3 -1
+
+fini:
        ww_acquire_fini(&ctx);
        mmap_read_unlock(mm);
 
        mmput(mm);
 
 
-       return 0;
+       return ret;

Oh! This is an *absolutely* clear NAK for that change.

This code here is to only improve debugging messages, so it's not problematic at all if it fails.

If I'm not completely mistaken if you return the error code the whole kernel would fail to boot *and* we have a random error injection feature for testing which makes it returning an error randomly!

So this change here would result in randomly not booting kernels and that is something we seriously can't do :)

We could add code which prints and error if ret is something else than 0 or EDEADLK, but that case is already covered by the selftests and so would be 100% dead code.

Why exactly do you need that? Would a code comment explaining the background be helpful?

Regards,
Christian.

Quoted 3 lines
drivers/dma-buf/dma-resv.c +0 -0
 }
 subsys_initcall(dma_resv_lockdep);

#endif

#13 lore raw

Re: [PATCH 06/62] dma-buf: Handle all dma_resv_lock() errors

Quoted 2 lines · Christian König

Why exactly do you need that? Would a code comment explaining the background be helpful?

dma_resv_lock() has been annotated with __cond_acquires(0, &obj->lock)
and dma_resv_unlock() has been annotated with __releases(&obj->lock). Hence, with thread-safety analysis enabled, Clang complains about dma_resv_unlock() calls if dma_resv_lock() returns an error code. There are several possibilities for suppressing Clang's thread- safety warnings:
* The least elegant is to annotate dma_resv_lockdep() with __no_context_analysis and to add a comment.
* A better option is to rework the code such that dma_resv_unlock() is not called if dma_resv_lock() returns an error code. That is what I tried to do. There may be better alternatives than my patch.

Thanks,

Bart.

maintainer
#14 lore raw

Re: [PATCH 06/62] dma-buf: Handle all dma_resv_lock() errors

Hi Bart,

Quoted 11 lines · Bart Van Assche
Quoted 2 lines · Christian König

Why exactly do you need that? Would a code comment explaining the background be helpful?

dma_resv_lock() has been annotated with    __cond_acquires(0, &obj->lock) and dma_resv_unlock() has been annotated with __releases(&obj->lock). Hence, with thread-safety analysis enabled, Clang complains about dma_resv_unlock() calls if dma_resv_lock() returns an error code. There are several possibilities for suppressing Clang's thread- safety warnings:
* The least elegant is to annotate dma_resv_lockdep() with __no_context_analysis and to add a comment.

Yeah, that is clearly a bad idea.

There are basically only two places were we have to ignore this:

1. The dma_resv_lockdep() function you stumbled over.

2. Some selftest we used to have which intentionally got it wrong to check if lockdep correctly complains about it. (You most likely already excluded that somehow).

Every other code should definitely have this analysis.

Is it somehow possible to annotate only the dma_resv_lockdep() function?

Quoted 3 lines

* A better option is to rework the code such that dma_resv_unlock() is not called if dma_resv_lock() returns an error code. That is what I tried to do. There may be better alternatives than my patch.

That would be dead code which is never used at all and only there to silence the warning. That is usually also a rather bad idea.

Would it help if we change the code like this?

        ret = dma_resv_lock(&obj, &ctx);
-       if (ret == -EDEADLK)
+       /* Only EDEADLK from the error injection is possible here */
+       if (ret)
                dma_resv_lock_slow(&obj, &ctx);

Thanks,
Christian.

Quoted 4 lines

Thanks,

Bart.

#15 lore raw

Re: [PATCH 06/62] dma-buf: Handle all dma_resv_lock() errors

Review

Quoted 7 lines · Christian König

Would it help if we change the code like this?

         ret = dma_resv_lock(&obj, &ctx);
(quoted diff) +2 -1
-       if (ret == -EDEADLK)
+       /* Only EDEADLK from the error injection is possible here */
+       if (ret)
                 dma_resv_lock_slow(&obj, &ctx);

Yes, the above is sufficient to suppress the Clang thread-safety warning for dma_resv_lockdep(). Is a source code comment about EDEADLK preferred or would the following perhaps also be acceptable?

drivers/dma-buf/dma-resv.c +3 -1
index bea3e9858aca..4d65dddbcbdf 100644
@@ -790,8 +790,10 @@ static int __init dma_resv_lockdep(void)
        mmap_read_lock(mm);
        ww_acquire_init(&ctx, &reservation_ww_class);
        ret = dma_resv_lock(&obj, &ctx);
-       if (ret == -EDEADLK)
+       if (ret) {
+               WARN_ON_ONCE(ret != -EDEADLK);
                dma_resv_lock_slow(&obj, &ctx);
+       }
        fs_reclaim_acquire(GFP_KERNEL);
        /* for unmap_mapping_range on trylocked buffer objects in 

shrinkers */

        i_mmap_lock_write(&mapping);

Thanks,

Bart.

maintainer
#16 lore raw

Re: [PATCH 06/62] dma-buf: Handle all dma_resv_lock() errors

Quoted 11 lines · Bart Van Assche
Quoted 7 lines · Christian König

Would it help if we change the code like this?

         ret = dma_resv_lock(&obj, &ctx);
-       if (ret == -EDEADLK)
+       /* Only EDEADLK from the error injection is possible here */ +       if (ret)
                 dma_resv_lock_slow(&obj, &ctx);

Yes, the above is sufficient to suppress the Clang thread-safety warning for dma_resv_lockdep().

Cool, then let us use this approach here.

Quoted 2 lines

Is a source code comment about EDEADLK preferred or would the following perhaps also be acceptable?

I think the warning is optional, but potentially good to have as well.

But the code comment is mandatory, otherwise we will have forgotten in 10 years why exactly only EDEADLK can happen here.

drivers/dma-buf/dma-resv.c static int __init dma_resv_lockdep(void) · line 794

Quoted 12 lines
drivers/dma-buf/dma-resv.c +2 -1
index bea3e9858aca..4d65dddbcbdf 100644
@@ -790,8 +790,10 @@ static int __init dma_resv_lockdep(void)
         mmap_read_lock(mm);
         ww_acquire_init(&ctx, &reservation_ww_class);
         ret = dma_resv_lock(&obj, &ctx);
-       if (ret == -EDEADLK)
+       if (ret) {
+               WARN_ON_ONCE(ret != -EDEADLK);

Please make that only WARN_ON(). I would be massively surprised when a subsystem initcall executes more than once.

Thanks,
Christian.

Quoted 9 lines
drivers/dma-buf/dma-resv.c +1 -0
                 dma_resv_lock_slow(&obj, &ctx);
+       }
         fs_reclaim_acquire(GFP_KERNEL);
         /* for unmap_mapping_range on trylocked buffer objects in shrinkers */
         i_mmap_lock_write(&mapping);

Thanks,

Bart.

#17 lore raw

PATCH 7/62 drm/amdgpu: Unlock a mutex before destroying it

In reply to a message not in the archive

Mutexes must be unlocked before these are destroyed. This has been detected by the Clang thread-safety analyzer.

Cc Alex Deucher <[email protected]>
Cc Christian König <[email protected]>
Cc Yang Wang <[email protected]>
Cc Hawking Zhang <[email protected]>
Fixes f5e4cc8461c4 ("drm/amdgpu: implement RAS ACA driver framework")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c +1 -0
index afe5ca81beec..db7858fe0c3d 100644
@@ -641,6 +641,7 @@ static void aca_error_fini(struct aca_error *aerr)
 		aca_bank_error_remove(aerr, bank_error);
 
 out_unlock:
+	mutex_unlock(&aerr->lock);
 	mutex_destroy(&aerr->lock);
 }
 
#18 lore raw

PATCH 8/62 drm/amdgpu: Fix locking bugs in error paths

In reply to a message not in the archive

Do not unlock psp->ras_context.mutex if it has not been locked. This has been detected by the Clang thread-safety analyzer.

Cc Alex Deucher <[email protected]>
Cc Christian König <[email protected]>
Cc YiPeng Chai <[email protected]>
Cc Hawking Zhang <[email protected]>
Fixes b3fb79cda568 ("drm/amdgpu: add mutex to protect ras shared memory")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c +7 -5
index 6e8aad91bcd3..0d3c18f04ac3 100644
@@ -332,13 +332,13 @@ static ssize_t ta_if_invoke_debugfs_write(struct file *fp, const char *buf, size
 	if (!context || !context->initialized) {
 		dev_err(adev->dev, "TA is not initialized\n");
 		ret = -EINVAL;
-		goto err_free_shared_buf;
+		goto free_shared_buf;
 	}
 
 	if (!psp->ta_funcs || !psp->ta_funcs->fn_ta_invoke) {
 		dev_err(adev->dev, "Unsupported function to invoke TA\n");
 		ret = -EOPNOTSUPP;
-		goto err_free_shared_buf;
+		goto free_shared_buf;
 	}
 
 	context->session_id = ta_id;
@@ -346,7 +346,7 @@ static ssize_t ta_if_invoke_debugfs_write(struct file *fp, const char *buf, size
 	mutex_lock(&psp->ras_context.mutex);
 	ret = prep_ta_mem_context(&context->mem_context, shared_buf, shared_buf_len);
 	if (ret)
-		goto err_free_shared_buf;
+		goto unlock;
 
 	ret = psp_fn_ta_invoke(psp, cmd_id);
 	if (ret || context->resp_status) {
@@ -354,15 +354,17 @@ static ssize_t ta_if_invoke_debugfs_write(struct file *fp, const char *buf, size
 			ret, context->resp_status);
 		if (!ret) {
 			ret = -EINVAL;
-			goto err_free_shared_buf;
+			goto unlock;
 		}
 	}
 
 	if (copy_to_user((char *)&buf[copy_pos], context->mem_context.shared_buf, shared_buf_len))
 		ret = -EFAULT;
 
-err_free_shared_buf:
+unlock:
 	mutex_unlock(&psp->ras_context.mutex);
+
+free_shared_buf:
 	kfree(shared_buf);
 
 	return ret;
#19 lore raw

PATCH 13/62 drm/qxl: Fix a buffer leak in an error path

In reply to a message not in the archive

If qxl_bo_reserve() succeeds, call qxl_bo_unreserve() instead of skipping that call.

This has been detected by the Clang thread-safety analyzer. Compile-tested only.

Cc Dave Airlie <[email protected]>
Cc Gerd Hoffmann <[email protected]>
Fixes f64122c1f6ad ("drm: add new QXL driver. (v1.4)")
---
 drivers/gpu/drm/qxl/qxl_ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/qxl/qxl_ioctl.c +1 -1
index 4ee2b5acf2e0..5617811f3c9b 100644
@@ -323,7 +323,7 @@ int qxl_update_area_ioctl(struct drm_device *dev, void *data, struct drm_file *f
 		qxl_ttm_placement_from_domain(qobj, qobj->type);
 		ret = ttm_bo_validate(&qobj->tbo, &qobj->placement, &ctx);
 		if (unlikely(ret))
-			goto out;
+			goto out2;
 	}
 
 	ret = qxl_bo_check_id(qdev, qobj);
#20 lore raw

PATCH 14/62 hwmon: (it87) Check the it87_lock() return value

In reply to a message not in the archive

Return early in it87_resume() if it87_lock() fails instead of ignoring the return value of that function. This patch suppresses a Clang thread-safety warning.

Cc Frank Crawford <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc Jean Delvare <[email protected]>
Fixes 376e1a937b30 ("hwmon: (it87) Add calls to smbus_enable/smbus_disable as required")
---
 drivers/hwmon/it87.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/hwmon/it87.c +3 -1
index e233aafa8856..8e3935089fca 100644
@@ -3593,7 +3593,9 @@ static int it87_resume(struct device *dev)
 
 	it87_resume_sio(pdev);
 
-	it87_lock(data);
+	int err = it87_lock(data);
+	if (err)
+		return err;
 
 	it87_check_pwm(dev);
 	it87_check_limit_regs(data);
#21 lore raw

PATCH 15/62 Input: synaptics-rmi4 - fix a locking bug in an error path

In reply to a message not in the archive

Lock f54->data_mutex before the first 'goto error' statement since jumping to the 'error' label causes that mutex to be unlocked.

This bug has been detected by the Clang thread-safety checker.

Cc Dmitry Torokhov <[email protected]>
Cc Nick Dyer <[email protected]>
Fixes 3a762dbd5347 ("[media] Input: synaptics-rmi4 - add support for F54 diagnostics")
---
 drivers/input/rmi4/rmi_f54.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/input/rmi4/rmi_f54.c +3 -2
index ac4041a69fcd..fd57ebb1cb50 100644
@@ -539,6 +539,9 @@ static void rmi_f54_work(struct work_struct *work)
 	int i;
 
 	report_size = rmi_f54_get_report_size(f54);
+
+	mutex_lock(&f54->data_mutex);
+
 	if (report_size == 0) {
 		dev_err(&fn->dev, "Bad report size, report type=%d\n",
 				f54->report_type);
@@ -546,8 +549,6 @@ static void rmi_f54_work(struct work_struct *work)
 		goto error;     /* retry won't help */
 	}
 
-	mutex_lock(&f54->data_mutex);
-
 	/*
 	 * Need to check if command has completed.
 	 * If not try again later.
#22 lore raw

PATCH 16/62 md: Make mddev_suspend() easier to analyze

In reply to a message not in the archive

Prepare for enabling Clang's thread-safety analysis by moving an if-statement. No functionality has been changed.

---
 drivers/md/md.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/md/md.c +5 -4
index 3ce6f9e9d38e..b0d260d03a7d 100644
@@ -475,12 +475,13 @@ int mddev_suspend(struct mddev *mddev, bool interruptible)
 	 */
 	lockdep_assert_not_held(&mddev->reconfig_mutex);
 
-	if (interruptible)
+	if (interruptible) {
 		err = mutex_lock_interruptible(&mddev->suspend_mutex);
-	else
+		if (err)
+			return err;
+	} else {
 		mutex_lock(&mddev->suspend_mutex);
-	if (err)
-		return err;
+	}
 
 	if (mddev->suspended) {
 		WRITE_ONCE(mddev->suspended, mddev->suspended + 1);
#23 lore raw

Re: [PATCH 16/62] md: Make mddev_suspend() easier to analyze

Dear Bart,

Thank you for the patch.

Am 23.02.26 um 22:49 schrieb Bart Van Assche:

Quoted 2 lines

Prepare for enabling Clang's thread-safety analysis by moving an if-statement. No functionality has been changed.

Why does the if-statement need to be moved? Could you explain it in the commit message?

Quoted 21 lines
---
  drivers/md/md.c | 9 +++++----
  1 file changed, 5 insertions(+), 4 deletions(-)
drivers/md/md.c +1 -2
index 3ce6f9e9d38e..b0d260d03a7d 100644
@@ -475,12 +475,13 @@ int mddev_suspend(struct mddev *mddev, bool interruptible)
  	 */
  	lockdep_assert_not_held(&mddev->reconfig_mutex);
 
-	if (interruptible)
+	if (interruptible) {
  		err = mutex_lock_interruptible(&mddev->suspend_mutex);
-	else

drivers/md/md.c int mddev_suspend(struct mddev *mddev, bool interruptible) · line 487

Quoted 10 lines
drivers/md/md.c +4 -2
+		if (err)
+			return err;
+	} else {
  		mutex_lock(&mddev->suspend_mutex);
-	if (err)
-		return err;
+	}
 
  	if (mddev->suspended) {
  		WRITE_ONCE(mddev->suspended, mddev->suspended + 1);

Kind regards,

Paul

#24 lore raw

PATCH 17/62 bnxt_en: Make bnxt_resume() easier to analyze

In reply to a message not in the archive

Pass the same argument to netdev_lock() and netdev_unlock(). This patch prepares for enabling the Clang thread-safety analysis functionality. No functional change intended.

---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1 -1
index e062d5d400da..950708575268 100644
@@ -17121,7 +17121,7 @@ static int bnxt_resume(struct device *device)
 	}
 
 resume_exit:
-	netdev_unlock(bp->dev);
+	netdev_unlock(dev);
 	bnxt_ulp_start(bp, rc);
 	if (!rc)
 		bnxt_reenable_sriov(bp);
maintainer
#25 lore raw

Re: [PATCH 17/62] bnxt_en: Make bnxt_resume() easier to analyze

Quoted 3 lines · On Mon, 23 Feb 2026 13:49:05 -0800 Bart Van Assche wrote:

Pass the same argument to netdev_lock() and netdev_unlock(). This patch prepares for enabling the Clang thread-safety analysis functionality. No functional change intended.

Please split out the 13(?) netdev patches to a separate series. If you CC us on a subset of the series out CI will not test it. Please keep in mind that we ask to wait at least 24h between resubmissions

Signature · 1 line
pw-bot: cr
maintainer
#26 lore raw

Re: [PATCH 17/62] bnxt_en: Make bnxt_resume() easier to analyze

Quoted 9 lines · On Mon, 23 Feb 2026 14:23:44 -0800 Jakub Kicinski wrote:
Quoted 3 lines · On Mon, 23 Feb 2026 13:49:05 -0800 Bart Van Assche wrote:

Pass the same argument to netdev_lock() and netdev_unlock(). This patch prepares for enabling the Clang thread-safety analysis functionality. No functional change intended.

Please split out the 13(?) netdev patches to a separate series. If you CC us on a subset of the series out CI will not test it. Please keep in mind that we ask to wait at least 24h between resubmissions

Oh, not 13, 5, you already spammed us 3 times with this. Sigh.

#27 lore raw

Re: [PATCH 17/62] bnxt_en: Make bnxt_resume() easier to analyze

Quoted 1 line · Jakub Kicinski

Oh, not 13, 5, you already spammed us 3 times with this. Sigh.

Sorry for the spam. I have not yet found an SMTP server that can post the entire patch series without reporting an error message halfway.

smtpauth.mailroute.net reported "quota exceeded" while
smtp.migadu.com reported "4.7.1 Error: too many recipients from 2a00:79e0:2e7c:8:b343:b0de:3e59:4e65".

Bart.

#28 lore raw

PATCH 18/62 bnxt_en: Fix bnxt_dl_reload_up()

In reply to a message not in the archive

bnxt_dl_reload_down() calls rtnl_lock() and netdev_lock() if it returns
0. Hence, bnxt_dl_reload_up() should invoke the corresponding unlock calls. This issue has been detected by the clang thread-sanitizer. Compile-tested only.

Cc Jakub Kicinski <[email protected]>
Cc Shantiprasad Shettar <[email protected]>
Cc Stanislav Fomichev <[email protected]>
Fixes 004b5008016a ("eth: bnxt: remove most dependencies on RTNL")
---
 drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c +2 -0
index 15de802bbac4..1e9a3454bb29 100644
@@ -562,6 +562,8 @@ static int bnxt_dl_reload_up(struct devlink *dl, enum devlink_reload_action acti
 		break;
 	}
 	default:
+		netdev_unlock(bp->dev);
+		rtnl_unlock();
 		return -EOPNOTSUPP;
 	}
 
maintainer
#29 lore raw

Re: [PATCH 18/62] bnxt_en: Fix bnxt_dl_reload_up()

.

Quoted 21 lines · Bart Van Assche

bnxt_dl_reload_down() calls rtnl_lock() and netdev_lock() if it returns
0. Hence, bnxt_dl_reload_up() should invoke the corresponding unlock calls. This issue has been detected by the clang thread-sanitizer. Compile-tested only.

Cc Jakub Kicinski <[email protected]>
Cc Shantiprasad Shettar <[email protected]>
Cc Stanislav Fomichev <[email protected]>
Fixes 004b5008016a ("eth: bnxt: remove most dependencies on RTNL")
---
 drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c +0 -0
index 15de802bbac4..1e9a3454bb29 100644

drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c static int bnxt_dl_reload_up(struct devlink *dl, enum devlink_reload_action acti · line 566

Quoted 5 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c +2 -0
@@ -562,6 +562,8 @@ static int bnxt_dl_reload_up(struct devlink *dl, enum devlink_reload_action acti
                break;
        }
        default:
+               netdev_unlock(bp->dev);
+               rtnl_unlock();

This doesn't look correct. The 2 locks are taken in bnxt_dl_reload_down() only for the 2 actions DEVLINK_RELOAD_ACTION_DRIVER_REINIT and DEVLINK_RELOAD_ACTION_FW_ACTIVATE. For the default action, no locks are taken so I don't think we should unlock here.

#30 lore raw

Re: [PATCH 18/62] bnxt_en: Fix bnxt_dl_reload_up()

Quoted 18 lines · Michael Chan

.

Quoted 16 lines · Bart Van Assche

bnxt_dl_reload_down() calls rtnl_lock() and netdev_lock() if it returns
0. Hence, bnxt_dl_reload_up() should invoke the corresponding unlock calls. This issue has been detected by the clang thread-sanitizer. Compile-tested only.

Cc Jakub Kicinski <[email protected]>
Cc Shantiprasad Shettar <[email protected]>
Cc Stanislav Fomichev <[email protected]>
Fixes 004b5008016a ("eth: bnxt: remove most dependencies on RTNL")
---
  drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c | 2 ++
  1 file changed, 2 insertions(+)
Quoted 16 lines

drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c static int bnxt_dl_reload_up(struct devlink *dl, enum devlink_reload_action acti · line 566

Quoted 10 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c +2 -0
index 15de802bbac4..1e9a3454bb29 100644
@@ -562,6 +562,8 @@ static int bnxt_dl_reload_up(struct devlink *dl, enum devlink_reload_action acti
                 break;
         }
         default:
+               netdev_unlock(bp->dev);
+               rtnl_unlock();

This doesn't look correct. The 2 locks are taken in bnxt_dl_reload_down() only for the 2 actions DEVLINK_RELOAD_ACTION_DRIVER_REINIT and DEVLINK_RELOAD_ACTION_FW_ACTIVATE. For the default action, no locks are taken so I don't think we should unlock here.

Hi Michael,

My understanding is that bnxt_dl_reload_up() is only called if bnxt_dl_reload_down() returns 0 (see also devlink_reload()). bnxt_dl_reload_up() returns an error code (-EOPNOTSUPP) for other actions than DEVLINK_RELOAD_ACTION_DRIVER_REINIT or DEVLINK_RELOAD_ACTION_FW_ACTIVATE. Hence, bnxt_dl_reload_up() is only called if "action" is either DEVLINK_RELOAD_ACTION_DRIVER_REINIT or DEVLINK_RELOAD_ACTION_FW_ACTIVATE. In other words, the code in the "default" clause will never be reached. So I think the above change is correct but also that the patch description should be modified to reflect that this is not a bug fix. Did I perhaps misunderstand something?

Thanks,

Bart.

maintainer
#31 lore raw

Re: [PATCH 18/62] bnxt_en: Fix bnxt_dl_reload_up()

Quoted 12 lines · Bart Van Assche

My understanding is that bnxt_dl_reload_up() is only called if bnxt_dl_reload_down() returns 0 (see also devlink_reload()). bnxt_dl_reload_up() returns an error code (-EOPNOTSUPP) for other actions than DEVLINK_RELOAD_ACTION_DRIVER_REINIT or DEVLINK_RELOAD_ACTION_FW_ACTIVATE. Hence, bnxt_dl_reload_up() is only called if "action" is either DEVLINK_RELOAD_ACTION_DRIVER_REINIT or DEVLINK_RELOAD_ACTION_FW_ACTIVATE. In other words, the code in the "default" clause will never be reached. So I think the above change is correct but also that the patch description should be modified to reflect that this is not a bug fix. Did I perhaps misunderstand something?

Yes, your description is correct. So perhaps a better cleanup would be to remove the default case in bnxt_dl_reload_up()? Thanks.

#32 lore raw

Re: [PATCH 18/62] bnxt_en: Fix bnxt_dl_reload_up()

Quoted 15 lines · Michael Chan
Quoted 12 lines · Bart Van Assche

My understanding is that bnxt_dl_reload_up() is only called if bnxt_dl_reload_down() returns 0 (see also devlink_reload()). bnxt_dl_reload_up() returns an error code (-EOPNOTSUPP) for other actions than DEVLINK_RELOAD_ACTION_DRIVER_REINIT or DEVLINK_RELOAD_ACTION_FW_ACTIVATE. Hence, bnxt_dl_reload_up() is only called if "action" is either DEVLINK_RELOAD_ACTION_DRIVER_REINIT or DEVLINK_RELOAD_ACTION_FW_ACTIVATE. In other words, the code in the "default" clause will never be reached. So I think the above change is correct but also that the patch description should be modified to reflect that this is not a bug fix. Did I perhaps misunderstand something?

Quoted 2 lines

Yes, your description is correct. So perhaps a better cleanup would be to remove the default case in bnxt_dl_reload_up()? Thanks.

Hmm ... wouldn't that trigger a -Wswitch warning, a warning that is enabled by default for kernel code? From the gcc documentation:
"Warn whenever a switch statement has an index of enumerated type and lacks a case for one or more of the named codes of that enumeration. (The presence of a default label prevents this warning.) case labels that do not correspond to enumerators also provoke warnings when this option is used, unless the enumeration is marked with the flag_enum attribute. This warning is enabled by -Wall."

Changing "default: return -EOPNOTSUPP;" into "default: BUG();" keeps the Clang thread-sanitizer happy but does not comply with the kernel coding style. Does the patch below look better?

Thanks,

Bart.

bnxt_en: Suppress thread-safety complaints about bnxt_dl_reload_up()

bnxt_dl_reload_down() returns an error code for actions that are not supported. Hence, bnxt_dl_reload_up() won't be called for unsupported actions. Since the compiler doesn't know this, add unlock calls to the default clause. This patch suppresses a Clang thread-sanitizer complaint. Compile-tested only.

Cc Jakub Kicinski <[email protected]>
Cc Shantiprasad Shettar <[email protected]>
Cc Stanislav Fomichev <[email protected]>
Fixes 004b5008016a ("eth: bnxt: remove most dependencies on RTNL")
drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c +7 -0
index 15de802bbac4..aa7ebd1426ed 100644
@@ -562,6 +562,13 @@ static int bnxt_dl_reload_up(struct devlink *dl, enum devlink_reload_action acti
 		break;
 	}
 	default:
+		/*
+		 * Other actions have already been rejected by
+		 * bnxt_dl_reload_down().
+		 */
+		WARN_ON_ONCE(true);
+		netdev_unlock(bp->dev);
+		rtnl_unlock();
 		return -EOPNOTSUPP;
 	}
 
maintainer
#33 lore raw

Re: [PATCH 18/62] bnxt_en: Fix bnxt_dl_reload_up()

Quoted 10 lines · Bart Van Assche
drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c +0 -0
index 15de802bbac4..aa7ebd1426ed 100644
@@ -562,6 +562,13 @@ static int bnxt_dl_reload_up(struct devlink *dl,

enum devlink_reload_action acti

                break;
        }
        default:

drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c static int bnxt_dl_reload_up(struct devlink *dl, enum devlink_reload_action acti · line 571

Quoted 7 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c +7 -0
+               /*
+                * Other actions have already been rejected by
+                * bnxt_dl_reload_down().
+                */
+               WARN_ON_ONCE(true);
+               netdev_unlock(bp->dev);
+               rtnl_unlock();

This is better. It makes it clear that it should never get here.

Quoted 4 lines
                return -EOPNOTSUPP;
        }
#34 lore raw

PATCH 20/62 octeontx2-pf: Fix locking in an error path

In reply to a message not in the archive

Only unlock pf->mbox.lock if it has been locked by otx2_do_set_vf_vlan(). This bug has been detected by the Clang thread-safety analyzer.

Cc Naveen Mamindlapalli <[email protected]>
Cc Jakub Kicinski <[email protected]>
Cc Sunil Goutham <[email protected]>
Cc Geetha sowjanya <[email protected]>
Cc Subbaraya Sundeep <[email protected]>
Cc hariprasad <[email protected]>
Cc Bharat Bhushan <[email protected]>
Fixes f0c2982aaf98 ("octeontx2-pf: Add support for SR-IOV management functions")
---
 drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +1 -1
index ee623476e5ff..8c9f08ed90fd 100644
@@ -2588,7 +2588,7 @@ static int otx2_do_set_vf_vlan(struct otx2_nic *pf, int vf, u16 vlan, u8 qos,
 	config = &pf->vf_configs[vf];
 
 	if (!vlan && !config->vlan)
-		goto out;
+		return err;
 
 	mutex_lock(&pf->mbox.lock);
 
#35 lore raw

PATCH 21/62 qed: Make _qed_mcp_cmd_and_union() easier to analyze

In reply to a message not in the archive

Make the implementation of this function compatible with clang's compile-time thread-safety analysis by moving error-handling code to the end of this function. No functionality has been changed.

---
 drivers/net/ethernet/qlogic/qed/qed_mcp.c | 56 ++++++++++++-----------
 1 file changed, 30 insertions(+), 26 deletions(-)
drivers/net/ethernet/qlogic/qed/qed_mcp.c +30 -26
index 7e37fe631a58..462e758c5890 100644
@@ -467,7 +467,7 @@ _qed_mcp_cmd_and_union(struct qed_hwfn *p_hwfn,
 	int rc = 0;
 
 	/* Wait until the mailbox is non-occupied */
-	do {
+	for (;;) {
 		/* Exit the loop if there is no pending command, or if the
 		 * pending command is completed during this iteration.
 		 * The spinlock stays locked until the command is sent.
@@ -486,18 +486,14 @@ _qed_mcp_cmd_and_union(struct qed_hwfn *p_hwfn,
 
 		spin_unlock_bh(&p_hwfn->mcp_info->cmd_lock);
 
+		if (++cnt >= QED_DRV_MB_MAX_RETRIES)
+			goto retries_exceeded_1;
+
 		if (QED_MB_FLAGS_IS_SET(p_mb_params, CAN_SLEEP))
 			usleep_range(QED_MCP_RESP_ITER_US,
 				     QED_MCP_RESP_ITER_US * 2);
 		else
 			udelay(QED_MCP_RESP_ITER_US);
-	} while (++cnt < QED_DRV_MB_MAX_RETRIES);
-
-	if (cnt >= QED_DRV_MB_MAX_RETRIES) {
-		DP_NOTICE(p_hwfn,
-			  "The MFW mailbox is occupied by an uncompleted command. Failed to send command 0x%08x [param 0x%08x].\n",
-			  p_mb_params->cmd, p_mb_params->param);
-		return -EAGAIN;
 	}
 
 	/* Send the mailbox command */
@@ -513,7 +509,7 @@ _qed_mcp_cmd_and_union(struct qed_hwfn *p_hwfn,
 	spin_unlock_bh(&p_hwfn->mcp_info->cmd_lock);
 
 	/* Wait for the MFW response */
-	do {
+	for (;;) {
 		/* Exit the loop if the command is already completed, or if the
 		 * command is completed during this iteration.
 		 * The spinlock stays locked until the list element is removed.
@@ -537,24 +533,9 @@ _qed_mcp_cmd_and_union(struct qed_hwfn *p_hwfn,
 			goto err;
 
 		spin_unlock_bh(&p_hwfn->mcp_info->cmd_lock);
-	} while (++cnt < QED_DRV_MB_MAX_RETRIES);
-
-	if (cnt >= QED_DRV_MB_MAX_RETRIES) {
-		DP_NOTICE(p_hwfn,
-			  "The MFW failed to respond to command 0x%08x [param 0x%08x].\n",
-			  p_mb_params->cmd, p_mb_params->param);
-		qed_mcp_print_cpu_info(p_hwfn, p_ptt);
-
-		spin_lock_bh(&p_hwfn->mcp_info->cmd_lock);
-		qed_mcp_cmd_del_elem(p_hwfn, p_cmd_elem);
-		spin_unlock_bh(&p_hwfn->mcp_info->cmd_lock);
 
-		if (!QED_MB_FLAGS_IS_SET(p_mb_params, AVOID_BLOCK))
-			qed_mcp_cmd_set_blocking(p_hwfn, true);
-
-		qed_hw_err_notify(p_hwfn, p_ptt,
-				  QED_HW_ERR_MFW_RESP_FAIL, NULL);
-		return -EAGAIN;
+		if (++cnt >= QED_DRV_MB_MAX_RETRIES)
+			goto retries_exceeded_2;
 	}
 
 	qed_mcp_cmd_del_elem(p_hwfn, p_cmd_elem);
@@ -576,6 +557,29 @@ _qed_mcp_cmd_and_union(struct qed_hwfn *p_hwfn,
 err:
 	spin_unlock_bh(&p_hwfn->mcp_info->cmd_lock);
 	return rc;
+
+retries_exceeded_1:
+	DP_NOTICE(p_hwfn,
+		  "The MFW mailbox is occupied by an uncompleted command. Failed to send command 0x%08x [param 0x%08x].\n",
+		  p_mb_params->cmd, p_mb_params->param);
+	return -EAGAIN;
+
+retries_exceeded_2:
+	DP_NOTICE(p_hwfn,
+		  "The MFW failed to respond to command 0x%08x [param 0x%08x].\n",
+		  p_mb_params->cmd, p_mb_params->param);
+	qed_mcp_print_cpu_info(p_hwfn, p_ptt);
+
+	spin_lock_bh(&p_hwfn->mcp_info->cmd_lock);
+	qed_mcp_cmd_del_elem(p_hwfn, p_cmd_elem);
+	spin_unlock_bh(&p_hwfn->mcp_info->cmd_lock);
+
+	if (!QED_MB_FLAGS_IS_SET(p_mb_params, AVOID_BLOCK))
+		qed_mcp_cmd_set_blocking(p_hwfn, true);
+
+	qed_hw_err_notify(p_hwfn, p_ptt,
+			  QED_HW_ERR_MFW_RESP_FAIL, NULL);
+	return -EAGAIN;
 }
 
 static int qed_mcp_cmd_and_union(struct qed_hwfn *p_hwfn,
#36 lore raw

PATCH 22/62 mctp i3c: Fix locking in error paths

In reply to a message not in the archive

Only unlock mi->lock if it has been locked. This bug has been detected by the Clang thread-safety analyzer.

Cc Leo Yang <[email protected]>
Cc Paolo Abeni <[email protected]>
Cc Jeremy Kerr <[email protected]>
Cc Matt Johnston <[email protected]>
Fixes 2d2d4f60ed26 ("mctp i3c: fix MCTP I3C driver multi-thread issue")
---
 drivers/net/mctp/mctp-i3c.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/mctp/mctp-i3c.c +4 -1
index 6d2bbae7477b..d4a29912c7e1 100644
@@ -112,7 +112,7 @@ static int mctp_i3c_read(struct mctp_i3c_device *mi)
 	if (!skb) {
 		stats->rx_dropped++;
 		rc = -ENOMEM;
-		goto err;
+		goto free_skb;
 	}
 
 	skb->protocol = htons(ETH_P_MCTP);
@@ -170,8 +170,11 @@ static int mctp_i3c_read(struct mctp_i3c_device *mi)
 
 	mutex_unlock(&mi->lock);
 	return 0;
+
 err:
 	mutex_unlock(&mi->lock);
+
+free_skb:
 	kfree_skb(skb);
 	return rc;
 }
#37 lore raw

PATCH 19/62 ice: Fix a locking bug in an error path

In reply to a message not in the archive

Move the mutex_lock() call up to prevent that DCB settings change after the ice_query_port_ets() call.

This patch fixes a bug in an error path. Without this patch pf->tc_mutex may be unlocked in an error path without having been locked. This bug has been detected by the clang thread-safety analyzer.

Cc Tony Nguyen <[email protected]>
Cc Przemek Kitszel <[email protected]>
Fixes 242b5e068b25 ("ice: Fix DCB rebuild after reset")
---
 drivers/net/ethernet/intel/ice/ice_dcb_lib.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/ice/ice_dcb_lib.c +2 -2
index bd77f1c001ee..78ded6876581 100644
@@ -537,14 +537,14 @@ void ice_dcb_rebuild(struct ice_pf *pf)
 	struct ice_dcbx_cfg *err_cfg;
 	int ret;
 
+	mutex_lock(&pf->tc_mutex);
+
 	ret = ice_query_port_ets(pf->hw.port_info, &buf, sizeof(buf), NULL);
 	if (ret) {
 		dev_err(dev, "Query Port ETS failed\n");
 		goto dcb_error;
 	}
 
-	mutex_lock(&pf->tc_mutex);
-
 	if (!pf->hw.port_info->qos_cfg.is_sw_lldp)
 		ice_cfg_etsrec_defaults(pf->hw.port_info);