From nobody Mon Feb 9 03:45:35 2026 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 13DE934D3AC for ; Fri, 19 Dec 2025 15:46:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766159216; cv=none; b=InuFPffdwU+/Ht+pSwjfRD1OSPXJhfvQK1W9J/9P5bBeQiOZLlOs414u2GXFaMC/he1StlO4MDgIMpMJWRQtVLw92FwZ0pE26JSFVMMezRs7M7CftY8WaB1hGfuFsRvaOcbeoKMglZMePO9jK/wlrPRwuQYTRp5Y9A82NHpvfWk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766159216; c=relaxed/simple; bh=ffn5A72rAl7FAFjS1rk5YlULl8qajeM/K30VyhzfQ+s=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=PWXyPByw5sh2QGMXh6G3mfrbsf2+vIeaZff/yFRfob4LZNim3GgSWgDX4w7cirBD+xLQ6JhFekYM/BPbs2pWsfLoxF79qBn2uhdnEzL1zpPuzmz9G1ExzwCOLzNaeZUOwiqjF+EyAZuHJ1YoPZHwXfetAzKLmlNFmWENyiSxtzM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--elver.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=cKbw4Wbp; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--elver.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="cKbw4Wbp" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-477563e531cso12949115e9.1 for ; Fri, 19 Dec 2025 07:46:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1766159212; x=1766764012; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=BPiD3KqRf4YAgh6EJvt9JR+cuwWr4Dg7H+dSvPnSAFc=; b=cKbw4WbpL+Cvqd22rO3gflpWRfLXWYBA5lTrVXemFojS3IzY5B9bWRbqDk2NK0N5t+ S5DGaTfJHL9AqeYURPH5JK9KoHPOx9g7bg1oGlDBd5GIM6jdMJ/GYz0brlm5FgEwe3/R 8hzLlb7c2OIt0Cz3ZEsSa5XLsFON5bYu4TWEly9dZ54gGSaJ1d5Fn2IqyQv0ACbeidRj 5AvEhmdol57VZWfEu7fgZNF/nPMGpICpSyo/4PHezLaG/9mBryDgF9i+ajBGDFX/Q2wW tFpczKzYxk4WX11wkI5XPDZVYqjZOqtv3il3BJ6fDvOV3P8nlfkM9y986Cc1BrDN3PPQ 1grg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766159212; x=1766764012; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=BPiD3KqRf4YAgh6EJvt9JR+cuwWr4Dg7H+dSvPnSAFc=; b=i05G1EJiDeYzw5+qWgC+OQ2CBdXR+JA8tKZ70orMQMXkiOTPL8c8/RjizA3LyDQHSs ZfXyRk7lCkZpn40HgfVPMKDzrXPDtkW9APnmK0pAaqTl73nM6qRK4GKk1Zg4o/PslOsX Rp1UKpdXTBybCGdvy6a1HoQAONqoC3Zvr0WbUoVxNnb6QhlkPtt5KaItdarAXtMt5D7S 8zS7PIXVHy25ES0lsiZHlMIWYpVVw3Wbq/7++g+PxoqqdQ/pGD9TVhOIw8BMUV0krCTP KFJi/DXTcx0+C8ZicLto6YhsubRXplKJkTmKHYQoF3VAivVLYG4rjBKX9UVRLGXhx+uw Qplw== X-Forwarded-Encrypted: i=1; AJvYcCXlYNVFHdkYkpva+r7Fz1ID6OCz6ReNp8t8U/ySFxKoBzKndF/o8+M1ZVDcoJsavkBk4UVGJeeZMWeIE8c=@vger.kernel.org X-Gm-Message-State: AOJu0YyqUPpCv0x+TFdgt3JL9M4HW7E8QbGDXO3fILK0oTWrNN6Nx7DE 0y5zVV7ZyY08HwZrCqz9ax+DQqAoFhWDA9zBvIMBpEwOUAO8JfPxIWFgSAZ4ks4EdEvNfVkv2DE 6uw== X-Google-Smtp-Source: AGHT+IGhAhPmou604sSjPj23AvOGmEtACeK8/O1HXfeBpY2WmsP8AIbWuFkf2cEj+zrFEmw2cUXjp49BYQ== X-Received: from wmco23.prod.google.com ([2002:a05:600c:a317:b0:477:93dd:bbb1]) (user=elver job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600d:108:20b0:477:214f:bd95 with SMTP id 5b1f17b1804b1-47d1c036d6cmr18724405e9.23.1766159212483; Fri, 19 Dec 2025 07:46:52 -0800 (PST) Date: Fri, 19 Dec 2025 16:40:11 +0100 In-Reply-To: <20251219154418.3592607-1-elver@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251219154418.3592607-1-elver@google.com> X-Mailer: git-send-email 2.52.0.322.g1dd061c0dc-goog Message-ID: <20251219154418.3592607-23-elver@google.com> Subject: [PATCH v5 22/36] um: Fix incorrect __acquires/__releases annotations From: Marco Elver To: elver@google.com, Peter Zijlstra , Boqun Feng , Ingo Molnar , Will Deacon Cc: "David S. Miller" , Luc Van Oostenryck , Chris Li , "Paul E. McKenney" , Alexander Potapenko , Arnd Bergmann , Bart Van Assche , Christoph Hellwig , Dmitry Vyukov , Eric Dumazet , Frederic Weisbecker , Greg Kroah-Hartman , Herbert Xu , Ian Rogers , Jann Horn , Joel Fernandes , Johannes Berg , Jonathan Corbet , Josh Triplett , Justin Stitt , Kees Cook , Kentaro Takeda , Lukas Bulwahn , Mark Rutland , Mathieu Desnoyers , Miguel Ojeda , Nathan Chancellor , Neeraj Upadhyay , Nick Desaulniers , Steven Rostedt , Tetsuo Handa , Thomas Gleixner , Thomas Graf , Uladzislau Rezki , Waiman Long , kasan-dev@googlegroups.com, linux-crypto@vger.kernel.org, linux-doc@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-security-module@vger.kernel.org, linux-sparse@vger.kernel.org, linux-wireless@vger.kernel.org, llvm@lists.linux.dev, rcu@vger.kernel.org, kernel test robot , Johannes Berg , Tiwei Bie Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" With Clang's context analysis, the compiler is a bit more strict about what goes into the __acquires/__releases annotations and can't refer to non-existent variables. On an UM build, mm_id.h is transitively included into mm_types.h, and we can observe the following error (if context analysis is enabled in e.g. stackdepot.c): In file included from lib/stackdepot.c:17: In file included from include/linux/debugfs.h:15: In file included from include/linux/fs.h:5: In file included from include/linux/fs/super.h:5: In file included from include/linux/fs/super_types.h:7: In file included from include/linux/list_lru.h:14: In file included from include/linux/xarray.h:16: In file included from include/linux/gfp.h:7: In file included from include/linux/mmzone.h:22: In file included from include/linux/mm_types.h:26: In file included from arch/um/include/asm/mmu.h:12: >> arch/um/include/shared/skas/mm_id.h:24:54: error: use of undeclared iden= tifier 'turnstile' 24 | void enter_turnstile(struct mm_id *mm_id) __acquires(turnstile); | ^~~~~~~~~ arch/um/include/shared/skas/mm_id.h:25:53: error: use of undeclared iden= tifier 'turnstile' 25 | void exit_turnstile(struct mm_id *mm_id) __releases(turnstile); | ^~~~~~~~~ One (discarded) option was to use token_context_lock(turnstile) to just define a token with the already used name, but that would not allow the compiler to distinguish between different mm_id-dependent instances. Another constraint is that struct mm_id is only declared and incomplete in the header, so even if we tried to construct an expression to get to the mutex instance, this would fail (including more headers transitively everywhere should also be avoided). Instead, just declare an mm_id-dependent helper to return the mutex, and use the mm_id-dependent call expression in the __acquires/__releases attributes; the compiler will consider the identity of the mutex to be the call expression. Then using __get_turnstile() in the lock/unlock wrappers (with context analysis enabled for mmu.c) the compiler will be able to verify the implementation of the wrappers as-is. We leave context analysis disabled in arch/um/kernel/skas/ for now. This change is a preparatory change to allow enabling context analysis in subsystems that include any of the above headers. No functional change intended. Closes: https://lore.kernel.org/oe-kbuild-all/202512171220.vHlvhpCr-lkp@int= el.com/ Reported-by: kernel test robot Signed-off-by: Marco Elver Cc: Johannes Berg Cc: Tiwei Bie --- arch/um/include/shared/skas/mm_id.h | 5 +++-- arch/um/kernel/skas/mmu.c | 13 ++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/arch/um/include/shared/skas/mm_id.h b/arch/um/include/shared/s= kas/mm_id.h index fb96c0bd8222..18c0621430d2 100644 --- a/arch/um/include/shared/skas/mm_id.h +++ b/arch/um/include/shared/skas/mm_id.h @@ -21,8 +21,9 @@ struct mm_id { int syscall_fd_map[STUB_MAX_FDS]; }; =20 -void enter_turnstile(struct mm_id *mm_id) __acquires(turnstile); -void exit_turnstile(struct mm_id *mm_id) __releases(turnstile); +struct mutex *__get_turnstile(struct mm_id *mm_id); +void enter_turnstile(struct mm_id *mm_id) __acquires(__get_turnstile(mm_id= )); +void exit_turnstile(struct mm_id *mm_id) __releases(__get_turnstile(mm_id)= ); =20 void notify_mm_kill(int pid); =20 diff --git a/arch/um/kernel/skas/mmu.c b/arch/um/kernel/skas/mmu.c index 00957788591b..b5017096028b 100644 --- a/arch/um/kernel/skas/mmu.c +++ b/arch/um/kernel/skas/mmu.c @@ -23,18 +23,21 @@ static_assert(sizeof(struct stub_data) =3D=3D STUB_DATA= _PAGES * UM_KERN_PAGE_SIZE); static spinlock_t mm_list_lock; static struct list_head mm_list; =20 -void enter_turnstile(struct mm_id *mm_id) __acquires(turnstile) +struct mutex *__get_turnstile(struct mm_id *mm_id) { struct mm_context *ctx =3D container_of(mm_id, struct mm_context, id); =20 - mutex_lock(&ctx->turnstile); + return &ctx->turnstile; } =20 -void exit_turnstile(struct mm_id *mm_id) __releases(turnstile) +void enter_turnstile(struct mm_id *mm_id) { - struct mm_context *ctx =3D container_of(mm_id, struct mm_context, id); + mutex_lock(__get_turnstile(mm_id)); +} =20 - mutex_unlock(&ctx->turnstile); +void exit_turnstile(struct mm_id *mm_id) +{ + mutex_unlock(__get_turnstile(mm_id)); } =20 int init_new_context(struct task_struct *task, struct mm_struct *mm) --=20 2.52.0.322.g1dd061c0dc-goog