From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B26F734404E for ; Fri, 10 Jul 2026 17:01:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783702917; cv=none; b=dcrqbY9WpJvX7XKDBbyRYFlTi3/KI7Knsdy1Xo6vA9hIIRnzPNflmRt3fYqi0Ompf9dD7mCXND4NBtgtQ6b68XC2ThKEEunENGa39TXyyKr0yDo1FQ0M+y7ximR4CbxyG+Ttg6q2Pv+42e+VC6gu04VKvH+62wiKWYvVArdsHNE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783702917; c=relaxed/simple; bh=oLlwgxJ/hzRXy8GFi25yVUWtdC3YIOvF2/fOjbuZurw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZnbhEJqK2n3nNaR/RRa/6ZGWnD/FvvyAUYlkPWOSgOa2NRTH4a1HFtTCNdsQ+4/2PjGDa+UE4kZ4eHF+IKRag4RjHTYeW6xRilyfONz8gA++4GSJQr2E2/4NYHzkvYG+HV+6+DPWk7zXJWGH40OFn+c5iLNGiSM08yVMRL3oHtM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca; spf=pass smtp.mailfrom=ziepe.ca; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b=afI+YM7o; arc=none smtp.client-ip=209.85.160.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ziepe.ca Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="afI+YM7o" Received: by mail-qt1-f182.google.com with SMTP id d75a77b69052e-51c0cea8883so9143071cf.1 for ; Fri, 10 Jul 2026 10:01:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1783702915; x=1784307715; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=zwCO1//q+s3YukDP/Z5Z7eubEGo+AIobT+lx9B201YY=; b=afI+YM7oBJf5AH9rBoEJScQuryMk0H1QK2dO48pLfIPPlSKlm9oXBbcg2ANsfVVGpc Bjc3lQS/6n+fhrN2DBCVK6tVWwzothgQGe4uLoh6UFHIKU3cHOiVfu3HhtDSge54/Pka y4B56Z1FiNEUqw7CEMETHakw4ScLKWGXNNukBz1jkDnMhITTtgh180SqDoUOrWh7iPaC ZA9kXhRyY49sA3GAhi2rLwj5hzw9Ogpe6r7r4t7YU4kjvbSg4XISYb1fZStpBUQFe6mO mdjyeoQBLyWgHgWkgbEqmRhuvxaxKIVJVtga/U5R2Rvzs7Adp7wRzCzfIVNpDXAG7D4A Hw+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783702915; x=1784307715; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=zwCO1//q+s3YukDP/Z5Z7eubEGo+AIobT+lx9B201YY=; b=gSbaHzQgysP9t4U/3ckvIR1SSOe3KHcaNe7ijYgU9Gbcwx+I2Q3wlOpxAw0gd05T76 1vpwZvucG1tKfKiBP3ERkkfb1ImN6lLwKUNakuces9lvYSmbs9PUF6+VHNlsdb4mHLFK 3PZXzZ1XVUVmQ+8EvM9P/ZpGqqpdChQVg4sRHbe3dOM7O+p9OcfLab23tKbq9bN/RdyI zVZZcwHYEKb99mMRxYRJJ58J949PQVdEfT6Sa9xjiwubgzcHjlTyD/jD3gJJpyIYQJfb hRz5/Ros0V3ZGNQpiJwL3zmbXog7s/i/hU3Rd/0jjiI6WSlCdfMlhsl6EKFZjcFjV5U7 HY+g== X-Forwarded-Encrypted: i=1; AHgh+RovuAqVab4Nx6ZP6eyyV3feU1WnagK3UmlCtKm27c55nDT2Owaj5jjYzrgP4y49OSCSJwTcar3BupDR+zA=@vger.kernel.org X-Gm-Message-State: AOJu0YzQLLt1DRMtb0uAM+fupPEW7vINoHvacRAPyrcQip0P3U/ZKNJ3 qBlECQqPTxPUsE9sZh+GHRUVetAHbb1DpukMm3z3HbmhlixPcAspMIuobcMtcs8ePg0= X-Gm-Gg: AfdE7ckosVgQXXZYhVdvoAf1CE6yEReIz7118INzTaFNUTrdxylj3BW3HCDO8rrd2TA rCA04Q+UvXeW+3Fi6iMjb0kOwF0gd0w7Az8Shp88botMSG8djyBnCaTLwndStV3RtkvB0x03MlQ TIgiTVafgHXcEBtxLdnZpWKFkscn1KWA+cdcuZ3OKqJyD94QfIY5KcB6Ckf5wKnHDwiKLr5LC6j YtBllIiqjxvNnlxOjHxBC2r1Aqt1RK8HBh/ca+aj49SgTFSmU2YHql71XovETjN+Nk1PHvvvp96 SNH09CUjxfCNAVJFYvWKH4LmevBMM0wQQZMufPmzJsMTgZ6rSuBrFiBmfK3CVWCJ2upegbSwTmK nOw3xv6jzEkWt3IHEceyI0CTwORSfL9VzDVOy8+c5z/TP6vaoPaGhn0hoax/W X-Received: by 2002:ac8:5fcc:0:b0:517:5ed7:d28f with SMTP id d75a77b69052e-51caa476931mr43472331cf.25.1783702914518; Fri, 10 Jul 2026 10:01:54 -0700 (PDT) Received: from ziepe.ca ([159.2.72.92]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-51cba49439dsm6020111cf.27.2026.07.10.10.01.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jul 2026 10:01:51 -0700 (PDT) Received: from jgg by wakko with local (Exim 4.97) (envelope-from ) id 1wiEbn-00000007aTw-07zw; Fri, 10 Jul 2026 14:01:51 -0300 Date: Fri, 10 Jul 2026 14:01:51 -0300 From: Jason Gunthorpe To: Shameer Kolothum Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, nicolinc@nvidia.com, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, nathanc@nvidia.com, mochs@nvidia.com Subject: Re: [PATCH v3 2/2] iommu/tegra241-cmdqv: Fix CMD_SYNC use-after-free on teardown Message-ID: <20260710170151.GC1803712@ziepe.ca> References: <20260629094106.251694-1-skolothumtho@nvidia.com> <20260629094106.251694-3-skolothumtho@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260629094106.251694-3-skolothumtho@nvidia.com> On Mon, Jun 29, 2026 at 10:41:06AM +0100, Shameer Kolothum wrote: > arm_smmu_impl_remove() is registered as a devres action in > arm_smmu_impl_probe(), before arm_smmu_init_queues() allocates > smmu->cmdq.q.base. On a devres unwind, whether a failed probe or an > unbind, the queue is freed first and arm_smmu_impl_remove() then runs > tegra241_cmdqv_remove_vintf(), whose VINTF deinit issues a CMD_SYNC on > the freed memory. > > Observed during testing with a QEMU hack that makes the VCMDQ fail to > enable, so the impl reset fails and probe aborts into the devres unwind: > > platform NVDA200C:00: tegra241_cmdqv: VINTF0: VCMDQ0/LVCMDQ0: failed to enable, STATUS=0x00000000 > platform NVDA200C:00: tegra241_cmdqv: VINTF0: VCMDQ0/LVCMDQ0: GERRORN=0x0, GERROR=0x4, CONS=0x0 > platform NVDA200C:00: tegra241_cmdqv: VINTF0: VCMDQ0/LVCMDQ0: uncleared error detected, resetting > arm-smmu-v3 arm-smmu-v3.0.auto: failed to reset impl > arm-smmu-v3 arm-smmu-v3.0.auto: probe with driver arm-smmu-v3 failed with error -110 > Unable to handle kernel paging request at virtual address ffff8000891e0098 > ... > Internal error: Oops: 0000000096000047 [#1] SMP > ... > Call trace: > arm_smmu_cmdq_issue_cmdlist+0x320/0x6fc (P) > tegra241_vcmdq_hw_deinit+0x98/0x168 > tegra241_vintf_hw_deinit+0x5c/0x1b0 > tegra241_cmdqv_remove_vintf+0x34/0xec > tegra241_cmdqv_remove+0x40/0x9c > arm_smmu_impl_remove+0x20/0x30 > devm_action_release+0x14/0x20 > devres_release_all+0xa8/0x110 > device_unbind_cleanup+0x18/0x84 > really_probe+0x1f0/0x29c > > Drop the VINTF deinit from tegra241_cmdqv_remove_vintf() so the unwind no > longer touches the freed queue. Quiesce the VINTFs earlier instead. Add a > device_disable() impl op and run it from arm_smmu_disable_action() while > the CMDQ is still up. That handles a live unbind. A failed reset is already > handled because tegra241_vintf_hw_init() deinits the VINTF on its own error > path. tegra241_cmdqv_remove_vintf() is also used by the iommufd viommu > destroy path, so quiesce there too. > > Fixes: 4dc0d12474f9 ("iommu/tegra241-cmdqv: Add user-space use support") > Cc: stable@vger.kernel.org > Reviewed-by: Nicolin Chen > Signed-off-by: Shameer Kolothum > --- > drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 1 + > drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 2 ++ > drivers/iommu/arm/arm-smmu-v3/tegra241-cmdqv.c | 15 +++++++++++++-- > 3 files changed, 16 insertions(+), 2 deletions(-) Reviewed-by: Jason Gunthorpe Jason