From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=148.163.158.5 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796376993; b=HUjAh1HSRSYDmH8A/yG6xg8EJtU3CDPvEWTEQL7WAbDDae7MiVD4xCe8AYkAS/rlZiqq rZHu+fdYOdDpg1bYSI5pruPj5Y5XG6Z5CgOs3ty2tX1XDuwTpv0vdOkrUkWQtpsycvbmF XfqWahAGnJdqkz3VOg6wh46FlNSSn9RmG6YJlzkUYArpGmgca2vFuvou3OB/L1C3Rfrb9 XkhIle2SEa+C9MKvnZ2dBaaJy1oblylWky+CbilCqd6wVTXZZ2RVus7CX0QDLvoElc1OX I5kNYK4N2OXcX5RmQFN87eVniM44rIf3vbFlo2wy71dRYBk6ZFPG8pk8O0mIJ3tDLYQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796376993; h=DMARC-Filter:Received:DKIM-Signature:Received:Received:Received: Received:Received:Received:Received:Message-ID:Date:MIME-Version: User-Agent:Subject:To:Cc:References:Content-Language:From:In-Reply-To: Content-Type:Content-Transfer-Encoding:X-TM-AS-GCONF: X-Proofpoint-Reinject:X-Proofpoint-ORIG-GUID:X-Proofpoint-Spam-Info: X-Proofpoint-Spam-Details-Enc:X-Authority-Analysis:X-Proofpoint-GUID: X-Proofpoint-Virus-Version:X-Proofpoint-Spam-Details; bh=K6i4hZWEFIUWGCDrd5Vy7WBHdmRbDCPNT+7oUctV5YQ=; b=0IrTEC2NgOerssPqSsHAKXQEc41CkqVvCF56QFUj0qK9m3223ZYEZ6kJ5BexkJgg4AZQ +WNh4JaJoBccEucyHRuto1q5FJLXMzy3eqO00hyaqkg9uYWpoaixglahFYYfgs4oHQPB/ /L90e7cUEg3qMKVdOj6v9TQYqM3n7uF8fRPDedcU/QDnNMWlukFY2GG6r4CCODjpUATyX WWxIsWwl12QwwjbO4EirsSY401EnSHp/7ishwnxXo5hPvGdXSQKxrCp4NJvq7SfrxrAtJ Z3zZAjj1cbZaqLuDfQYM47jckTVsOpZkpjJ7O9o0oghJ7O+S1nneZjgeR1MWzAxRFyg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=e3uZKcbk; arc=none smtp.remote-ip=148.163.158.5 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 2494C606A322 for ; Fri, 4 Dec 2026 09:36:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2494C606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=e3uZKcbk Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B45ZKKG1277113; Fri, 4 Dec 2026 09:36:22 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pp1; bh=K6i4hZ WEFIUWGCDrd5Vy7WBHdmRbDCPNT+7oUctV5YQ=; b=e3uZKcbkel1Nqm7zhmZgkw WTqb1jLPch2zV/I0MyxlATGuL0ZowlmMCM1xnakuFLiVhkfChheYcdrZVfSdijOK 0rxw1pSyuK7/CaLuiVCN801+PPmDOoCeVzhOgNJx6O5fKhUpqzjHUAf0LA6H8xuJ A882lTh8JrbaUb3Nr+mbXGa1Iz6fJL245U4Rdgz4EVA3gBGk1E0gx6GIrBApwxsL TiE82F40d0XaTwgAWE8XYecUIe15fhOkk+a33+gQQVxMVgbOGF3OKJoiPNkMmQIF MsijMXNPPqIH6Y9CEc6ZVgLKXTQKCHvDuwXcUeDvU42avHoUYWfxKBCdOeF4tT/w == Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4jbqgg0quw-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 04 Dec 2026 09:36:22 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 6B48dw0I2589331; Fri, 4 Dec 2026 09:36:21 GMT Received: from smtprelay04.wdc07v.mail.ibm.com ([172.16.1.71]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4jbnggh2f6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 04 Dec 2026 09:36:21 +0000 (GMT) Received: from smtpav06.wdc07v.mail.ibm.com (smtpav06.wdc07v.mail.ibm.com [10.39.53.233]) by smtprelay04.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6B49aLOX60490090 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 4 Dec 2026 09:36:21 GMT Received: from smtpav06.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 51AD05804E; Fri, 4 Dec 2026 09:36:21 +0000 (GMT) Received: from smtpav06.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 238375803F; Fri, 4 Dec 2026 09:36:16 +0000 (GMT) Received: from [9.61.147.78] (unknown [9.61.147.78]) by smtpav06.wdc07v.mail.ibm.com (Postfix) with ESMTP; Fri, 4 Dec 2026 09:36:15 +0000 (GMT) Message-ID: Date: Fri, 4 Dec 2026 15:06:13 +0530 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: Bart Van Assche , 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> <9d8dd1c0-e9ee-4329-9d57-3d3eb07a4fe4@acm.org> Content-Language: en-US From: Nilay Shroff In-Reply-To: <9d8dd1c0-e9ee-4329-9d57-3d3eb07a4fe4@acm.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-ORIG-GUID: ca3PS7FidiSnD4pJjnMmGE2e_TOQLa_H X-Proofpoint-Spam-Info: AW1haW4tMjYxMjA0MDAzOCBTYWx0ZWRfX18wQK1zsNWtk 2uCVgwa46BGshwRSirmewqG1Hv0aGozYiSiJRbyGqTrGqNrLCY4LQUbVfnQKWQwVju83QYSLC4C fpDS2ySpj/zsIya/rgXwxCMrekXd1Mw= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjA0MDAzOCBTYWx0ZWRfX8J9dtnZ1/mKG VhU28jyQZ9vaw8fv8Aj8nNcxlpeIcXoGztSGxfes244jV48gPEmoyLfivM4FB0jRfR2fLUB5bnj LkD7gXD0gYqpGAbIaN8pnP/GHiOdIe52qjfldQafGevdAZbpW4ntT8e9OKUm6R25fPT9gsPi81d AcnSDgWhiJNmMOYWqLHeQLaNyuI/EXCFiJYknqBXSQfOjf2M+lk8NiTfmBOtCu1sUIGH+NSKctF abtrRbGV4TSZjHLHZvYwfbVofZSKwho1db0RfAa+uIVqIXSQzfl0/xYDwIICemzUs/0XXxSN8hS BXLM7tZrBK4GjsQGmZnoTLSR0PEC7hYEq6R7Qo6JIBznbEMOIKzXdzlf73AEMXU+PnlUJUpazeb zi47yS9EzkRx8cmV6j1kEzUB80Q5tI7DlKXSHyA/RIj9h7ffigpV9x/tzQWv52B+U4/2IClZjlx PCUt0AMUl6OX4y3/Jfw== X-Authority-Analysis: v=2.4 cv=PaJqFShd c=1 sm=1 tr=0 ts=6b128996 cx=c_pps a=3Bg1Hr4SwmMryq2xdFQyZA==:117 a=3Bg1Hr4SwmMryq2xdFQyZA==:17 a=IkcTkHD0fZMA:10 a=pUM-KoujPXoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=RzCfie-kr_QcCd8fBx8p:22 a=LeZpcoP_ZW_hmhIJJXkA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 X-Proofpoint-GUID: -_6i_6uwUiYwZQ2amvnVhRst6LTixFaO X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-12-04_01,2026-12-03_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 lowpriorityscore=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 adultscore=0 clxscore=1015 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2612040038 On 12/3/26 10:13 PM, Bart Van Assche wrote: > 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. > Yes agreed and that's the reason commit message only mentions that __guarded_by(&tag_list_lock, &quiesce_lock) just documents this locking requirement. But yes I should be more explicit here. I will update the description accordingly in the next revision of the patch. > > 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 */). > Yes noted all points. Regarding last point, I think that was typo and not intention to add comment as literal string. > 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). > I did consider using scoped_guard(_init, ...) helper here, but then realized that doing so would make lockdep class name and key for these locks registered as "_T->lock" instead of &set->tag_list_lock or &set->quiesce_lock respectively. And that then might make the lockdep splat involving these locks difficult to trace, isn't it? Does this unintentionally degrade lockdep class identity or diagnostics? grepping through kernel source, I found only handful of mutex_init/ spinlock_init guard users. Still if you think scoped_guard(_init, ...) is the only alternative here, I'd do this but other preference would be to create inline helper involving initialization of set->tag_list and set->quiesce_depth and marking the helper with __context_unsafe. Alternatively, I could also directly make use of context_unsafe(...) as a statement expression and add both initialization under it, like shown below: context_unsafe( INIT_LIST_HEAD(&set->tag_list); set->quiesce_depth = 0; ); > >      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. > Yes okay will update comment. > >  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? > Yes I considered doing that but then realized the scope of annotating set->update_nr_hwq_lock is much bigger then only annotating these two functions and so thought I'd address it in a different patch covering all relevant annotation needed for set->update_nr_hwq_lock instead of adding it in this series. That said, if you prefer, I could add one more patch in the same series to address locking requirement of set->update_nr_hwq_lock. Thanks, --Nilay