From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (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 C524A3A63E7 for ; Tue, 3 Feb 2026 14:05:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770127551; cv=none; b=D2F0vxh2/q1v4SuJbO5w5tOQVVM5ssr52gAE7IgG5zFKB1GXBDEeHUVAA2EKY4/+c5+y9rrHRgcXoK30k0D5bLPwhBPrtp1Eltn7StweVDMCTw7XL3m2qwxbh+Uyy12erlElva0YhwCu9/9Gx3NRyoumDPMJwf4DU0WoGyH3dks= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770127551; c=relaxed/simple; bh=AdnbG1mSoEYvcYhYnToyL1f8w2uVIotRM/DCTsC88Pc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=FuDzKMlzC7X2g4GCNrRXFpx9jxHe/c/5N7cxfSLi3JtmNMyiPApN6/F8HtA5fA4z4GNThwAly4DJJ4KgnSf4uL0aiK9p/iRWj/ar4mFTBxNkpW/DuB5cSPMiIGWr1Qv8Z1TaheN59Mk+G+ofgHkKjd2StbjZCOZUa02JDWaQb3Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=gJYFjyZZ; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=ULRCis1k; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="gJYFjyZZ"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="ULRCis1k" Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 613A8gXE933184 for ; Tue, 3 Feb 2026 14:05:49 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= bEL43MhGa4sMuZXohHqUo8HZ6KYOBL8kkEKhb9cT3hs=; b=gJYFjyZZAYvlqt3l sDDpBNvz8JZKEzjcS+WwCZ7uyeUjRFC49dXPysrJw/IHCxRiz6FC4ymZYEl01/p1 icS+ta3L+ajJ0sz4x0WornJOdSC5EPM7voHsfYJOPSwMZKqZnE9UyC9d5gt1O/bv O07DTn/VDydsi/jCkmNVnY7AGvHwcAMOIUEA/TfKAGrNbw4OzjbR/LP0aA2yww2U pDFUT6Sc9HHpIYxCZ/zBh0mABti19bQ3L4iKTc/nv1ssJxCciBAG08rA5xPFmjox hTQmkX3FxAYYuUpmCyManYay62ZoEeHmoLx5uGeVXGlc3RMYU1NANVEdUm7qr4vA lEFsMw== Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4c38yu1ufh-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 03 Feb 2026 14:05:48 +0000 (GMT) Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-2a78c094ad6so58799735ad.1 for ; Tue, 03 Feb 2026 06:05:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1770127548; x=1770732348; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=bEL43MhGa4sMuZXohHqUo8HZ6KYOBL8kkEKhb9cT3hs=; b=ULRCis1k0tvLjGyxJ6ZG5W70KTkjTrpwCcUvU+ZSLiN/mPd8pJV2QbXaYdapIx/fRf NjFHUy7PweJqqFGydHGo2xk95sM2HtOwMlpM0Qm7tx4YDgxpC6aMJXJwt34sTg4b/Z62 2H88mZQlki8vQwPAULOEVOc5/B5wfh0dIKK0Vyv6hcj8Dbss6nXkoiYGeH4BCZrCpcuX 5AVOd3fZkLqzC0daHQu4zVnSHcdZfJTpTyQT2dsKmPqlObXoMkOqqr6m3UhLPc6xKc00 xAVWQoCiaKhm/9JA64cdx6qe2SR3o1VGnTwOcWJ/ow/+WHDjKvbDl8XGUUUipiqDD7x2 IvSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770127548; x=1770732348; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=bEL43MhGa4sMuZXohHqUo8HZ6KYOBL8kkEKhb9cT3hs=; b=H0XGABffpYBr7qHWWKrYe4OcZBDsFVbNI9pNMeg5voqtdQVGRJOs5RLlCZI+LM6WU+ k3y7ePbJJdqirkUPDG+7UjUIABOJfzusKrZ7/uNbfeTQPKmX5SXPi/ZtS/eoseVo9NSj cJXlmLNYF3y4M5xgIlduHCFYa+BftRSiT+dswh+RhpZi+GjD/RoHFrvS2txAXR3jysDS 01J9nzGmVDIzmjVlvQKuhb8laXT7e6AY+uiJJUF7V09OoogpyOqDvznKR7p6ZXB4MJZ+ F4CJlPwmFmBNcA6Pdd5eicO8A0D2JtUSg3eNwxkcLsJooElfA0JGr28ckwEWtp/MeI5/ JQLA== X-Forwarded-Encrypted: i=1; AJvYcCX5PxicTrxa6oyBzr5CGozUZb6SzRsq5WwSV5NIFu1NERvb1MLP0CdxilbM+/T5zcWfueEgyuXjXIdcU0s=@vger.kernel.org X-Gm-Message-State: AOJu0Yzb2RMvGchDvrQHKgIAqQN6JTujq7OyrkZGt+WRuOBXWRuroqnd 726fmMmsSd+/93P4BY67qpb38iGzZQIIocpACTZQlSHS+T0kzv1gmovnUvYl7vGE4NIaH7HcDVZ M2nr3WWmQhRQp+3AdtWlj96doABddjPrJ/rvgDSiqpkSuX7X5x3vOzJsZkFeVq+htbw0= X-Gm-Gg: AZuq6aJEGvdSqQkHgsfnDCYB5I2Dufgz4OMmCAv1ML0rNtApc9gzPBQW0TBbRrZsiZx Jp+azPBV7DoACaGUq6PxtOQYTDxayzVrlyByN7KEmp92jCfq9SktsC2ufdfptrzMmV7bCSK2It8 Xi8x2FmhYvAvX9emXCHIAErGKtfpRK86QTODwfTpdyAu1XfqdVNa38epvEPgHXBGBI5pLpAO1Wr EF7WxXdN9eOqZ168gFVA1U00P8rOt1CSitxyZYgK9BNfI2Eca4p1xQIj7jyDXV7MSrPO7LMUNee fJJUPdDBnM9S5llU/JD58IA408AdF7fo8ICam0nvPNUQ125s3foA/qWMWtc4GW4yy84273vFrJ7 kguW5uqb+lZQGJZ6J8vkF10KrF6f8kZtkoPhq7lQfuOBUiY09T1s= X-Received: by 2002:a17:902:ce8e:b0:2a7:3dbe:353d with SMTP id d9443c01a7336-2a8d81a0da6mr159708305ad.53.1770127547702; Tue, 03 Feb 2026 06:05:47 -0800 (PST) X-Received: by 2002:a17:902:ce8e:b0:2a7:3dbe:353d with SMTP id d9443c01a7336-2a8d81a0da6mr159707915ad.53.1770127547086; Tue, 03 Feb 2026 06:05:47 -0800 (PST) Received: from [10.217.216.105] ([202.46.22.19]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a8b47f4717sm171421055ad.18.2026.02.03.06.05.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 03 Feb 2026 06:05:46 -0800 (PST) Message-ID: <79034c4c-ba06-4961-b41b-a43e5f5946af@oss.qualcomm.com> Date: Tue, 3 Feb 2026 19:35:41 +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: [PATCH V1] nvme-pci: Fix NULL pointer dereference in nvme_pci_prp_iter_next To: Christoph Hellwig , Keith Busch Cc: Robin Murphy , axboe@kernel.dk, sagi@grimberg.me, linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, nitin.rawat@oss.qualcomm.com, Leon Romanovsky , Marek Szyprowski , iommu@lists.linux.dev References: <20260202143548.GA19313@lst.de> <20260202173624.GA32713@lst.de> <20260203052756.GA15839@lst.de> Content-Language: en-US From: Pradeep Pragallapati In-Reply-To: <20260203052756.GA15839@lst.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMjAzMDExMyBTYWx0ZWRfX2qfe04GUDGu+ r2c+LtV6DyGstWpf2QMCK7gOAev6JwNkXrOlrjplt2l2/chWS1Ye+ZlnHnNcVmzAfE9JXGGQohU gGn9K5eLAHPg9QIscZDJxzzw2iSswDtHymdenhWGpq7ybBsNXhMQrwDST4vW/9N9qmyQunmQ5Ml SvXvpIaFAkX14/Wgd5Osm7c8smNYqhyRyP3JFmCTvSw/EGpHtkRmfNO//NFxWStqZ1dZH1keVbR PFcfUH9CjsW0RfAujNSHM9PJvbEN20YZ1Y47mNaq3uEooUhE5uDv/gCugLfmzuZsG/cC9clPrG4 4LX+3ME9Q64CZ2rxF1fUKqXqcTI4FEc5jS/0TsJ6k1F7FTtXW/8vsNxamvPlL5Fs9Hpoy7MpJfm kuZ/uS/YWuzk1DDgteDI+DL7ZANhIqqow/FEnImQ+mSlbpSFjFTKLi6JCCRuZ6hwQKJHQnaRlSA /5hslmw7INLV6NDcbUQ== X-Proofpoint-ORIG-GUID: ObUJC4EIuzxkiC3bI2LOgAZSV-HIq57w X-Proofpoint-GUID: ObUJC4EIuzxkiC3bI2LOgAZSV-HIq57w X-Authority-Analysis: v=2.4 cv=UKTQ3Sfy c=1 sm=1 tr=0 ts=698200bc cx=c_pps a=IZJwPbhc+fLeJZngyXXI0A==:117 a=fChuTYTh2wq5r3m49p7fHw==:17 a=IkcTkHD0fZMA:10 a=HzLeVaNsDn8A:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=zVLJcoG1pTuyLsMQ7wEA:9 a=QEXdDO2ut3YA:10 a=uG9DUKGECoFWVXl0Dc02:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-02-03_04,2026-02-02_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 suspectscore=0 impostorscore=0 malwarescore=0 adultscore=0 priorityscore=1501 phishscore=0 clxscore=1015 bulkscore=0 spamscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2602030113 On 2/3/2026 10:57 AM, Christoph Hellwig wrote: > On Mon, Feb 02, 2026 at 11:59:04AM -0700, Keith Busch wrote: >> In the case where this iteration caused dma_need_unmap() to toggle to >> true, this is the iteration that allocates the dma_vecs, and it >> initializes the first entry to this iter. But the next lines proceed to >> the save this iter in the next index, so it's doubly accounted for and >> will get unmapped twice in the completion. > > Yeah. > >> Also, if the allocation fails, we should set iter->status to >> BLK_STS_RESOURCE so the callers know why the iteration can't continue. >> Otherwise, the caller will think the request is badly formed if you >> return false from here without setting iter->status. >> >> Here's my quick take. Boot tested with swiotlb enabled, but haven't >> tried to test the changing dma_need_unmap() scenario. > > Looks much better. Cosmetic nits below. > > Pradeep, can you test this with your setup? Sure, testing has started, and I will share the findings soon. Also, I did not pick up the initialization of dma_vecs during testing. > >> + if (!dma_use_iova(&iod->dma_state) && dma_need_unmap(dma_dev)) >> + return nvme_pci_prp_save_mapping(iter, req); > >> + if (!dma_use_iova(&iod->dma_state) && dma_need_unmap(nvmeq->dev->dev)) >> + if (!nvme_pci_prp_save_mapping(iter, req)) >> + return iter->status; > > I'd move the dma_use_iova / dma_need_unmap checks into > nvme_pci_prp_save_mapping to simplify this a bit more. > >> >> /* >> * PRP1 always points to the start of the DMA transfers. >> @@ -1218,6 +1231,8 @@ static blk_status_t nvme_prep_rq(struct request *req) >> iod->nr_descriptors = 0; >> iod->total_len = 0; >> iod->meta_total_len = 0; >> + iod->nr_dma_vecs = 0; >> + iod->dma_vecs = NULL; > > I don't think we need the dma_vecs initialization here, as everything > is keyed off nr_dma_vecs.