kvm: Make pi_enable_wakeup_handler() easier to analyze
Subsystems (26)
A message that is not in the archive (sent off-list or not yet received): [email protected]
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.
--- arch/x86/kvm/vmx/posted_intr.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
arch/x86/kvm/vmx/posted_intr.c +4 -3
@@ -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" );
PATCH 2/62 blk-ioc: Prepare for enabling thread-safety analysis
In reply to a message not in the archiveThe 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
@@ -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 ; }
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.
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.
PATCH 3/62 drbd: Balance RCU calls in drbd_adm_dump_devices()
In reply to a message not in the archiveMake 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.
--- drivers/block/drbd/drbd_nl.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/block/drbd/drbd_nl.c +6 -2
@@ -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; }
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()callrcu_read_lock()beforercu_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")Signed-off-by Bart Van Assche <[email protected]>--- drivers/block/drbd/drbd_nl.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/block/drbd/drbd_nl.c +3
-1@@ -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
-1retcode =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
PATCH 4/62 dax/bus.c: Fix a locking bug
In reply to a message not in the archiveOnly unlock dax_dev_rwsem if it has been locked. This locking bug was detected by the Clang thread-safety analyzer.
--- drivers/dax/bus.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/dax/bus.c +1 -2
@@ -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);
PATCH 5/62 dma-buf: Convert dma_buf_import_sync_file() to the early-return style
In reply to a message not in the archiveBefore 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
@@ -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); }
Christian König
maintainerRe: [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.Cc Sumit Semwal <[email protected]>Cc Christian König <[email protected]>Signed-off-by Bart Van Assche <[email protected]>--- drivers/dma-buf/dma-buf.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)drivers/dma-buf/dma-buf.c +0
-0@@ -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
-4ret =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); }
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@@ -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
-4ret =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.
PATCH 6/62 dma-buf: Handle all dma_resv_lock() errors
In reply to a message not in the archiveInstead 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
@@ -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
Christian König
maintainerRe: [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 possibledma_resv_lock()return values. This patch prepares for enabling compile-time thread-safety analysis. This will cause the compiler to check whether alldma_resv_lock()return values are handled.Cc Sumit Semwal <[email protected]>Cc Christian König <[email protected]>Signed-off-by Bart Van Assche <[email protected]>--- drivers/dma-buf/dma-resv.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/dma-buf/dma-resv.c +0
-0
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
-0fs_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
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.
Christian König
maintainerRe: [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)anddma_resv_unlock()has been annotated with__releases(&obj->lock). Hence, with thread-safety analysis enabled, Clang complains aboutdma_resv_unlock()calls ifdma_resv_lock()returns an error code. There are several possibilities for suppressing Clang's thread- safety warnings:
* The least elegant is to annotatedma_resv_lockdep()with__no_context_analysisand 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 ifdma_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.
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
@@ -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.
Christian König
maintainerRe: [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@@ -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
-0dma_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.
PATCH 7/62 drm/amdgpu: Unlock a mutex before destroying it
In reply to a message not in the archiveMutexes must be unlocked before these are destroyed. This has been detected by the Clang thread-safety analyzer.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c +1 -0
@@ -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); }
PATCH 8/62 drm/amdgpu: Fix locking bugs in error paths
In reply to a message not in the archiveDo not unlock psp->ras_context.mutex if it has not been locked. This has been detected by the Clang thread-safety analyzer.
--- 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
@@ -332,13 +332,13 @@ static ssize_t ta_if_invoke_debugfs_write(struct file *fp, const char *buf, sizeif (!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, sizemutex_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;
PATCH 13/62 drm/qxl: Fix a buffer leak in an error path
In reply to a message not in the archiveIf 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.
--- drivers/gpu/drm/qxl/qxl_ioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/qxl/qxl_ioctl.c +1 -1
@@ -323,7 +323,7 @@ int qxl_update_area_ioctl(struct drm_device *dev, void *data, struct drm_file *fqxl_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);
PATCH 14/62 hwmon: (it87) Check the it87_lock() return value
In reply to a message not in the archiveReturn 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.
--- drivers/hwmon/it87.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/hwmon/it87.c +3 -1
@@ -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);
PATCH 15/62 Input: synaptics-rmi4 - fix a locking bug in an error path
In reply to a message not in the archiveLock 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.
--- drivers/input/rmi4/rmi_f54.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/input/rmi4/rmi_f54.c +3 -2
@@ -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.
PATCH 16/62 md: Make mddev_suspend() easier to analyze
In reply to a message not in the archivePrepare 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
@@ -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 );
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
Cc Song Liu <[email protected]>Cc Yu Kuai <[email protected]>Signed-off-by Bart Van Assche <[email protected]>--- drivers/md/md.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)drivers/md/md.c +1
-2@@ -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
PATCH 17/62 bnxt_en: Make bnxt_resume() easier to analyze
In reply to a message not in the archivePass 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
@@ -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);
Jakub Kicinski
maintainerRe: [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()andnetdev_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
Jakub Kicinski
maintainerRe: [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()andnetdev_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.
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.
PATCH 18/62 bnxt_en: Fix bnxt_dl_reload_up()
In reply to a message not in the archivebnxt_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.
--- drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c | 2 ++ 1 file changed, 2 insertions(+)
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 actibreak ; }default : +netdev_unlock (bp->dev); +rtnl_unlock ();return -EOPNOTSUPP ; }
Michael Chan
maintainerRe: [PATCH 18/62] bnxt_en: Fix bnxt_dl_reload_up()
.
Quoted 21 lines · Bart Van Assche
bnxt_dl_reload_down()callsrtnl_lock()andnetdev_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")Signed-off-by Bart Van Assche <[email protected]>--- drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c | 2 ++ 1 file changed, 2 insertions(+)drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c +0
-0
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 actibreak ; }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.
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()callsrtnl_lock()andnetdev_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")Signed-off-by Bart Van Assche <[email protected]>--- 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@@ -562,6 +562,8 @@ static int bnxt_dl_reload_up(struct devlink *dl, enum devlink_reload_action actibreak ; }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 actionsDEVLINK_RELOAD_ACTION_DRIVER_REINITandDEVLINK_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.
Michael Chan
maintainerRe: [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 ifbnxt_dl_reload_down()returns 0 (see alsodevlink_reload()).bnxt_dl_reload_up()returns an error code (-EOPNOTSUPP) for other actions thanDEVLINK_RELOAD_ACTION_DRIVER_REINITorDEVLINK_RELOAD_ACTION_FW_ACTIVATE. Hence,bnxt_dl_reload_up()is only called if "action" is eitherDEVLINK_RELOAD_ACTION_DRIVER_REINITorDEVLINK_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.
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 ifbnxt_dl_reload_down()returns 0 (see alsodevlink_reload()).bnxt_dl_reload_up()returns an error code (-EOPNOTSUPP) for other actions thanDEVLINK_RELOAD_ACTION_DRIVER_REINITorDEVLINK_RELOAD_ACTION_FW_ACTIVATE. Hence,bnxt_dl_reload_up()is only called if "action" is eitherDEVLINK_RELOAD_ACTION_DRIVER_REINITorDEVLINK_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.
drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c +7 -0
@@ -562,6 +562,13 @@ static int bnxt_dl_reload_up(struct devlink *dl, enum devlink_reload_action actibreak ; }default : +/* +* Other actions have already been rejected by +* bnxt_dl_reload_down(). +*/ +WARN_ON_ONCE (true); +netdev_unlock (bp->dev); +rtnl_unlock ();return -EOPNOTSUPP ; }
Michael Chan
maintainerRe: [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@@ -562,6 +562,13 @@ static int bnxt_dl_reload_up(struct devlink *dl,enum
devlink_reload_actionactibreak; } 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;
}PATCH 20/62 octeontx2-pf: Fix locking in an error path
In reply to a message not in the archiveOnly 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.
--- 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
@@ -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);
PATCH 21/62 qed: Make _qed_mcp_cmd_and_union() easier to analyze
In reply to a message not in the archiveMake 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
@@ -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,
PATCH 22/62 mctp i3c: Fix locking in error paths
In reply to a message not in the archiveOnly unlock mi->lock if it has been locked. This bug has been detected by the Clang thread-safety analyzer.
--- drivers/net/mctp/mctp-i3c.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/mctp/mctp-i3c.c +4 -1
@@ -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; }
PATCH 19/62 ice: Fix a locking bug in an error path
In reply to a message not in the archiveMove 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.
--- 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
@@ -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);