From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=199.89.1.14 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796316252; b=jI3NLN2nNJvga9P/C/+/SBEiD+HLqvN+QfzzBLy9GNuSgHY4/OvfnJ0Gdx5ZzdMgUrvz EVcGNy9m0QCTK9Qyj8/mtCJ+uhl3FD5OUihI+LwmxilA+etGEYgeM/6K/5s3k6h7jvu8T kFHxq8VjyjkMlEHBXCeby2yccSLDmE0iQ1yQsamlUfsaAwiSRnclOILadreWmmrntoJs5 FS0KVb0qjEEcJgGq0Fl2kgIBHgrmrtJ9DqFuNSgE9Q1Y3+vfddo6BLqoCZTesG5LjZsQY LmzqsLCncgjst2S6Acs4o14iE9GrCQdNzQsxKLmykqSnBoGmu/Ee2+EUdbM1qnbSDTw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796316252; h=DMARC-Filter:Received:DKIM-Signature:X-Virus-Scanned:Received: Received:Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc: References:Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=XVTDYbU9RNHdbnu7XalP7Wqj17AkZajVjRTVm/jKnSQ=; b=K+3glUz7/I6Ub8GsNk+rfUGfnRcJxkBpoPX2NnT//CoE0q9H98QvsVS1lSSPZ5SFT/cA CvfjG9/j0RdoPzRI4V6KosEpR9hpHNEYxpy9ffc8cl9AV1xS5wFZ+tkiyDUjKxCT1i2yr 3wNS/axtPNi+9L0TfyMkxe1yPECZFjuSnmD1BcpGzeiKOqT5IMyaJ+96q7wxxEhSc023D CtSdeytCY4kSJHHE7AwQCbEb65zsSA4gnDPoe7Af7e6po4auOochGxaJTzaJ8d83NdMKF aj2Vt5f/uMWAXPK6Vv1UpYc/cqEipReD25zOSj/g/7hX2aEE6TECS+e77oKNrKuqAAg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass header.d=acm.org header.i=@acm.org header.a=rsa-sha256 header.s=mr01 header.b=3+PiHuGo; arc=none smtp.remote-ip=199.89.1.14 Received: from 011.lax.mailroute.net (011.lax.mailroute.net [199.89.1.14]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5DA5B606A32F for ; Thu, 3 Dec 2026 16:44:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5DA5B606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=acm.org header.i=@acm.org header.a=rsa-sha256 header.s=mr01 header.b=3+PiHuGo Received: from localhost (localhost [127.0.0.1]) by 011.lax.mailroute.net (Postfix) with ESMTP id 4jgL7B4C47z1XMFvk; Thu, 3 Dec 2026 16:44:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:content-type:content-type:in-reply-to :from:from:content-language:references:subject:subject :user-agent:mime-version:date:date:message-id:received:received; s=mr01; t=1796316240; x=1798908241; bh=XVTDYbU9RNHdbnu7XalP7Wqj 17AkZajVjRTVm/jKnSQ=; b=3+PiHuGowsMcc9CdKECroDjd7LInTRqX/rtxGNYq vRfAS7ahd4fMU6HpqATtnh7WPsdlFgkobBjecQqxAg7J0NNJ2FJe4MCRPoY7e82m i7S0H01mwwXHVCS+uMYh5ZWljrFjtjZVEHjsD5hEVGTvVGwJOgMyR9fnMbD+imQm VHJ9StQoRDFaFImBghCiT3XYN1DGPrzo7PMDFdq/W0MCcTUBRRjUPjxYJrpvDH+6 MoobTmjcCK+KpdWQUiHuKlsVHPtQjqQh5Boj+2TqXIizcw7yunFUi5SlsqcS8yrG +gUnHWY9rtJjZgwywaEKpO27Qlaw02ldepHlnPlI+WVqdQ== X-Virus-Scanned: by MailRoute Received: from 011.lax.mailroute.net ([127.0.0.1]) by localhost (011.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id JaAOlA82ImgL; Thu, 3 Dec 2026 16:44:00 +0000 (UTC) Received: from [100.77.36.205] (unknown [104.135.183.85]) (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) (Authenticated sender: bvanassche@acm.org) by 011.lax.mailroute.net (Postfix) with ESMTPSA id 4jgL7412X8z1XMYJR; Thu, 3 Dec 2026 16:44:00 +0000 (UTC) Message-ID: <9d8dd1c0-e9ee-4329-9d57-3d3eb07a4fe4@acm.org> Date: Thu, 3 Dec 2026 08:43:57 -0800 X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 3/3] block: add context annotations for tag_list_lock and quiesce_lock To: Nilay Shroff , axboe@kernel.dk, mt4022@columbia.edu, hch@lst.de, mkhalfella@purestorage.com, kbusch@kernel.org, josef@toxicpanda.com, tom.leiming@gmail.com, tz2294@columbia.edu, gjoyce@linux.ibm.com Cc: linux-block@vger.kernel.org References: <20261203152318.654390-5-nilay@linux.ibm.com> <20261203152318.654390-8-nilay@linux.ibm.com> Content-Language: en-US From: Bart Van Assche In-Reply-To: <20261203152318.654390-8-nilay@linux.ibm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 12/3/26 7:22 AM, Nilay Shroff wrote: > Access to ->tag_list is protected by either tag_list_lock or > quiesce_lock for reads, and by both locks for writes. Annotate > ->tag_list using __guarded_by(&tag_list_lock, &quiesce_lock) > to document this locking requirement. Please mention that the compiler does not verify the "both locks for writes" requirement for this list. Passing &set->tag_list to list_add_tail() is treated as a read access, and list_del() does not reference set->tag_list at all. If I remove the quiesce_lock lock/unlock calls from blk_mq_add_queue_tag_set() and blk_mq_del_queue_tag_set(), Clang does not complain. > Finally, mark blk_mq_alloc_tag_set() with __context_unsafe() > because it initializes lock-guarded variables before they are > published and accessed by other contexts. This avoids false > positive warnings from the context analyzer during initialization. [ ... ] > -int blk_mq_alloc_tag_set(struct blk_mq_tag_set *set); > +int blk_mq_alloc_tag_set(struct blk_mq_tag_set *set) > + __context_unsafe("/* initialize unpublished/lock-guarded variables */"); I see three issues with this change: - This disables context analysis for all of blk_mq_alloc_tag_set(). That is a large function with several error paths. Please use the *_init guards. - Disabling context analysis is not part of the interface of a function. Hence, such an attribute should occur in the function definition instead of in the declaration in the header file. - All other __context_unsafe() users pass a comment as argument instead of a string literal, e.g. __context_unsafe(/* conditional locking */). Please consider leaving the blk_mq_alloc_tag_set() declaration unmodified and making the following change instead: - mutex_init(&set->tag_list_lock); - INIT_LIST_HEAD(&set->tag_list); - spin_lock_init(&set->quiesce_lock); - set->quiesce_depth = 0; + scoped_guard(mutex_init, &set->tag_list_lock) + INIT_LIST_HEAD(&set->tag_list); + scoped_guard(spinlock_init, &set->quiesce_lock) + set->quiesce_depth = 0; With this change block/ builds without context analysis warnings on my setup (Clang, CONFIG_WARN_CONTEXT_ANALYSIS=y). > struct mutex tag_list_lock; > - struct list_head tag_list; > + struct list_head tag_list > + __guarded_by(&tag_list_lock, &quiesce_lock); The kernel-doc comment above this struct still says "@tag_list_lock: Serializes tag_list accesses." Please update that comment such that it matches the above annotation or remove it. > int blk_mq_alloc_sched_res_batch(struct xarray *elv_tbl, > - struct blk_mq_tag_set *set, unsigned int nr_hw_queues); > + struct blk_mq_tag_set *set, unsigned int nr_hw_queues) > + __must_hold(&set->tag_list_lock); > int blk_mq_alloc_sched_ctx_batch(struct xarray *elv_tbl, > - struct blk_mq_tag_set *set); > + struct blk_mq_tag_set *set) > + __must_hold(&set->tag_list_lock); Both functions have a lockdep_assert_held_write() call for set->update_nr_hwq_lock. Has it been considered to add __must_hold(&set->update_nr_hwq_lock) to these declarations too? Thanks, Bart.