From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (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 673823115AF for ; Tue, 28 Apr 2026 21:05:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777410330; cv=none; b=t98V2I5z6cnQ1Yrp9fTOAQe5WI12TjbMgH8e2qZIjjKPz5hyGA6F/L+r3b3uRgzEaoBZ89YfiUlg64Eq3b2npwhi8hfTmQwl3VjRb7/di0jpqEZFww9BUhYd+390VQTzuMlM16Ypzk5vhB/d21I3zr8ZVKrLv2AB4A53q/NOkPI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777410330; c=relaxed/simple; bh=tafbavSt1B9m+FpQuytKM+dZyRDCduwyt4a553hazWA=; h=Message-ID:Date:MIME-Version:To:Cc:From:Subject:Content-Type; b=QrBQuiW62GBHWVqoN8qP7k3xGrTZy+0dT291BEJgCeISgdCli4+VoM4/aM1/dDHo7s/oaZgj8+2RiWhtABMXyCDo826Ryf3KuSc3zGvE/51BfYl3TXVcPlchdQzu6rLqPSrsXiOH8nZCrDjZA0JRoBTbMv0vAz3Zl538dvXor/4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mND7BLKr; arc=none smtp.client-ip=209.85.221.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mND7BLKr" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-43cfd1f9fd1so7419071f8f.3 for ; Tue, 28 Apr 2026 14:05:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777410327; x=1778015127; darn=vger.kernel.org; h=content-transfer-encoding:subject:from:cc:to:content-language :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=JlbZeob04LDnMGja9W6KgX7+nrXPI8t4mB9ZtPfUwLg=; b=mND7BLKrpO8b/48Ugl7EFXF+HtU8/Y9gjj4TTjvs+GnGm+WXsM2UFr4dwgg8TG4KKh hoI9DISVKP0noShcWYXZtMOSNL5iG9dmQSyK3V2Vdf3X25yk9uXG5who96qU2M/67gYn g/h7Twh1/qJcQunz2S1W8NiPAi7BoqvGBww6mgBpY/id4iuosFTGzXTnOR1hbX7we/h7 qzERBjnbRRuuNgZcDiMKh7zKdQ0JVQ+ixfmjk7/SaiwWMqheUCnRtr3gSrK34gwfL//C 290Gy+zXlBu0j2gr5BaL9+RdDXeNqa10WnTFukmPGEPUgTOH8+G3ROvK3kWx3ujr5GPt pubQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777410327; x=1778015127; h=content-transfer-encoding:subject:from:cc:to:content-language :user-agent:mime-version:date:message-id:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=JlbZeob04LDnMGja9W6KgX7+nrXPI8t4mB9ZtPfUwLg=; b=azEE0FzN+RGqHhWpgflcPH/jxHZ6TfFTplfNFPYYW1vRZX/1zPoSzy0Xjo/JIxSO02 Q38ThND8zhNz9FDhlmBUCvmWLAW/M/uVHfN6oxwvQ/MXxz9B9Q1D2h3bfrj4ZFBBwNm4 ELibmH1wZNBn033r+g9CMyOIogeFXObnxqnswXqNorra6kt9wDvIVpUSrvZBZntCvA8s 0bWvYqB5Lw0iErPLx8O4jNGSgJoYhC4VFEB3LR6cMzwj/IGoyEG+Vc2FDIlDdhSyGK3R 5jWfV9RHMOjmY3RCKiEXPshOYKjv2crnUsoyU9wPMHVSMx4gdrL7VpPbVNO7EBNzC9qP Wjdw== X-Gm-Message-State: AOJu0YzF6WikG7vP+VnBz8Gh7ZHCydYh+iYNEWe/lIz2fjnJKdZFCaSJ bUtC4jzo4EYNGxddBPxXdPPa1Oizp2nhHG1OqivW8XU9dSaHdqFyX0Cc X-Gm-Gg: AeBDieuAxWKC8i65LJ1QFUTWLPpCw3stAhUlbYN4jq6vAeS1SOzRr6RaxmLvuxMq2e+ uJbb2T+8A2o5y9FHB7zSvB0oO++cyWyh+DlseaQdbSw3h8PQKWc33i1IB1BgFuJI6j+e75SzRZ9 tN/iMi4nzZdpKdcL9ejolq9Gw0vHsedaUjwBw+eLNy2xDNw9ZjDS9kmFRxRIwWDVVaHU9PD1lcJ W3Min07jA3QmH88t3mu9K1iRma/lExidcethN7YiQTvcpXz5yD3gUlA+fQNPN2CzIda+qAxbtOW maE1Ao5TZcgJJ+w/N6JlQJfeyc7fn6hHylb31BfZt+FCdbj/lPnbGwwxOyLI+1g6e3n38vPNBYX RH0K6Pn+efWFhTpTSmBAeW7/AJqYgEwl0iaYJaP16zvCKB5SiGqwByi+VJcvYDBoy1E86TVhSVG nhIYyU6lY9hHL/E3Cgc9Xu1q3/luJq8Jhu474EuF3aK+Q8xDpRMGzvDaOrnNSlhABGo22mPew9l 5/4AxvAIrLbg5vKrgG0OVgkRID25M7jq0h05qIzpePWKGhCxSIiM5acABqWVYfr9JQwp4rZ6g== X-Received: by 2002:a05:6000:2003:b0:43d:7b7b:ab77 with SMTP id ffacd0b85a97d-446493f4955mr8719648f8f.11.1777410326583; Tue, 28 Apr 2026 14:05:26 -0700 (PDT) Received: from ?IPV6:2003:ea:8f13:9d00:19ea:f9e7:298:7edf? (p200300ea8f139d0019eaf9e702987edf.dip0.t-ipconnect.de. [2003:ea:8f13:9d00:19ea:f9e7:298:7edf]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-447b4216675sm655706f8f.11.2026.04.28.14.05.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 28 Apr 2026 14:05:26 -0700 (PDT) Message-ID: Date: Tue, 28 Apr 2026 23:05:25 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Peter Zijlstra , Ingo Molnar , Will Deacon , Boqun Feng , Waiman Long Cc: Linux Kernel Mailing List From: Heiner Kallweit Subject: [PATCH] lockdep: constify usage of struct lock_class_key where possible Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Constify usage of struct lock_class_key where possible. This requires to constify also usage of struct lockdep_subclass_key in two places. Especially relevant is constification of lockdep_map.key, as it makes clear that the key isn't changed during lifetime of struct lockdep_map. Signed-off-by: Heiner Kallweit --- include/linux/lockdep.h | 18 ++++++++++-------- include/linux/lockdep_types.h | 2 +- kernel/locking/lockdep.c | 12 ++++++------ 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h index 621566345..3fa2b62f2 100644 --- a/include/linux/lockdep.h +++ b/include/linux/lockdep.h @@ -125,25 +125,27 @@ extern void lockdep_unregister_key(struct lock_class_key *key); * to lockdep: */ -extern void lockdep_init_map_type(struct lockdep_map *lock, const char *name, - struct lock_class_key *key, int subclass, u8 inner, u8 outer, u8 lock_type); +void lockdep_init_map_type(struct lockdep_map *lock, const char *name, + const struct lock_class_key *key, int subclass, + u8 inner, u8 outer, u8 lock_type); static inline void lockdep_init_map_waits(struct lockdep_map *lock, const char *name, - struct lock_class_key *key, int subclass, u8 inner, u8 outer) + const struct lock_class_key *key, int subclass, + u8 inner, u8 outer) { lockdep_init_map_type(lock, name, key, subclass, inner, outer, LD_LOCK_NORMAL); } static inline void lockdep_init_map_wait(struct lockdep_map *lock, const char *name, - struct lock_class_key *key, int subclass, u8 inner) + const struct lock_class_key *key, int subclass, u8 inner) { lockdep_init_map_waits(lock, name, key, subclass, inner, LD_WAIT_INV); } static inline void lockdep_init_map(struct lockdep_map *lock, const char *name, - struct lock_class_key *key, int subclass) + const struct lock_class_key *key, int subclass) { lockdep_init_map_wait(lock, name, key, subclass, LD_WAIT_INV); } @@ -252,9 +254,9 @@ static inline int lock_is_held(const struct lockdep_map *lock) #define lockdep_is_held(lock) lock_is_held(&(lock)->dep_map) #define lockdep_is_held_type(lock, r) lock_is_held_type(&(lock)->dep_map, (r)) -extern void lock_set_class(struct lockdep_map *lock, const char *name, - struct lock_class_key *key, unsigned int subclass, - unsigned long ip); +void lock_set_class(struct lockdep_map *lock, const char *name, + const struct lock_class_key *key, unsigned int subclass, + unsigned long ip); #define lock_set_novalidate_class(l, n, i) \ lock_set_class(l, n, &__lockdep_no_validate__, 0, i) diff --git a/include/linux/lockdep_types.h b/include/linux/lockdep_types.h index eae115a26..0d3df9019 100644 --- a/include/linux/lockdep_types.h +++ b/include/linux/lockdep_types.h @@ -184,7 +184,7 @@ void clear_lock_stats(struct lock_class *class); * This is embedded into specific lock instances: */ struct lockdep_map { - struct lock_class_key *key; + const struct lock_class_key *key; struct lock_class *class_cache[NR_LOCKDEP_CACHING_CLASSES]; const char *name; u8 wait_type_outer; /* can be taken in this context */ diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index f13883162..fe1415260 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -888,7 +888,7 @@ static int count_matching_names(struct lock_class *new_class) static noinstr struct lock_class * look_up_lock_class(const struct lockdep_map *lock, unsigned int subclass) { - struct lockdep_subclass_key *key; + const struct lockdep_subclass_key *key; struct hlist_head *hash_head; struct lock_class *class; @@ -1286,7 +1286,7 @@ static bool is_dynamic_key(const struct lock_class_key *key) static struct lock_class * register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force) { - struct lockdep_subclass_key *key; + const struct lockdep_subclass_key *key; struct hlist_head *hash_head; struct lock_class *class; int idx; @@ -4937,8 +4937,8 @@ static inline int check_wait_context(struct task_struct *curr, * Initialize a lock instance's lock-class mapping info: */ void lockdep_init_map_type(struct lockdep_map *lock, const char *name, - struct lock_class_key *key, int subclass, - u8 inner, u8 outer, u8 lock_type) + const struct lock_class_key *key, int subclass, + u8 inner, u8 outer, u8 lock_type) { int i; @@ -5408,7 +5408,7 @@ static int reacquire_held_locks(struct task_struct *curr, unsigned int depth, static int __lock_set_class(struct lockdep_map *lock, const char *name, - struct lock_class_key *key, unsigned int subclass, + const struct lock_class_key *key, unsigned int subclass, unsigned long ip) { struct task_struct *curr = current; @@ -5733,7 +5733,7 @@ static noinstr void check_flags(unsigned long flags) } void lock_set_class(struct lockdep_map *lock, const char *name, - struct lock_class_key *key, unsigned int subclass, + const struct lock_class_key *key, unsigned int subclass, unsigned long ip) { unsigned long flags; -- 2.54.0