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 6851C32E128 for ; Fri, 26 Jun 2026 15:22:56 +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=1782487377; cv=none; b=ZR60U4tOd+gG9+pxnzebpLW9zpD+LHH49gwMdB7rCSQ4CymHlNJyWBO7MggZ6+VY0IubjT3aSp/Q3zg5WvAW2nE0p+OvC3vol7K81pQiAQpYQw0gH279KCJ4CgjR+66sqO7iLTNqnJghKHqLD70Ay/wspNltt/Cvrw9SRnZUwhs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782487377; c=relaxed/simple; bh=Ic/G1tkkrI3/zGlgZAj7mF01CzQggTJtolb4eqJizvw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=sxhdcBQVi9/uGfZVm/gBVMc5W0+1vH5an9de/EZZr3VbGIE5zU1ukBNQkzGbeF2UGOTqQP2vf3xYF+Io8CKuUgXLe9FvM6Izhao4VhFT2/dlOhgoZ0qr6HmLpLzeRFcGKwGn+fFwyty13zDNDN3vipRWH1SzVOxhtmznkBFAQl8= 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=DdBkoC+U; 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="DdBkoC+U" 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 65QFISLl3296836; Fri, 26 Jun 2026 15:22:43 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=SA0TIm prX+59HKNwV9tPBfPSw40s9XpCg8thS6KvUn0=; b=DdBkoC+UN+3LaqLZ89PPeX FNZKkMwKHmdOjw4DQX80NWYxAX/DU+jcOBv+Vb2+9TmeEHNnl8deh0HAmfwbXM9U dsQk3SpXGHBKMiz5pZ7yah0ILzVfD2UYqkHS4/VnjJHxjw1hXWtBRN+gmalkCKtC WnRuJcRSxE5afaRROcgZ67bfszSmXZofGgrJNfLxyKCcZA0+CkqTdagcIRRaJtmC nPt8SWGGc+LRTT6bLTF42/YcJo/Qy9eV1j9w5+En1a+UOJk6eaTgkVT3eK8+oMuN eMRGW0RVGjHHU44Kr9qP8cfswGF/BeVIe7uaV3jonZZ1hCrqsSgHb3lViDXcy+XA == 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 4ewh9gya7j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 26 Jun 2026 15:22:42 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 65QFJha9023964; Fri, 26 Jun 2026 15:22:41 GMT Received: from smtprelay02.wdc07v.mail.ibm.com ([172.16.1.69]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4ex6phum66-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 26 Jun 2026 15:22:41 +0000 (GMT) Received: from smtpav01.dal12v.mail.ibm.com (smtpav01.dal12v.mail.ibm.com [10.241.53.100]) by smtprelay02.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 65QFMfdD29622968 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 26 Jun 2026 15:22:41 GMT Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3148A58059; Fri, 26 Jun 2026 15:22:41 +0000 (GMT) Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DCE2258057; Fri, 26 Jun 2026 15:22:37 +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:22:37 +0000 (GMT) Message-ID: Date: Fri, 26 Jun 2026 20:52:36 +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 12/17] nvme: add Clang context annotations for nvme_queue::cq_poll_lock To: 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, elver@google.com, gjoyce@linux.ibm.com References: <20260614131541.2017845-1-nilay@linux.ibm.com> <20260614131541.2017845-13-nilay@linux.ibm.com> <20260626064816.GB11106@lst.de> Content-Language: en-US From: Nilay Shroff In-Reply-To: <20260626064816.GB11106@lst.de> 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-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KmVbJ0S 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-26_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-2606260126 On 6/26/26 12:18 PM, Christoph Hellwig wrote: > On Sun, Jun 14, 2026 at 06:45:27PM +0530, Nilay Shroff wrote: >> nvme_queue::cqes, nvme_queue::cq_head, and nvme_queue::cq_phase are >> protected by nvme_queue::cq_poll_lock. Annotate these fields with >> __guarded_by(&cq_poll_lock) and annotate helpers accessing them with >> __must_hold(&cq_poll_lock) so that Clang's context analysis can >> validate the locking requirements. >> >> IRQ-based queues do not use cq_poll_lock and instead rely on interrupt >> serialization. Annotate nvme_irq() and nvme_irq_check() with >> __context_unsafe() to suppress the corresponding context analysis >> warnings. >> >> nvme_poll() invokes nvme_cqe_pending() as a lockless fast-path check >> before acquiring cq_poll_lock. This check is intentionally kept outside >> the lock because nvme_poll() may be called repeatedly in a tight polling >> loop until completions are found. The result is only advisory, as the >> completion queue is subsequently revalidated under cq_poll_lock by >> nvme_poll_cq(). Suppress the corresponding context analysis warning by >> annotating the lockless invocation of nvme_cqe_pending() with >> context_unsafe(). > > I'm not sure the annotation really buys us anything in this form, > as it makes bold claims about a guard and then ignores it for the > most common case. > That's because nvme_poll() and nvme_irq() both reuse nvme_poll_cq() to process completions, but they rely on different synchronization mechanisms. For the polling path, accesses to the completion queue are synchronized by ->cq_poll_lock, so it is still useful to annotate those accesses with __must_hold(&cq_poll_lock) and let Clang verify that the polling path acquires the lock correctly. The IRQ path, on the other hand, relies on interrupt serialization rather than ->cq_poll_lock, so those accesses are intentionally annotated with context_unsafe() to suppress the corresponding warnings. So, IMO, while the annotations don't apply to the IRQ path, they still provide value by validating the locking requirements for the polling path, where ->cq_poll_lock is the intended synchronization primitive. Thanks, --Nilay