From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 6F5DE37DAC2 for ; Fri, 26 Jun 2026 15:12:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782486760; cv=none; b=bENYYoCjHmqmXTnrA/SISN+nUd37jk3fsgvh4ZQkvA3IneOL+XWzfeDY+T+OB0LuTJ+pxMOzxg2gYbZyK+lziAUpHGWx//WYg4tp4gjREVNH23LxxVLsEaZCsCQYdV8I0vCbY8iyD6LRMZdBeflvDUk6qSBJ9uPt0aocVUrhV6M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782486760; c=relaxed/simple; bh=VPeOcsenRuQHq0LPpr0TwQxnwnxhBGFljTl/nYnmn+s=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=oNoCKDLEQkJb0di7TZiLz9EnAs/CGuVmjNynj1G/PpgtCWjqQZj2osyeyo1d5338+iMcksRKLOn+FK1cg7bJdAGBa8HtgIUBuHs7/+a6l8DPY7INFBN6h0u/oI8Bx6+T6nmLYHCRIQutPK5kklC09C6bvRSmd7fjgpqiHW3tmXQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=RIsIbAjG; arc=none smtp.client-ip=148.163.158.5 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.b="RIsIbAjG" Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 65QAIRvs2660004; Fri, 26 Jun 2026 15:12:11 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=7z1jJP HNW8xbBOvUMfR0PS2C6t6H6tXTE75ez/mYGl4=; b=RIsIbAjGMUDXJ+bIgO+gmb mSWzan2sar5nYOXUZdtzEOhXimGCZyOq+vayYWktTmatZ9mQ7BmDSBPsxKygrivb 2qJcV3WOiEn8dm6PJB5Zhxn2KqadkdJwSjSeWAG5WuNZfPB+5big/VAWEAReYhq5 oOuR3iNpTQHaxiL7y3UG65fqdDDH5ReN4bP1/HuMBTwI+6okol4MWeIuqAbGvtZz p3yeA1+75bQAAxzgY0wSxmNurqCQSCEESY8ROgxZ/uZRdM7+U9jt/Ws/udRo3Zwe icRnI6aBH8nNcCh/18LWZCFb2GeeCj0c6BLlXCQpZ7QRGCOk9RrvCAJHED6PiL8g == Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4ewh9gy8k0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 26 Jun 2026 15:12:11 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 65QF6xuF000895; Fri, 26 Jun 2026 15:12:10 GMT Received: from smtprelay05.wdc07v.mail.ibm.com ([172.16.1.72]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 4ex7dgkdt7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 26 Jun 2026 15:12:10 +0000 (GMT) Received: from smtpav01.dal12v.mail.ibm.com (smtpav01.dal12v.mail.ibm.com [10.241.53.100]) by smtprelay05.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 65QFC9KE31982208 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 26 Jun 2026 15:12:09 GMT Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5D6895805D; Fri, 26 Jun 2026 15:12:09 +0000 (GMT) Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0597A58057; Fri, 26 Jun 2026 15:12:06 +0000 (GMT) Received: from [9.43.54.234] (unknown [9.43.54.234]) by smtpav01.dal12v.mail.ibm.com (Postfix) with ESMTP; Fri, 26 Jun 2026 15:12:05 +0000 (GMT) Message-ID: <09fb5b3d-e5d0-4c7b-a333-9ca51286929b@linux.ibm.com> Date: Fri, 26 Jun 2026 20:42:04 +0530 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: [PATCHv2 11/17] nvme: add Clang context annotations for nvme_queue::sq_lock To: Marco Elver , Christoph Hellwig Cc: linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, kbusch@kernel.org, sagi@grimberg.me, axboe@fb.com, bvanassche@acm.org, gjoyce@linux.ibm.com References: <20260614131541.2017845-1-nilay@linux.ibm.com> <20260614131541.2017845-12-nilay@linux.ibm.com> <20260626064721.GA11106@lst.de> Content-Language: en-US From: Nilay Shroff In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-GUID: 3me4vj911bivnZ9aF2C7RX9TCvqu0mLc X-Proofpoint-Spam-Info: AW1haW4tMjYwNjI2MDEyMiBTYWx0ZWRfX2KhmghEdOHWW EwiYjEih4M8ysjhLHmAxxuMkK3aI2KB1XYictkyTQGaSXuiBwD9XESFxrL3DBmRYmLrshxunX4e tZKYiZYVplqGOSSk073qVX+Irv/N7Z8= X-Authority-Analysis: v=2.4 cv=c62bhx9l c=1 sm=1 tr=0 ts=6a3e96cb cx=c_pps a=AfN7/Ok6k8XGzOShvHwTGQ==:117 a=AfN7/Ok6k8XGzOShvHwTGQ==:17 a=IkcTkHD0fZMA:10 a=FelO9ux0wxsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=V8glGbnc2Ofi9Qvn3v5h:22 a=VwQbUJbxAAAA:8 a=LADbP_c0cKmsurRaz28A:9 a=QEXdDO2ut3YA:10 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNjI2MDEyMiBTYWx0ZWRfXwprDvjCleuhv 6mDhRAdFF6carK7aN0YgpQtFdxthfiRHflEU74R/YZpAPSoP7A3KYsQnRTWvdHSSTu1CjK2/TiX fdE0v3H3qw/B6W6BGxQ4ipoEsGt8VvDAyPQnuG4yvlzdoBw32Hxh/0wyoQESXUm6yh1puL7QNds mc8JjNdoKD0c5zKFVxpAXFNFpjYsO51E4MVbdx6E7abu3S0OiXw08KtuDghY0PNHaojXRJ3ubMG c4///FvvbZLmsl/evZTlmGuk2dKpGoWevW65l2a92BN7e3UQBjGbXfP1XngY9B+fn6xPwndOid4 NI9EAqS2DfFfnCVITV2g2qWa7lAJ4EvGsqvQigP4S2vI1lOYC9QDZ59mmlsIzurqpWOIE/O2B8l L9SPjxQhDpJDR+JcC6QgTDgiWWphwjvyAL/JwKwPWH4UEpTwJ454ii4vrO/eZ9z3wYR3Vu/OcFK b0KdENyIm+zdgsK2zIw== X-Proofpoint-ORIG-GUID: q90oZa9-FzUP2HjD5i-ZPAWfYdAj7OJ8 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.125,FMLib:17.12.100.49 definitions=2026-06-26_03,2026-06-24_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 impostorscore=0 adultscore=0 clxscore=1015 suspectscore=0 priorityscore=1501 phishscore=0 spamscore=0 bulkscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2606260122 On 6/26/26 3:20 PM, Marco Elver wrote: > On Fri, 26 Jun 2026 at 08:47, Christoph Hellwig wrote: >> >> On Sun, Jun 14, 2026 at 06:45:26PM +0530, Nilay Shroff wrote: >>> Accesses to sq_tail used solely for tracing are annotated with >>> context_unsafe(), as they only require a lockless snapshot of the > > This sounds like an intentional "benign" data race... > Yes, agreed. For the tracing case this is an intentional data race, so it can simply be written as: trace_nvme_sq(req, cqe->sq_head, data_race(nvmeq->sq_tail)); >>> value. Likewise, nvme_init_queue() and nvme_free_queue() operate on >>> queues that have not yet been published or are no longer reachable, >>> and therefore do not require sq_lock protection. Similarly, >>> nvme_alloc_sq_cmds() allocates memory for nvme_queue::sq_cmds for >>> the queue which is not yet published or in use and hence it's safe >>> to annotate all these helpers using context_unsafe. >> >> Accessing scalar fields without lock is pretty common. Don't we >> have an annotation that only requires the guarding lock for >> writes? > > If the writes can happen concurrently with readers these are data > races. I'd probably annotate the particular reads with data_race(...): > this will both tell Context Analysis this is ok without a lock, and > also if KCSAN is enabled, not to report these data races when actually > observed at runtime > (https://docs.kernel.org/dev-tools/lkmm/docs/access-marking.html). I don't think data_race() is appropriate for the initialization paths. There we're only initializing scalar fields before the object is published, so there is no concurrent reader or writer and hence no actual data race. The remaining issue is simply convincing the context analyzer that these accesses are safe. As far as I can tell, the only way to suppress those warnings today is to use context_unsafe(), either around the helper itself or around the individual scalar field accesses. Thanks, --Nilay