From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E9F2A2C15A5 for ; Wed, 29 Apr 2026 17:04:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777482281; cv=none; b=APMeujHPKys1uaE4jO7fdgGrFT5HBPK5uL0a2nSeMnWW348DdqmaNjxCZEfpNFxXknn6eCdeder/2BI2En3+X5ivt7C2OGZORGWEgDcnAGMjpGhmFfYMJulBaOIQ97ETA5PrkLQWagkMnzZKdEgcu56Cxv1lVssh2FKvhJEajc8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777482281; c=relaxed/simple; bh=iWADCEWI2kbddXxC59WSSexvjIeulIYVPPBjw1AH57E=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=FRNeC84yvuNBoIMl6MghihSBcpgJ8Y6wrMz356wNIhkcJnzCeHIHkuJTTS1ALlpOCNiON5wyQZwSFPj8FlBoaBlA5Lwtt2tHtqwSj/dv9VQd0raUOLMu581kPzIIG20jpEybDbpT/wAM7HDy0sMycOsUuBUiVAREr5pOiSIgBps= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=M1FFnLTe; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="M1FFnLTe" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1777482278; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X4B+iWfcMc0S1IjN+beeW8jJKbOctR5SAFKCzF51xgA=; b=M1FFnLTexYeQY+nDKJv1/UGk/QqOcD0Ov01x5D7PCvY+LmklQ48/j4/Bfb77qPixQAyPik vXIYSCbWvzoCSBcPBYP+dkXvZ+5r/FvLzOlRJS6c8QqU6QVKEBaX/eqAhfmLtunoIoA1YE B8W7YhYxJR/bIfeSeM6CE7ZZIGl0Omw= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-687-Ja9rMUcSN9iXcdDGJ-97HQ-1; Wed, 29 Apr 2026 13:04:36 -0400 X-MC-Unique: Ja9rMUcSN9iXcdDGJ-97HQ-1 X-Mimecast-MFC-AGG-ID: Ja9rMUcSN9iXcdDGJ-97HQ_1777482275 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CC3DD19560A6; Wed, 29 Apr 2026 17:04:34 +0000 (UTC) Received: from [10.22.65.94] (unknown [10.22.65.94]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C858B1955F42; Wed, 29 Apr 2026 17:04:32 +0000 (UTC) Message-ID: <1ca10597-1ac4-441e-bfe4-eeb937eecaae@redhat.com> Date: Wed, 29 Apr 2026 13:04:31 -0400 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: Heiner Kallweit , Peter Zijlstra , Ingo Molnar , Will Deacon , Boqun Feng Cc: Linux Kernel Mailing List References: Content-Language: en-US From: Waiman Long In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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? 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;