From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 48B463E8350 for ; Tue, 19 May 2026 21:25:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779225918; cv=none; b=NxjvKWAklMW1s8hHXzY/uYiZiCH5z+2JomO2HrvkVgjPGKWEWi9oor0vzvbzUzAP2dCYx7NByzKMNycqdRFZup345+uEIS8c7V/jOqxmCIlLEwdyB5rk000m2Mj5Xx56qpo0bITFZ2MZ8SPD7hzv0nY7sWVz8di6FLO5+Hy2D80= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779225918; c=relaxed/simple; bh=CWG4mJsfZkyJHOQ00O90SjmdF/aiATH9FgVAEHfx6zE=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Fr3M0lBs4CU2qVkfnfjT1eFFjAfttSYSZmW847f0+JSOUC1FoV6EaCX6Cc6XTPiwl/QZT+mM/jUtDuh7hF/U2zfuro9rQHNL6Q1NCR46ur0iqjj9RSsRL6URRCJKT2Y9dNoiXpjBsjdUk+7v4Vy2l5WWGT9g63YZHdWbk4GUk+g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=n+YQLxlZ; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="n+YQLxlZ" Received: from localhost (unknown [20.236.10.129]) by linux.microsoft.com (Postfix) with ESMTPSA id 8DA0820B7166; Tue, 19 May 2026 14:25:08 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 8DA0820B7166 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1779225909; bh=aIW3zMIQjtbCVzrlTe/Q+S8fNDzvaMLXVlMgMR8yFCw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=n+YQLxlZLfWyFnmt1zyBXzzNdqiDgdZY4fW6NQ19CLpaVmulXxGWkfyBQG8VZUvGC aXaL5vSmuHgc5DtXBBXlXRcjCCgsF3IutuJi3V6Iwwar7XC/0yHw+3cMux7U+52Hm7 R5+yMkUw+1kZgRwfvJjiJQHuYkbZrsSokPXUohVw= Date: Tue, 19 May 2026 14:25:13 -0700 From: Jacob Pan To: Baolu Lu Cc: linux-kernel@vger.kernel.org, "iommu@lists.linux.dev" , Jason Gunthorpe , Alex Williamson , Joerg Roedel , Mostafa Saleh , David Matlack , Robin Murphy , Nicolin Chen , "Tian, Kevin" , Yi Liu , Saurabh Sengar , skhawaja@google.com, pasha.tatashin@soleen.com, Will Deacon , jacob.pan@linux.microsoft.com Subject: Re: [PATCH v5 4/9] iommufd: Allow binding to a noiommu device Message-ID: <20260519142513.00002e1e@linux.microsoft.com> In-Reply-To: References: <20260511184116.3687392-1-jacob.pan@linux.microsoft.com> <20260511184116.3687392-5-jacob.pan@linux.microsoft.com> <9f1aa339-6ee5-4ec2-a3f9-b52961afad37@linux.intel.com> <20260513150800.000027e5@linux.microsoft.com> Organization: LSG X-Mailer: Claws Mail 3.21.0 (GTK+ 2.24.33; x86_64-w64-mingw32) 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-Transfer-Encoding: 7bit Hi Baolu, On Thu, 14 May 2026 14:51:01 +0800 Baolu Lu wrote: > On 5/14/26 06:08, Jacob Pan wrote: > >>> +} > >>> + > >>> static void iommufd_group_release(struct kref *kref) > >>> { > >>> struct iommufd_group *igroup = > >>> @@ -30,9 +40,11 @@ static void iommufd_group_release(struct kref > >>> *kref) > >>> WARN_ON(!xa_empty(&igroup->pasid_attach)); > >>> > >>> - xa_cmpxchg(&igroup->ictx->groups, > >>> iommu_group_id(igroup->group), igroup, > >>> - NULL, GFP_KERNEL); > >>> - iommu_group_put(igroup->group); > >>> + if (igroup->group) { > >>> + xa_cmpxchg(&igroup->ictx->groups, > >>> iommu_group_id(igroup->group), > >>> + igroup, NULL, GFP_KERNEL); > >>> + iommu_group_put(igroup->group); > >>> + } > >>> mutex_destroy(&igroup->lock); > >>> kfree(igroup); > >>> } > >>> @@ -204,32 +216,19 @@ void iommufd_device_destroy(struct > >>> iommufd_object *obj) struct iommufd_device *idev = > >>> container_of(obj, struct iommufd_device, obj); > >>> > >>> - iommu_device_release_dma_owner(idev->dev); > >>> + if (!idev->igroup) > >>> + return; > >> I don't quite follow this logic. Is this check being added > >> specifically for the new noiommu mode? Since the noiommu mode > >> introduces the convention that "igroup->group == NULL" implies > >> noiommu, there should be no cases where idev->igroup itself is > >> NULL. > > idev->igroup can be null on error path only, not limited to > > noiommu. It is the partially initialized idev case. > > /* > > * iommufd_device_destroy() handles partially initialized idev, > > * so iommufd_object_abort_and_destroy() is safe to call here. > > */ > > > > How about add this comment? > > /* igroup is NULL when destroy called during bind error cleanup > > */ > > If it's not limited to noiommu, why not making it in a separated > patch? > Because the error handling is restructured by this patch to use iommufd_object_abort_and_destroy() on any failure, which calls iommufd_device_destroy(). Since idev->igroup is now set inside iommufd_bind_iommu()/iommufd_bind_noiommu(), a failure before those succeed (or within them before the assignment) leaves idev->igroup == NULL. Hence the new null check applies to both iommu and noiommu but only needed because of this patch. Before this patch, iommufd_device_destroy was only reachable after bind fully succeeded. i.e. no partial init idev.