s390: Enable CONTEXT_ANALYSIS for various directories
Heiko Carstens
maintainercover s390: Enable CONTEXT_ANALYSIS for various directories
Enable CONTEXT_ANALYSYS for various directories.
Static code checking for acquiring and releasing locks used to be done with sparse. That was removed with [1] and replaced with a clang based approach [2]. The new approach requires that each subsystem needs to be explicitly enabled for checking.
Do that for various directories. In order to avoid valid warnings add attributes (sysinfo), or disable context analysis for specific functions (mm). Disabling context analysis for specific functions still keeps analysis enabled for the rest of a file.
[1] 5b63d0ae94cc ("compiler-context-analysis: Remove Sparse support")
[2] 3269701cb256 ("compiler-context-analysis: Add infrastructure for Context Analysis with Clang")
Notes:
- More patches for other s390 specific subsystems will follow
- "Pre-existing issues" reported by AI will not be addressed in the context of this series
Heiko Carstens (4):
s390/sysinfo: Add context analysis attributes
s390/mm: Add __context_unsafe() attribute to do_secure_storage_access() s390/mm: Add __context_unsafe() attribute to gmap helper functions
s390: Enable CONTEXT_ANALYSIS for various directories
arch/s390/appldata/Makefile | 2 ++ arch/s390/hypfs/Makefile | 2 ++ arch/s390/kernel/Makefile | 2 ++ arch/s390/kernel/sysinfo.c | 2 ++ arch/s390/lib/Makefile | 2 ++ arch/s390/mm/Makefile | 2 ++ arch/s390/mm/fault.c | 1 + arch/s390/mm/gmap_helpers.c | 3 +++ arch/s390/net/Makefile | 3 +++ arch/s390/purgatory/Makefile | 2 ++ 10 files changed, 21 insertions(+)
Signature · 1 line
2.53.0
Heiko Carstens
maintainerPATCH 1/4 s390/sysinfo: Add context analysis attributes
Add context analysis attributes to service_level_start() and service_level_stop() to specify that those functions only acquire or release a lock.
Addresses the following warnings:
arch/s390/kernel/sysinfo.c:331:1: warning: rw_semaphore 'service_level_sem' is still held at the end of function arch/s390/kernel/sysinfo.c:329:2: note: rw_semaphore acquired here
329 | down_read(&service_level_sem);arch/s390/kernel/sysinfo.c:340:2: warning: releasing rw_semaphore 'service_level_sem' that was not held
340 | up_read(&service_level_sem);
--- arch/s390/kernel/sysinfo.c | 2 ++ 1 file changed, 2 insertions(+)
arch/s390/kernel/sysinfo.c +2 -0
@@ -325,6 +325,7 @@ int unregister_service_level(struct service_level *slr)EXPORT_SYMBOL (unregister_service_level);static void *service_level_start (struct seq_file *m,loff_t *pos) +__acquires_shared (service_level_sem) {down_read (&service_level_sem);return seq_list_start (&service_level_list, *pos);
@@ -336,6 +337,7 @@ static void *service_level_next(struct seq_file *m, void *p, loff_t *pos) }static void service_level_stop (struct seq_file *m,void *p) +__releases_shared (service_level_sem) {up_read (&service_level_sem); }
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH 1/4] s390/sysinfo: Add context analysis attributes
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 lines
Add context analysis attributes to
service_level_start()andservice_level_stop()to specify that those functions only acquire or release a lock.Addresses the following warnings:
Quoted 7 lines
arch/s390/kernel/sysinfo.c:331:1: warning:rw_semaphore'service_level_sem' is still held at the end of functionarch/s390/kernel/sysinfo.c:329:2: note:rw_semaphoreacquired here
329 |down_read(&service_level_sem);arch/s390/kernel/sysinfo.c:340:2: warning: releasingrw_semaphore'service_level_sem' that was not held
340 |up_read(&service_level_sem);Signed-off-by Heiko Carstens <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Heiko Carstens
maintainerPATCH 2/4 s390/mm: Add __context_unsafe() attribute to do_secure_storage_access()
In reply to Heiko CarstensCompiling do_secure_storage_access() with context analysis enabled results in this warning:
arch/s390/mm/fault.c:472:3: warning: releasing spinlock 'fw.ptl' that was not held
472 | folio_walk_end(&fw, vma);
Problem is that folio_walk_end() comes without the required context analysis attribute. Also the proper attribute cannot be added easily, since folio_walk_end() is a macro, and not a function.
For the time being disable context analysis only for do_secure_storage_access() until this is resolved.
--- arch/s390/mm/fault.c | 1 + 1 file changed, 1 insertion(+)
arch/s390/mm/fault.c +1 -0
@@ -406,6 +406,7 @@ NOKPROBE_SYMBOL(do_dat_exception);#if IS_ENABLED (CONFIG_KVM )void do_secure_storage_access (struct pt_regs *regs) +__context_unsafe (/* folio_walk_end() not instrumented */ ) {union teid teid = { .val = regs->int_parm_long };unsigned long addr =get_fault_address (regs);
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH 2/4] s390/mm: Add __context_unsafe() attribute to do_secure_storage_access()
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Using find_vma() instead of vma_lookup() in do_secure_storage_access() allows an unprivileged user to trigger a WARN_ON_ONCE if a secure storage access exception races with an unmap operation or occurs on an unmapped address. --
--- Patch [2]: [PATCH 2/4] s390/mm: Add __context_unsafe() attribute to do_secure_storage_access() --- commit 679818f3abe10b8b5132294910a12a6eb003e99e
Author: Heiko Carstens <[email protected]>
s390/mm: Add __context_unsafe() attribute to do_secure_storage_access()
This commit disables context analysis for do_secure_storage_access() by adding the __context_unsafe() attribute. This prevents a warning during compilation about releasing a spinlock that wasn't held, which occurs because folio_walk_end() is a macro and lacks the necessary context analysis attribute.
arch/s390/mm/fault.c NOKPROBE_SYMBOL(do_dat_exception); · line 410
Quoted 10 lines
arch/s390/mm/fault.c +1
-0@@ -406,6 +406,7 @@ NOKPROBE_SYMBOL(do_dat_exception);#if IS_ENABLED (CONFIG_KVM )void do_secure_storage_access (struct pt_regs *regs) +__context_unsafe (/* folio_walk_end() not instrumented */ ) {
[Severity: High]
This isn't a bug introduced by this patch, but could this function trigger a WARN_ON_ONCE that is reachable by unprivileged users?
Later in do_secure_storage_access(), find_vma() is called instead of vma_lookup():
arch/s390/mm/fault.c:do_secure_storage_access() {
...
mmap_read_lock(mm);
vma = find_vma(mm, addr);
if (!vma)
return handle_fault_error(regs, SEGV_MAPERR);
folio = folio_walk_start(&fw, vma, addr, 0);
...
}If a secure storage access exception races with an unmap operation via munmap(), or occurs on an unmapped address, find_vma() returns the next VMA in the address space where vma->vm_start > addr.
When this VMA is passed to folio_walk_start(), it hits the explicit WARN_ON_ONCE(addr < vma->vm_start || addr >= vma->vm_end) check.
With panic_on_warn enabled, could this allow an unprivileged process manipulating its own memory to cause a denial of service?
Quoted 2 lines
arch/s390/mm/fault.c +0
-0union teid teid = { .val = regs->int_parm_long };unsigned long addr =get_fault_address (regs);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Heiko Carstens
maintainerPATCH 3/4 s390/mm: Add __context_unsafe() attribute to gmap helper functions
In reply to Heiko CarstensDisable context analysis for various gmap helper functions to get rid of a few warnings:
arch/s390/mm/gmap_helpers.c:80:1: warning: spinlock 'ptl' is not held on every path through here arch/s390/mm/gmap_helpers.c:116:2: warning: releasing spinlock 'ptl' that was not held arch/s390/mm/gmap_helpers.c:186:2: warning: releasing spinlock 'ptl' that was not held
Use __context_unsafe() to give a short comment why for function context analysis is disabled.
try_get_locked_pte() is disabled since it may return a nonull value regardless if it returns with a lock held or not.
This cannot be reflected with the context analysis attributes. It is however possible to workaround this e.g. by adding a another contended function parameter, however this would lead to the next problem:pte_unmap_unlock() is a macro and therefore doesn't come with the required context analysis attribute to address this.
For that reason also disable context analysis for gmap_helper_zap_one_page() and gmap_helper_try_set_pte_unused() until this has been addressed.
--- arch/s390/mm/gmap_helpers.c | 3 +++ 1 file changed, 3 insertions(+)
arch/s390/mm/gmap_helpers.c +3 -0
@@ -40,6 +40,7 @@* and locked. */ pte_t *try_get_locked_pte (struct mm_struct *mm,unsigned long vmaddr,spinlock_t **ptl) +__context_unsafe (/* Returns nonnull if lock taken or not taken */ ) {pmd_t *pmdp, pmd, pmdval;pud_t *pudp, pud;
@@ -90,6 +91,7 @@ EXPORT_SYMBOL_GPL(try_get_locked_pte);* Context: needs to be called while holding the mmap lock. */ void gmap_helper_zap_one_page (struct mm_struct *mm,unsigned long vmaddr) +__context_unsafe (/* pte_unmap_unlock() not instrumented */ ) {struct vm_area_struct *vma;spinlock_t *ptl;/* Lock for the host (userspace) page table */
@@ -161,6 +163,7 @@ EXPORT_SYMBOL_GPL(gmap_helper_discard);* disabled. */ void gmap_helper_try_set_pte_unused (struct mm_struct *mm,unsigned long vmaddr) +__context_unsafe (/* pte_unmap_unlock() not instrumented */ ) {spinlock_t *ptl;/* Lock for the host (userspace) page table */ pte_t *ptep;
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH 3/4] s390/mm: Add __context_unsafe() attribute to gmap helper functions
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 19 lines
Disable context analysis for various gmap helper functions to get rid of a few warnings:
arch/s390/mm/gmap_helpers.c:80:1: warning: spinlock 'ptl' is not held on every path through herearch/s390/mm/gmap_helpers.c:116:2: warning: releasing spinlock 'ptl' that was not heldarch/s390/mm/gmap_helpers.c:186:2: warning: releasing spinlock 'ptl' that was not heldUse
__context_unsafe()to give a short comment why for function context analysis is disabled.
try_get_locked_pte()is disabled since it may return a nonull value regardless if it returns with a lock held or not.This cannot be reflected with the context analysis attributes. It is however possible to workaround this e.g. by adding a another
contendedfunction parameter, however this would lead to the next problem:pte_unmap_unlock()is a macro and therefore doesn't come with the required context analysis attribute to address this.
Quoted 5 lines
For that reason also disable context analysis for
gmap_helper_zap_one_page()andgmap_helper_try_set_pte_unused()until this has been addressed.Signed-off-by Heiko Carstens <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Re: [PATCH 3/4] s390/mm: Add __context_unsafe() attribute to gmap helper functions
In reply to Heiko CarstensQuoted 19 lines · On Mon, 3 Aug 2026 19:21:43 +0200 Heiko Carstens <[email protected]> wrote:
Disable context analysis for various gmap helper functions to get rid of a few warnings:
arch/s390/mm/gmap_helpers.c:80:1: warning: spinlock 'ptl' is not held on every path through herearch/s390/mm/gmap_helpers.c:116:2: warning: releasing spinlock 'ptl' that was not heldarch/s390/mm/gmap_helpers.c:186:2: warning: releasing spinlock 'ptl' that was not heldUse
__context_unsafe()to give a short comment why for function context analysis is disabled.
try_get_locked_pte()is disabled since it may return a nonull value regardless if it returns with a lock held or not.This cannot be reflected with the context analysis attributes. It is however possible to workaround this e.g. by adding a another
contendedfunction parameter, however this would lead to the next problem:pte_unmap_unlock()is a macro and therefore doesn't come with the required context analysis attribute to address this.
Quoted 5 lines
For that reason also disable context analysis for
gmap_helper_zap_one_page()andgmap_helper_try_set_pte_unused()until this has been addressed.Signed-off-by Heiko Carstens <[email protected]>
Quoted 32 lines
--- arch/s390/mm/gmap_helpers.c | 3 +++ 1 file changed, 3 insertions(+)arch/s390/mm/gmap_helpers.c +3
-0@@ -40,6 +40,7 @@* and locked. */ pte_t *try_get_locked_pte (struct mm_struct *mm,unsigned long vmaddr,spinlock_t **ptl) +__context_unsafe (/* Returns nonnull if lock taken or not taken */ ) {pmd_t *pmdp, pmd, pmdval;pud_t *pudp, pud;@@ -90,6 +91,7 @@ EXPORT_SYMBOL_GPL(try_get_locked_pte);* Context: needs to be called while holding the mmap lock. */ void gmap_helper_zap_one_page (struct mm_struct *mm,unsigned long vmaddr) +__context_unsafe (/* pte_unmap_unlock() not instrumented */ ) {struct vm_area_struct *vma;spinlock_t *ptl;/* Lock for the host (userspace) page table */ @@ -161,6 +163,7 @@ EXPORT_SYMBOL_GPL(gmap_helper_discard);* disabled. */ void gmap_helper_try_set_pte_unused (struct mm_struct *mm,unsigned long vmaddr) +__context_unsafe (/* pte_unmap_unlock() not instrumented */ ) {spinlock_t *ptl;/* Lock for the host (userspace) page table */ pte_t *ptep;
Heiko Carstens
maintainerPATCH 4/4 s390: Enable CONTEXT_ANALYSIS for various directories
In reply to Heiko CarstensEnable CONTEXT_ANALYSIS for various directories which do not generate any warnings (anymore).
--- arch/s390/appldata/Makefile | 2 ++ arch/s390/hypfs/Makefile | 2 ++ arch/s390/kernel/Makefile | 2 ++ arch/s390/lib/Makefile | 2 ++ arch/s390/mm/Makefile | 2 ++ arch/s390/net/Makefile | 3 +++ arch/s390/purgatory/Makefile | 2 ++ 7 files changed, 15 insertions(+)
arch/s390/appldata/Makefile +2 -0
@@ -3,6 +3,8 @@ # Makefile for the Linux - z/VM Monitor Stream. # +CONTEXT_ANALYSIS := y + obj-$(CONFIG_APPLDATA_BASE) += appldata_base.o obj-$(CONFIG_APPLDATA_MEM) += appldata_mem.o obj-$(CONFIG_APPLDATA_OS) += appldata_os.o
arch/s390/hypfs/Makefile +2 -0
@@ -3,6 +3,8 @@ # Makefile for the linux hypfs filesystem routines. # +CONTEXT_ANALYSIS := y + obj-$(CONFIG_S390_HYPFS) += hypfs_dbfs.o obj-$(CONFIG_S390_HYPFS) += hypfs_diag.o obj-$(CONFIG_S390_HYPFS) += hypfs_diag0c.o
arch/s390/kernel/Makefile +2 -0
@@ -3,6 +3,8 @@ # Makefile for the linux kernel. # +CONTEXT_ANALYSIS := y + ifdef CONFIG_FUNCTION_TRACER # Do not trace tracer code
arch/s390/lib/Makefile +2 -0
@@ -3,6 +3,8 @@ # Makefile for s390-specific library files.. # +CONTEXT_ANALYSIS := y + # string.o implements standard library functions like memset/memcpy etc. # Use -ffreestanding to ensure that the compiler does not try to "optimize" # them into calls to themselves.
arch/s390/mm/Makefile +2 -0
@@ -3,6 +3,8 @@ # Makefile for the linux s390-specific parts of the memory manager. # +CONTEXT_ANALYSIS := y + obj-y := init.o fault.o extmem.o mmap.o vmem.o maccess.o obj-y += page-states.o pageattr.o pgtable.o pgalloc.o extable.o
arch/s390/net/Makefile +3 -0
@@ -2,5 +2,8 @@ # # Arch-specific network modules # + +CONTEXT_ANALYSIS := y + obj-$(CONFIG_BPF_JIT) += bpf_jit_comp.o bpf_timed_may_goto.o obj-$(CONFIG_HAVE_PNETID) += pnet.o
arch/s390/purgatory/Makefile +2 -0
@@ -1,5 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 +CONTEXT_ANALYSIS := y + purgatory-y := head.o purgatory.o string.o sha256.o targets += $(purgatory-y) purgatory.lds purgatory purgatory.chk purgatory.ro
Signature · 1 line
2.53.0
[email protected]
AI reviewSashiko has reviewed this patch and found no issues. It looks great!
Quoted 4 lines
Enable
CONTEXT_ANALYSISfor various directories which do not generate any warnings (anymore).Signed-off-by Heiko Carstens <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4