From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 80395301471 for ; Wed, 29 Apr 2026 19:40:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777491647; cv=none; b=s3ZEinUHGliJWmfMlKhfzaH5yAhBVzv3fMBpZysbG1aTsdx6sHMhUHf7ubkk8avB5KnxdOCGKDCJ8k6CG4wYturnyEo9qT6nm5taGv+EfIBfpmIJEhWLkS9iTBeXnWeoGDJN7XyqTyPHEqVKNA+PZgdMDVuZB8jmnC6772+IrVg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777491647; c=relaxed/simple; bh=prrD9bJIRLONQj+7mlnHtvZz//C4jIcYkMXVJPJDivE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=AsIYwuTnN/aCslKRvcV4teI/QOmoPrxbJDHI+PQMAl344BgQ6QWFxWj3xW83zIId9r3bzhccwglR5L2oj1rGT3psu1ZKQBIYcZ/8hS8F3pSmHV4x2/pvY6LAqDwdRg4RAVT4L3YULjovo/5DKMVj4pE6AYEhVv7nVoPut2PTLuM= 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=BFYiUOeT; arc=none smtp.client-ip=209.85.128.53 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="BFYiUOeT" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-488b0e1b870so2028495e9.2 for ; Wed, 29 Apr 2026 12:40:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777491644; x=1778096444; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=akPGwpQ7qApnfRddq4WG68BkrIa5DY5wWgHGmYogdS8=; b=BFYiUOeTEBblLhzVHY+xuPBB6IvihRd6QDWJCygqb4Iu0hpOExC5S8ZmX3f0wv5whh ii3FQU2ARDPk34xFS4OLqkL2DGK80tBJcZO7upCPFiN2ZRitA2Iqo5hPK+FuH1Wc8LeX wzgyByA8pTkaAo8vaOJeKv4VhFqPiD2C6UUZHOIyY/TRZNwV8KbYrqJmRAJyl/M8J1bO PUnPuW3jH6Vljn8xP8M8WF7L4SUjF4HKZ27wm23YW+IGn1uMUNHr8VV+z82+Ir5h6alk Pkxc3w+v8QA7Fh8EmLznaG9vJ+05nybI0CKACpd2tk3bqY1tGCqjOziRBLleb4S01F5L 981w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777491644; x=1778096444; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=akPGwpQ7qApnfRddq4WG68BkrIa5DY5wWgHGmYogdS8=; b=QR2T+nZnb4ehZacsjsH/i+dbfVJd5PG05R4zDLKwesQ4kB3aFL286gsoska713cg13 7Qxd4fvJyRwnUTeaEoRG1Vwz6XtXuQ0dHbMgiguPQf82kOASGSwJ2Z12UekuE46O5472 3+soeJRejyqcYKyO0AYYGVCSHncKDAdJ907bWGYY8keTgGrCSAoFmwoSfzEZygbYR0x2 AGWtW6HeNCVWtg9Fwd43kSqkX1/IobGrfdwCsmhQFw09PHk2IEdwOp5JlM7QVYM6ROWX bZ9+ZlWV+N7wOiZho8Q6s1eKwHMhHcQR3fTj7asxkjh9Wl1cq8zxCP/RtaP8UuRGBsFu ryNQ== X-Gm-Message-State: AOJu0YymG/X9+c0xZttGZ7looL659vJaHPTmZGvqzy8N6zKsA/T4hf7M r6fxy4I+DTpVfYF2z+7ywpUrDjmB0BB3mjjNiJ2iGC5jKkREpQuEkjeE X-Gm-Gg: AeBDiesNLEkYPna7T9iLyOVcyM9aIU948rfLGCX7sgG3TQh6GtfItkTHHyaYqQc/SgX HsQLV9/IEVLNcsOC/KcAy2IeeBcGWVrJJ2rrPSwNbZ33WJ7CLggmvMRkdsi9Eba8wAZHW9VaBD/ L6abNpOuR67/amCnsv7JqNUqCACJBW0hlovR3ZZqBBNNQNaUQ0vEv7JiQ39+c4V9YRIoiWN15SF l5SpD/QxMZ/Qc9BqaXgSI80ZcsOJcrykUidwYGippln1UqsaVStz4Gq6NrI1/5I+VmgA4p/XhTk FtujGrniS0IZaOZ7FPSgddh9ZTtDeC7NfSpopxrmruwR5UWgw/kiaEz4aWqX1J5T9upBXQHpYnO ihLfdLbjhr7hcr37o6AmsWG7lm3aTJI8PdJzF6JWDKe6IqwkHK9l4wThBU6ex6l5cZLWjg8hyDG zGHiDNY6GIw39Glkg8TbDdtrUIBpp8H+j8mfyMmh1LCTojV0EfojUSkAlkrVnj16JLU5NBbMzOM 9M4DDig9c98AdtTwqKwDef0ACwbrfw/e13SFsLFGIcENgo+dSF/1bj6NnHy2+prJrOeBhg7As31 X-Received: by 2002:a05:600c:608f:b0:488:ae6c:42c0 with SMTP id 5b1f17b1804b1-48a8444a545mr123115e9.7.1777491643569; Wed, 29 Apr 2026 12:40:43 -0700 (PDT) Received: from ?IPV6:2003:ea:8f17:a200:24ea:b321:1d34:8587? (p200300ea8f17a20024eab3211d348587.dip0.t-ipconnect.de. [2003:ea:8f17:a200:24ea:b321:1d34:8587]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48a82301b7bsm13475005e9.11.2026.04.29.12.40.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Apr 2026 12:40:42 -0700 (PDT) Message-ID: Date: Wed, 29 Apr 2026 21:40:41 +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 Subject: Re: [PATCH] lockdep: constify usage of struct lock_class_key where possible To: Waiman Long , Peter Zijlstra , Ingo Molnar , Will Deacon , Boqun Feng Cc: Linux Kernel Mailing List References: <1ca10597-1ac4-441e-bfe4-eeb937eecaae@redhat.com> Content-Language: en-US From: Heiner Kallweit In-Reply-To: <1ca10597-1ac4-441e-bfe4-eeb937eecaae@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 29.04.2026 19:04, Waiman Long wrote: > On 4/28/26 5:05 PM, Heiner Kallweit wrote: >> 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. > > Other than making clear that the lock_class_key isn't being modified, is there other benefit of making this change like helping compiler to generate better code? > Doing an objdump -o kernel/locking/lockdep.o I see no difference in section sizes. Hence at least with gcc it doesn't seem to affect code generation. I didn't check whether it affects callers of e.g. lockdep_init_map_wait(). > Cheers, > Longman > >> >> 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; >