powerpc/mm, pseries, powernv: Enable clang context analysis
Subsystems (2)
Ritesh Harjani (IBM)
reviewerv2 cover powerpc/mm, pseries, powernv: Enable clang context analysis
Enable Clang context analysis checking for most of powerpc/mm, pseries & powernv platforms.
Lock acquire and release checking used to be done with Sparse. That support was removed [1] and replaced with Clang context analysis [2].
Note that enabling this caught a real locking rcu bug in arch/powerpc/mm (Patch-1). Note, more invasive checkers to check what each lock protects is deferred for later enablement.
The series was build tested with LLVM/Clang 23.x
[1] 5b63d0ae94cc ("compiler-context-analysis: Remove Sparse support")
[2] 3269701cb256 ("compiler-context-analysis: Add infrastructure for Context Analysis with Clang")
v1 -> v2:
===========
1. Dropped RFC tag, since this series is looking in shape to be included for v7.5
2. Clubbed both RFC series {pseries|powernv} and mm into one.
2. Patch-3 changed the type of i from "unsigned long i" to "int i"
3. Fixed commit msg for patch-14 - as pointed by Sashiko
Ritesh Harjani (IBM) (18):
powerpc/mm/book3s64: unlock RCU before returning from mm_iommu_is_devmem() powerpc/mm/book3s64: Rework tlbie() to remove conditional locking powerpc/mm/book3s64: Rework native_flush_hash_range() to remove conditional locking powerpc/mm/book3s64: Annotate the subpage-protection PTE lock powerpc/mm: Rework nohash TLB broadcast locking
powerpc/mm: Enable context analysis
powerpc/pseries: Drop inline from hugepage invalidate powerpc/pseries: Rework hugepage invalidate to remove conditional locking powerpc/pseries: Rework hash flush to remove conditional locking powerpc/pseries: Add context annotations for the DTL worker lock powerpc/pseries: Annotate the VPD sequence lock context powerpc/pseries: Annotate the RTAS indices sequence lock context powerpc/pseries: Annotate the RTAS physical-attestation sequence lock context powerpc/pseries: Annotate the DTL debugfs read lock context powerpc/pseries: Disable context analysis for the CMM hotplug notifier powerpc/pseries: Enable context analysis
powerpc/powernv: Rework OPAL console write to remove conditional locking powerpc/powernv: Enable context analysis
arch/powerpc/mm/Makefile | 2 + arch/powerpc/mm/book3s32/Makefile | 2 + arch/powerpc/mm/book3s64/Makefile | 2 + arch/powerpc/mm/book3s64/hash_native.c | 122 +++++++++++------- arch/powerpc/mm/book3s64/iommu_api.c | 6 +- arch/powerpc/mm/book3s64/subpage_prot.c | 2 + arch/powerpc/mm/nohash/Makefile | 2 + arch/powerpc/mm/nohash/mmu_context.c | 1 + arch/powerpc/mm/nohash/tlb.c | 8 +- arch/powerpc/platforms/powernv/Makefile | 2 + arch/powerpc/platforms/powernv/opal.c | 30 +++-- arch/powerpc/platforms/pseries/Makefile | 3 + arch/powerpc/platforms/pseries/cmm.c | 1 + arch/powerpc/platforms/pseries/dtl.c | 8 ++ arch/powerpc/platforms/pseries/lpar.c | 59 +++++---- arch/powerpc/platforms/pseries/papr-indices.c | 3 + .../platforms/pseries/papr-phy-attest.c | 4 + arch/powerpc/platforms/pseries/papr-vpd.c | 3 + 18 files changed, 179 insertions(+), 81 deletions(-)
--
2.39.5
Ritesh Harjani (IBM)
reviewerPATCH v2 1/18 powerpc/mm/book3s64: unlock RCU before returning from mm_iommu_is_devmem()
Clang's context analysis reports:
iommu_api.c:380:1: error: __ctx_lock_RCU 'RCU' is not held on every path through here [-Werror,-Wthread-safety-analysis]
mm_iommu_is_devmem() takes the RCU read lock to walk the preregistered device-memory list. On a match it returned true from inside the loop and skipped rcu_read_unlock(). Hence fix it.
--- arch/powerpc/mm/book3s64/iommu_api.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
arch/powerpc/mm/book3s64/iommu_api.c +4 -2
@@ -356,6 +356,7 @@ bool mm_iommu_is_devmem(struct mm_struct *mm, unsigned long hpa, {struct mm_iommu_table_group_mem_t *mem;unsigned long end; +bool ret = false;rcu_read_lock ();list_for_each_entry_rcu (mem, &mm->context.iommu_group_mem_list, next) {
@@ -371,12 +372,13 @@ bool mm_iommu_is_devmem(struct mm_struct *mm, unsigned long hpa,* and the caller needs to distinguish this situation. */ *size =min (1UL << pageshift, end - hpa); -return true; + ret = true; +break ; } }rcu_read_unlock (); -return false; +return ret; }EXPORT_SYMBOL_GPL (mm_iommu_is_devmem);
Signature · 1 line
2.39.5
Ritesh Harjani (IBM)
reviewerPATCH v2 2/18 powerpc/mm/book3s64: Rework tlbie() to remove conditional locking
In reply to Ritesh Harjani (IBM)Clang's context analysis reports:
hash_native.c:235:2: error: raw_spinlock 'native_tlbie_lock' is not held on every path through here [-Werror,-Wthread-safety-analysis] hash_native.c:245:3: error: releasing raw_spinlock 'native_tlbie_lock' that was not held [-Werror,-Wthread-safety-analysis]
This patch reworks the tlbie() function to remove the conditional locking. It fixes the clang context analysis reported errors. However, this also simplifies the code around tlbie[l] - which is also a win.
No functional change intended.
--- arch/powerpc/mm/book3s64/hash_native.c | 34 ++++++++++++++++++-------- 1 file changed, 24 insertions(+), 10 deletions(-)
arch/powerpc/mm/book3s64/hash_native.c +24 -10
@@ -222,6 +222,23 @@ static inline void __tlbiel(unsigned long vpn, int psize, int apsize, int ssize) } +static inline void __tlbie_sequence (unsigned long vpn,int psize,int apsize, +int ssize) +{ + asmvolatile ("ptesync" : : :"memory" ); +__tlbie (vpn, psize, apsize, ssize); +fixup_tlbie_vpn (vpn, psize, apsize, ssize); + asmvolatile ("eieio; tlbsync; ptesync" : : :"memory" ); +} + +static inline void __tlbiel_sequence (unsigned long vpn,int psize,int apsize, +int ssize) +{ + asmvolatile ("ptesync" : : :"memory" ); +__tlbiel (vpn, psize, apsize, ssize); +ppc_after_tlbiel_barrier (); +} +static inline void tlbie (unsigned long vpn,int psize,int apsize,int ssize,int local) {
@@ -230,19 +247,16 @@ static inline void tlbie(unsigned long vpn, int psize, int apsize,if (use_local) use_local = mmu_psize_defs[psize].tlbiel; -if (lock_tlbie && !use_local) -raw_spin_lock (&native_tlbie_lock); - asmvolatile ("ptesync" : : :"memory" ); +if (use_local) { -__tlbiel (vpn, psize, apsize, ssize); -ppc_after_tlbiel_barrier (); +__tlbiel_sequence (vpn, psize, apsize, ssize); + }else if (lock_tlbie) { +raw_spin_lock (&native_tlbie_lock); +__tlbie_sequence (vpn, psize, apsize, ssize); +raw_spin_unlock (&native_tlbie_lock); }else { -__tlbie (vpn, psize, apsize, ssize); -fixup_tlbie_vpn (vpn, psize, apsize, ssize); - asmvolatile ("eieio; tlbsync; ptesync" : : :"memory" ); +__tlbie_sequence (vpn, psize, apsize, ssize); } -if (lock_tlbie && !use_local) -raw_spin_unlock (&native_tlbie_lock); }static inline void native_lock_hpte (struct hash_pte *hptep)
Signature · 1 line
2.39.5
Ritesh Harjani (IBM)
reviewerPATCH v2 3/18 powerpc/mm/book3s64: Rework native_flush_hash_range() to remove conditional locking
In reply to Ritesh Harjani (IBM)Clang's context analysis reports:
hash_native.c:851:2: error: raw_spinlock 'native_tlbie_lock' is not held on every path through here [-Werror,-Wthread-safety-analysis] hash_native.c:868:3: error: releasing raw_spinlock 'native_tlbie_lock' that was not held [-Werror,-Wthread-safety-analysis]
This patch reworks the native_flush_hash_range() function to remove the conditional locking. It fixes the clang context analysis reported errors. However, this also simplifies the code in native_flush_hash_range() due to various if conditions.
No functional change intended.
--- arch/powerpc/mm/book3s64/hash_native.c | 88 ++++++++++++++++---------- 1 file changed, 54 insertions(+), 34 deletions(-)
arch/powerpc/mm/book3s64/hash_native.c +54 -34
@@ -792,6 +792,54 @@ static notrace void native_hpte_clear(void) asmvolatile ("eieio; tlbsync; ptesync" :::"memory" ); } +static void native_flush_hash_range_tlbiel (struct ppc64_tlb_batch *batch, +unsigned long number) +{ +unsigned long vpn =0 , index, shift; +real_pte_t pte; +unsigned long psize = batch->psize; +int ssize = batch->ssize; +int i; + + asmvolatile ("ptesync" :::"memory" ); +for (i =0 ; i < number; i++) { + vpn = batch->vpn[i]; + pte = batch->pte[i]; + +pte_iterate_hashed_subpages (pte, psize, + vpn, index, shift) { +__tlbiel (vpn, psize, psize, ssize); + }pte_iterate_hashed_end (); + } +ppc_after_tlbiel_barrier (); +} + +static void native_flush_hash_range_tlbie (struct ppc64_tlb_batch *batch, +unsigned long number) +{ +unsigned long vpn =0 , index, shift; +real_pte_t pte; +unsigned long psize = batch->psize; +int ssize = batch->ssize; +int i; + + asmvolatile ("ptesync" :::"memory" ); +for (i =0 ; i < number; i++) { + vpn = batch->vpn[i]; + pte = batch->pte[i]; + +pte_iterate_hashed_subpages (pte, psize, + vpn, index, shift) { +__tlbie (vpn, psize, psize, ssize); + }pte_iterate_hashed_end (); + } +/* +* Just do one more with the last used values. +*/ +fixup_tlbie_vpn (vpn, psize, psize, ssize); + asmvolatile ("eieio; tlbsync; ptesync" :::"memory" ); +} +/* * Batched hash table flush, we batch the tlbie's to avoid taking/releasing * the lock all the time
@@ -845,41 +893,13 @@ static void native_flush_hash_range(unsigned long number, int local)if (mmu_has_feature (MMU_FTR_TLBIEL ) && mmu_psize_defs[psize].tlbiel && local) { - asmvolatile ("ptesync" :::"memory" ); -for (i =0 ; i < number; i++) { - vpn = batch->vpn[i]; - pte = batch->pte[i]; - -pte_iterate_hashed_subpages (pte, psize, - vpn, index, shift) { -__tlbiel (vpn, psize, psize, ssize); - }pte_iterate_hashed_end (); - } -ppc_after_tlbiel_barrier (); +native_flush_hash_range_tlbiel (batch, number); + }else if (!mmu_has_feature (MMU_FTR_LOCKLESS_TLBIE )) { +raw_spin_lock (&native_tlbie_lock); +native_flush_hash_range_tlbie (batch, number); +raw_spin_unlock (&native_tlbie_lock); }else { -int lock_tlbie = !mmu_has_feature (MMU_FTR_LOCKLESS_TLBIE ); - -if (lock_tlbie) -raw_spin_lock (&native_tlbie_lock); - - asmvolatile ("ptesync" :::"memory" ); -for (i =0 ; i < number; i++) { - vpn = batch->vpn[i]; - pte = batch->pte[i]; - -pte_iterate_hashed_subpages (pte, psize, - vpn, index, shift) { -__tlbie (vpn, psize, psize, ssize); - }pte_iterate_hashed_end (); - } -/* -* Just do one more with the last used values. -*/ -fixup_tlbie_vpn (vpn, psize, psize, ssize); - asmvolatile ("eieio; tlbsync; ptesync" :::"memory" ); - -if (lock_tlbie) -raw_spin_unlock (&native_tlbie_lock); +native_flush_hash_range_tlbie (batch, number); }local_irq_restore (flags);
Signature · 1 line
2.39.5
Ritesh Harjani (IBM)
reviewerPATCH v2 4/18 powerpc/mm/book3s64: Annotate the subpage-protection PTE lock
In reply to Ritesh Harjani (IBM)Clang's context analysis reports:
subpage_prot.c:83:2: error: releasing spinlock 'ptl' that was not held [-Werror,-Wthread-safety-analysis]
pte_offset_map_lock() holds ptl when it returns a PTE and pte_unmap_unlock() drops it. However since the lock is taken inside the helper, which is not annotated, so the unlock in hpte_flush_range() looks unheld.
This patch fixes it in hpte_flush_range() by adding the needed annotation here. IMO, should ideally be added to pte_offset_map_lock(), once that happens (since it might need larger enablement), we can remove it from here.
--- arch/powerpc/mm/book3s64/subpage_prot.c | 2 ++ 1 file changed, 2 insertions(+)
arch/powerpc/mm/book3s64/subpage_prot.c +2 -0
@@ -73,6 +73,8 @@ static void hpte_flush_range(struct mm_struct *mm, unsigned long addr, pte =pte_offset_map_lock (mm, pmd, addr, &ptl);if (!pte)return ; +/* pte_offset_map_lock on success returns with ptl lock held */ +__acquire (ptl);lazy_mmu_mode_enable ();for (; npages >0 ; --npages) {pte_update (mm, addr, pte,0 ,0 ,0 );
Signature · 1 line
2.39.5
Ritesh Harjani (IBM)
reviewerPATCH v2 5/18 powerpc/mm: Rework nohash TLB broadcast locking
In reply to Ritesh Harjani (IBM)Clang's context analysis reports:
mmu_context.c:141:2: error: releasing raw_spinlock 'context_lock' that was not held [-Werror,-Wthread-safety-analysis] mmu_context.c:147:1: error: raw_spinlock 'context_lock' is not held on every path through here [-Werror,-Wthread-safety-analysis]
tlb.c:257:4: error: raw_spinlock 'tlbivax_lock' is not held on every path through here [-Werror,-Wthread-safety-analysis] tlb.c:259:5: error: releasing raw_spinlock 'tlbivax_lock' that was not held [-Werror,-Wthread-safety-analysis]
This reworks the locking in __flush_tlb_page() a bit to satisfy clang context analyzer requirement.
Also steal_context_smp() drops the context_lock, so it needs to be annotated with __must_hold to inform the clang analyzer that this function holds the context_lock.
--- arch/powerpc/mm/nohash/mmu_context.c | 1 + arch/powerpc/mm/nohash/tlb.c | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-)
arch/powerpc/mm/nohash/mmu_context.c +1 -0
@@ -95,6 +95,7 @@ static DEFINE_RAW_SPINLOCK(context_lock);* -- benh */ static unsigned int steal_context_smp (unsigned int id) + __must_hold(&context_lock) {struct mm_struct *mm;unsigned int cpu, max, i;
arch/powerpc/mm/nohash/tlb.c +5 -3
@@ -252,11 +252,13 @@ void __flush_tlb_page(struct mm_struct *mm, unsigned long vmaddr,/* If broadcast tlbivax is supported, use it */ if (mmu_has_feature (MMU_FTR_USE_TLBIVAX_BCAST )) {int lock =mmu_has_feature (MMU_FTR_LOCK_BCAST_INVAL ); -if (lock) +if (lock) {raw_spin_lock (&tlbivax_lock); -_tlbivax_bcast (vmaddr, pid, tsize, ind); -if (lock) +_tlbivax_bcast (vmaddr, pid, tsize, ind);raw_spin_unlock (&tlbivax_lock); + }else { +_tlbivax_bcast (vmaddr, pid, tsize, ind); + } goto bail; }else {struct tlb_flush_param p = {
Signature · 1 line
2.39.5
Ritesh Harjani (IBM)
reviewerPATCH v2 6/18 powerpc/mm: Enable context analysis
In reply to Ritesh Harjani (IBM)powerpc/mm/ objects now build with Clang context analysis enabled. Turn it on for book3s32, book3s64 and nohash mmu.
--- arch/powerpc/mm/Makefile | 2 ++ arch/powerpc/mm/book3s32/Makefile | 2 ++ arch/powerpc/mm/book3s64/Makefile | 2 ++ arch/powerpc/mm/nohash/Makefile | 2 ++ 4 files changed, 8 insertions(+)
arch/powerpc/mm/Makefile +2 -0
@@ -3,6 +3,8 @@ # Makefile for the linux ppc-specific parts of the memory manager. # +CONTEXT_ANALYSIS := y + obj-y := fault.o mem.o pgtable.o maccess.o pageattr.o \ init_$(BITS).o pgtable_$(BITS).o \ pgtable-frag.o ioremap.o ioremap_$(BITS).o \
arch/powerpc/mm/book3s32/Makefile +2 -0
@@ -1,5 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 +CONTEXT_ANALYSIS := y + KASAN_SANITIZE_mmu.o := n ifdef CONFIG_KASAN
arch/powerpc/mm/book3s64/Makefile +2 -0
@@ -1,5 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 +CONTEXT_ANALYSIS := y + obj-y += mmu_context.o pgtable.o trace.o ifdef CONFIG_PPC_64S_HASH_MMU CFLAGS_REMOVE_slb.o = $(CC_FLAGS_FTRACE)
arch/powerpc/mm/nohash/Makefile +2 -0
@@ -1,5 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 +CONTEXT_ANALYSIS := y + obj-y += mmu_context.o tlb.o tlb_low.o kup.o obj-$(CONFIG_PPC_BOOK3E_64) += tlb_64e.o tlb_low_64e.o book3e_pgtable.o obj-$(CONFIG_44x) += 44x.o
Signature · 1 line
2.39.5
Ritesh Harjani (IBM)
reviewerPATCH v2 7/18 powerpc/pseries: Drop inline from hugepage invalidate
In reply to Ritesh Harjani (IBM)Leave __pSeries_lpar_hugepage_invalidate() static and let the compiler decide whether to inline it.
--- arch/powerpc/platforms/pseries/lpar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/platforms/pseries/lpar.c +1 -1
@@ -1225,7 +1225,7 @@ static void hugepage_bulk_invalidate(unsigned long *slot, unsigned long *vpn, } } -static inline void __pSeries_lpar_hugepage_invalidate (unsigned long *slot, +static void __pSeries_lpar_hugepage_invalidate (unsigned long *slot,unsigned long *vpn,int count,int psize,int ssize)
Signature · 1 line
2.39.5
Ritesh Harjani (IBM)
reviewerPATCH v2 8/18 powerpc/pseries: Rework hugepage invalidate to remove conditional locking
In reply to Ritesh Harjani (IBM)Clang's compiler based static context analysis does not work with locks that are conditionally taken like in __pSeries_lpar_hugepage_invalidate().
lpar.c:1240:6: error: spinlock 'pSeries_lpar_tlbie_lock' is not held on every path through here [-Werror,-Wthread-safety-analysis]
But this also simplifies the function definition in my opinion - so this is also a win.
No functional change intended.
--- arch/powerpc/platforms/pseries/lpar.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-)
arch/powerpc/platforms/pseries/lpar.c +16 -9
@@ -1224,26 +1224,33 @@ static void hugepage_bulk_invalidate(unsigned long *slot, unsigned long *vpn,BUG_ON (rc !=H_SUCCESS ); } } - -static void __pSeries_lpar_hugepage_invalidate (unsigned long *slot, +static void __pSeries_lpar_hugepage_invalidate_unlocked (unsigned long *slot,unsigned long *vpn,int count,int psize,int ssize) { -unsigned long flags =0 ; -int lock_tlbie = !mmu_has_feature (MMU_FTR_LOCKLESS_TLBIE ); - -if (lock_tlbie) -spin_lock_irqsave (&pSeries_lpar_tlbie_lock, flags); -/* Assuming THP size is 16M */ if (is_supported_hlbkrm (psize,MMU_PAGE_16M ))hugepage_block_invalidate (slot, vpn, count, psize, ssize);else hugepage_bulk_invalidate (slot, vpn, count, psize, ssize); +} -if (lock_tlbie) +static void __pSeries_lpar_hugepage_invalidate (unsigned long *slot, +unsigned long *vpn, +int count,int psize, +int ssize) +{ +unsigned long flags =0 ; + +if (!mmu_has_feature (MMU_FTR_LOCKLESS_TLBIE )) { +spin_lock_irqsave (&pSeries_lpar_tlbie_lock, flags); +__pSeries_lpar_hugepage_invalidate_unlocked (slot, vpn, count, psize, ssize);spin_unlock_irqrestore (&pSeries_lpar_tlbie_lock, flags); +return ; + } + +__pSeries_lpar_hugepage_invalidate_unlocked (slot, vpn, count, psize, ssize); } static void pSeries_lpar_hugepage_invalidate(unsigned long vsid,
Signature · 1 line
2.39.5
Ritesh Harjani (IBM)
reviewerPATCH v2 9/18 powerpc/pseries: Rework hash flush to remove conditional locking
In reply to Ritesh Harjani (IBM)Clang's compiler based static context analysis does not work with locks that are conditionally taken like in pSeries_lpar_flush_hash_range().
This also simplifies the function definition in my opinion - so this is also a win.
No functional change intended.
--- arch/powerpc/platforms/pseries/lpar.c | 31 ++++++++++++++++----------- 1 file changed, 18 insertions(+), 13 deletions(-)
arch/powerpc/platforms/pseries/lpar.c +18 -13
@@ -1526,28 +1526,19 @@ void __init pseries_lpar_read_hblkrm_characteristics(void) bpsize, idx, hblkrm_size[bpsize][idx]); } -/* -* Take a spinlock around flushes to avoid bouncing the hypervisor tlbie -* lock. -*/ -static void pSeries_lpar_flush_hash_range (unsigned long number,int local) +static void pSeries_lpar_flush_hash_range_unlocked (unsigned long number,int local) {unsigned long vpn;unsigned long i, pix, rc; -unsigned long flags =0 ;struct ppc64_tlb_batch *batch =this_cpu_ptr (&ppc64_tlb_batch); -int lock_tlbie = !mmu_has_feature (MMU_FTR_LOCKLESS_TLBIE );unsigned long param[PLPAR_HCALL9_BUFSIZE ];unsigned long index, shift, slot;real_pte_t pte;int psize, ssize; -if (lock_tlbie) -spin_lock_irqsave (&pSeries_lpar_tlbie_lock, flags); -if (is_supported_hlbkrm (batch->psize, batch->psize)) {do_block_remove (number, batch, param); - goto out; +return ; } psize = batch->psize;
@@ -1587,10 +1578,24 @@ static void pSeries_lpar_flush_hash_range(unsigned long number, int local) param[6], param[7]);BUG_ON (rc !=H_SUCCESS ); } +} -out: -if (lock_tlbie) +/* +* Take a spinlock around flushes to avoid bouncing the hypervisor tlbie +* lock. Firmware with MMU_FTR_LOCKLESS_TLBIE does not need it. +*/ +static void pSeries_lpar_flush_hash_range (unsigned long number,int local) +{ +unsigned long flags; + +if (!mmu_has_feature (MMU_FTR_LOCKLESS_TLBIE )) { +spin_lock_irqsave (&pSeries_lpar_tlbie_lock, flags); +pSeries_lpar_flush_hash_range_unlocked (number, local);spin_unlock_irqrestore (&pSeries_lpar_tlbie_lock, flags); +return ; + } + +pSeries_lpar_flush_hash_range_unlocked (number, local); }static int __init disable_bulk_remove (char *str)
Signature · 1 line
2.39.5
Ritesh Harjani (IBM)
reviewerPATCH v2 10/18 powerpc/pseries: Add context annotations for the DTL worker lock
In reply to Ritesh Harjani (IBM)dtl_worker_{enable,disable}() needs annotations since they acquire and release locks. So this adds conditional annotation based on return value.
Let's also disable context analysis for vcpudispatch_stats_write(), since based on received input, it can leave the lock held until a later write of 0 unlocks it. So we need to mark it with __context_unsafe().
Otherwise we get following error on enabling CONTEXT_ANALYSIS on this
file:
lpar.c:490:9: error: rw_semaphore 'dtl_access_lock' is not held on every path through here [-Werror,-Wthread-safety-analysis] lpar.c:498:2: error: releasing rw_semaphore 'dtl_access_lock' that was not held [-Werror,-Wthread-safety-analysis]
--- arch/powerpc/platforms/pseries/lpar.c | 3 +++ 1 file changed, 3 insertions(+)
arch/powerpc/platforms/pseries/lpar.c +3 -0
@@ -461,6 +461,7 @@ static void reset_global_dtl_mask(void) }static int dtl_worker_enable (unsigned long *time_limit) + __cond_acquires(0, &dtl_access_lock) {int rc =0 , state;
@@ -491,6 +492,7 @@ static int dtl_worker_enable(unsigned long *time_limit) }static void dtl_worker_disable (unsigned long *time_limit) + __releases(&dtl_access_lock) {cpuhp_remove_state (dtl_worker_state);free_dtl_buffers (time_limit);
@@ -500,6 +502,7 @@ static void dtl_worker_disable(unsigned long *time_limit)static ssize_t vcpudispatch_stats_write (struct file *file,const char __user *p,size_t count,loff_t *ppos) +__context_unsafe (/* dtl_access_lock is held from enable write until disable write */ ) {unsigned long time_limit = jiffies +HZ ;struct vcpu_dispatch_data *disp;
Signature · 1 line
2.39.5
Ritesh Harjani (IBM)
reviewerPATCH v2 11/18 powerpc/pseries: Annotate the VPD sequence lock context
In reply to Ritesh Harjani (IBM)Clang's context analysis reports:
papr-vpd.c:151:1: error: mutex 'rtas_ibm_get_vpd_lock' is still held at the end of function [-Werror,-Wthread-safety-analysis] papr-vpd.c:165:2: error: releasing mutex 'rtas_ibm_get_vpd_lock' that was not held [-Werror,-Wthread-safety-analysis]
Add the necessary annotations to in vpd_sequence_{begin|end}(), to fix these errors for enabling Clang context analysis.
--- arch/powerpc/platforms/pseries/papr-vpd.c | 3 +++ 1 file changed, 3 insertions(+)
arch/powerpc/platforms/pseries/papr-vpd.c +3 -0
@@ -123,8 +123,10 @@ static int rtas_ibm_get_vpd(struct rtas_ibm_get_vpd_params *params)* @seq: vpd call parameters from sequence struct * * Context: May sleep. +* Returns with rtas_ibm_get_vpd_lock held. vpd_sequence_end() releases it. */ static void vpd_sequence_begin (struct papr_rtas_sequence *seq) + __acquires(&rtas_ibm_get_vpd_lock) {struct rtas_ibm_get_vpd_params *vpd_params;/*
@@ -157,6 +159,7 @@ static void vpd_sequence_begin(struct papr_rtas_sequence *seq)* Releases resources obtained by vpd_sequence_begin(). */ static void vpd_sequence_end (struct papr_rtas_sequence *seq) + __releases(&rtas_ibm_get_vpd_lock) {struct rtas_ibm_get_vpd_params *vpd_params;
Signature · 1 line
2.39.5
Ritesh Harjani (IBM)
reviewerPATCH v2 12/18 powerpc/pseries: Annotate the RTAS indices sequence lock context
In reply to Ritesh Harjani (IBM)Clang's context analysis reports:
papr-indices.c:145:1: error: mutex 'rtas_ibm_get_indices_lock' is still held at the end of function [-Werror,-Wthread-safety-analysis] papr-indices.c:158:2: error: releasing mutex 'rtas_ibm_get_indices_lock' that was not held [-Werror,-Wthread-safety-analysis]
Add the necessary annotations to indices_sequence_{begin|end}(), to fix these errors for enabling Clang context analysis.
--- arch/powerpc/platforms/pseries/papr-indices.c | 3 +++ 1 file changed, 3 insertions(+)
arch/powerpc/platforms/pseries/papr-indices.c +3 -0
@@ -126,8 +126,10 @@ static int rtas_ibm_get_indices(struct rtas_get_indices_params *params)* indices_sequence_begin() - Begin a indices retrieval sequence. * * Context: May sleep. +* Returns with rtas_ibm_get_indices_lock held. indices_sequence_end() releases it. */ static void indices_sequence_begin (struct papr_rtas_sequence *seq) + __acquires(&rtas_ibm_get_indices_lock) {struct rtas_get_indices_params *param;
@@ -150,6 +152,7 @@ static void indices_sequence_begin(struct papr_rtas_sequence *seq)* Releases resources obtained by indices_sequence_begin(). */ static void indices_sequence_end (struct papr_rtas_sequence *seq) + __releases(&rtas_ibm_get_indices_lock) {struct rtas_get_indices_params *param;
Signature · 1 line
2.39.5
Ritesh Harjani (IBM)
reviewerPATCH v2 13/18 powerpc/pseries: Annotate the RTAS physical-attestation sequence lock context
In reply to Ritesh Harjani (IBM)Clang's context analysis reports:
papr-phy-attest.c:154:1: error: mutex 'rtas_ibm_physical_attestation_lock' is still held at the end of function [-Werror,-Wthread-safety-analysis] papr-phy-attest.c:169:2: error: releasing mutex 'rtas_ibm_physical_attestation_lock' that was not held [-Werror,-Wthread-safety-analysis]
Add the necessary annotations to phy_attest_sequence_{begin|end}(), to fix these errors for enabling Clang context analysis.
--- arch/powerpc/platforms/pseries/papr-phy-attest.c | 4 ++++ 1 file changed, 4 insertions(+)
arch/powerpc/platforms/pseries/papr-phy-attest.c +4 -0
@@ -133,8 +133,11 @@ static int rtas_physical_attestation(struct rtas_phy_attest_params *params)* @seq: user specified parameters for RTAS call from seq struct. * * Context: May sleep. +* Returns with rtas_ibm_physical_attestation_lock held. +* phy_attest_sequence_end() releases it. */ static void phy_attest_sequence_begin (struct papr_rtas_sequence *seq) + __acquires(&rtas_ibm_physical_attestation_lock) {struct rtas_phy_attest_params *param;
@@ -161,6 +164,7 @@ static void phy_attest_sequence_begin(struct papr_rtas_sequence *seq)* Releases resources obtained by phy_attest_sequence_begin(). */ static void phy_attest_sequence_end (struct papr_rtas_sequence *seq) + __releases(&rtas_ibm_physical_attestation_lock) {struct rtas_phy_attest_params *param;
Signature · 1 line
2.39.5
Ritesh Harjani (IBM)
reviewerPATCH v2 14/18 powerpc/pseries: Annotate the DTL debugfs read lock context
In reply to Ritesh Harjani (IBM)Clang's context analysis reports:
dtl.c: error: rw_semaphore 'dtl_access_lock' is still held at the end of function [-Werror,-Wthread-safety-analysis] dtl.c: error: releasing rw_semaphore 'dtl_access_lock' that was not held [-Werror,-Wthread-safety-analysis]
Add the necessary annotations to
dtl_{enable|disable}(), dtl_file{open|release}(),to fix these errors for enabling Clang context analysis.
--- arch/powerpc/platforms/pseries/dtl.c | 8 ++++++++ 1 file changed, 8 insertions(+)
arch/powerpc/platforms/pseries/dtl.c +8 -0
@@ -177,7 +177,12 @@ static u64 dtl_current_index(struct dtl *dtl) }#endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */ +/* +* On success the read lock stays held until dtl_disable(). That covers +* the whole time the debugfs file is open. +*/ static int dtl_enable (struct dtl *dtl) + __cond_acquires_shared(0, &dtl_access_lock) {long int n_entries;long int rc;
@@ -225,6 +230,7 @@ static int dtl_enable(struct dtl *dtl) }static void dtl_disable (struct dtl *dtl) + __releases_shared(&dtl_access_lock) {spin_lock (&dtl->lock);dtl_stop (dtl);
@@ -238,6 +244,7 @@ static void dtl_disable(struct dtl *dtl)/* file interface */ static int dtl_file_open (struct inode *inode,struct file *filp) + __cond_acquires_shared(0, &dtl_access_lock) {struct dtl *dtl = inode->i_private;int rc;
@@ -251,6 +258,7 @@ static int dtl_file_open(struct inode *inode, struct file *filp) }static int dtl_file_release (struct inode *inode,struct file *filp) + __releases_shared(&dtl_access_lock) {struct dtl *dtl = inode->i_private;dtl_disable (dtl);
Signature · 1 line
2.39.5
Ritesh Harjani (IBM)
reviewerPATCH v2 15/18 powerpc/pseries: Disable context analysis for the CMM hotplug notifier
In reply to Ritesh Harjani (IBM)Clang's context analysis reports:
cmm.c: error: mutex 'hotplug_mutex' is still held at the end of function [-Werror,-Wthread-safety-analysis] cmm.c: error: releasing mutex 'hotplug_mutex' that was not held [-Werror,-Wthread-safety-analysis]
cmm_memory_cb() takes hotplug_mutex on MEM_GOING_OFFLINE and drops it on a later MEM_OFFLINE or MEM_CANCEL_OFFLINE call.
Add __context_unsafe() annotation for cmm_memory_cb() callback to avoid the reported build error in order to enable Clang context analysis.
--- arch/powerpc/platforms/pseries/cmm.c | 1 + 1 file changed, 1 insertion(+)
arch/powerpc/platforms/pseries/cmm.c +1 -0
@@ -470,6 +470,7 @@ static struct notifier_block cmm_reboot_nb = {**/ static int cmm_memory_cb (struct notifier_block *self,unsigned long action,void *arg) +__context_unsafe (/* Conditional locking */ ) {switch (action) {case MEM_GOING_OFFLINE :
Signature · 1 line
2.39.5
Ritesh Harjani (IBM)
reviewerPATCH v2 16/18 powerpc/pseries: Enable context analysis
In reply to Ritesh Harjani (IBM)pseries objects now build with Clang context analysis enabled. Turn it on for the directory.
This checks that each lock taken in this code is dropped on every path.
--- arch/powerpc/platforms/pseries/Makefile | 3 +++ 1 file changed, 3 insertions(+)
arch/powerpc/platforms/pseries/Makefile +3 -0
@@ -1,4 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 + +CONTEXT_ANALYSIS := y + ccflags-$(CONFIG_PPC_PSERIES_DEBUG) += -DDEBUG obj-y := lpar.o hvCall.o nvram.o reconfig.o \
Signature · 1 line
2.39.5
Ritesh Harjani (IBM)
reviewerPATCH v2 17/18 powerpc/powernv: Rework OPAL console write to remove conditional locking
In reply to Ritesh Harjani (IBM)Clang's context analysis reports:
opal.c:454:7: error: spinlock 'opal_write_lock' is not held on every path through here [-Werror,-Wthread-safety-analysis] opal.c:493:3: error: releasing spinlock 'opal_write_lock' that was not held [-Werror,-Wthread-safety-analysis]
This patch rework the OPAL console write function to remove this conditional locking to fix the reported build errors while enabling Clang context analysis. We could have marked __context_unsafe(), but this anyways simplifies the locking a bit.
--- arch/powerpc/platforms/powernv/opal.c | 30 ++++++++++++++++++--------- 1 file changed, 20 insertions(+), 10 deletions(-)
arch/powerpc/platforms/powernv/opal.c +20 -10
@@ -438,19 +438,13 @@ ssize_t opal_get_chars(uint32_t vtermno, u8 *buf, size_t count)return 0 ; } -static ssize_t __opal_put_chars (uint32_t vtermno,const u8 *data, -size_t total_len,bool atomic) +static ssize_t __opal_put_chars_unlocked (uint32_t vtermno,const u8 *data, +size_t total_len,bool atomic) { -unsigned long flags =0 /* shut up gcc */ ;ssize_t written;__be64 olen;s64 rc; -if (!opal.entry) -return -ENODEV ; - -if (atomic) -spin_lock_irqsave (&opal_write_lock, flags); rc =opal_console_write_buffer_space (vtermno, &olen);if (rc ||be64_to_cpu (olen) < total_len) {/* Closed -> drop characters */
@@ -489,10 +483,26 @@ static ssize_t __opal_put_chars(uint32_t vtermno, const u8 *data, } out: -if (atomic) +return written; +} + +static ssize_t __opal_put_chars (uint32_t vtermno,const u8 *data, +size_t total_len,bool atomic) +{ +unsigned long flags =0 ; +ssize_t written; + +if (!opal.entry) +return -ENODEV ; + +if (atomic) { +spin_lock_irqsave (&opal_write_lock, flags); + written =__opal_put_chars_unlocked (vtermno, data, total_len, true);spin_unlock_irqrestore (&opal_write_lock, flags); +return written; + } -return written; +return __opal_put_chars_unlocked (vtermno, data, total_len, false); }ssize_t opal_put_chars (uint32_t vtermno,const u8 *data,size_t total_len)
Signature · 1 line
2.39.5
Ritesh Harjani (IBM)
reviewerPATCH v2 18/18 powerpc/powernv: Enable context analysis
In reply to Ritesh Harjani (IBM)powernv objects now build with Clang context analysis enabled. Turn it on for the directory.
This checks that each lock taken in this code is dropped on every path.
--- arch/powerpc/platforms/powernv/Makefile | 2 ++ 1 file changed, 2 insertions(+)
arch/powerpc/platforms/powernv/Makefile +2 -0
@@ -1,5 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 +CONTEXT_ANALYSIS := y + # nothing that deals with real mode is safe to KASAN # in particular, idle code runs a bunch of things in real mode KASAN_SANITIZE_idle.o := n
Signature · 1 line
2.39.5