From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (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 72ACC3DFC85 for ; Wed, 18 Mar 2026 18:39:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773859186; cv=none; b=PuVBDpe8pXct6hRkqNdzzUz8cx2nc0XOsP/+syVVgg67iL2Ej5+Ac/zgs363wcwLW3LFMtvRYJ58hVT91ENgcmW8xP3g+wOh5XcVht5eZZBXEzZoHgvWKa75VkISSe1VE6sGsnvnmlbJo/9OgMKZI+T/ivUOT25wgINFcYL9Yb8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773859186; c=relaxed/simple; bh=i7Z7BF+ComiZGkbeFzkQ/Ss2FktQJH5//MVZdkKxR0c=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Km4ifxIxQeXcahzcmgS66T8qwKJapXkg/5Z7Krwz9m9owXwl6CUVz3j4TrBF16BcxCkrcRzhUuBdx0laueFu1Q78qv3D16/aLy5JeZftZ0NysRos8PUmgOlT5lcysNNcnt2kvFQX8aY6yCzZ7Ec2CLZVAhGeKDK0xMdYRXAm4iw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=sybf4z6Z; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="sybf4z6Z" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-2aeab6ff148so11105ad.1 for ; Wed, 18 Mar 2026 11:39:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1773859185; x=1774463985; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=PUvTjxGjBip13gOAImg7DvrqpmVJiE6Xpjign68Hlwo=; b=sybf4z6ZBZb2ehlTb8lswcREQpXmeKlhoy2Tm1T6HgWKGipLYQ7ANdJps4HDIC9nPW lqfxfuakAzUBfBUT05+SWPSH1DBXttbAEPlavblaAcxlfqee16aNfMSk3y8+44ClVyb0 HxPlpll3wqTEXy01cftBggXCkiVLV33gKE1Sb7XzucWb7kgeeyRRK/ffpukM6fPJoY9P iIe6VYLxeUqYqnAIEXLCK26jRk/QCWkwe6JKp3VT6NPLVRu2aowM9dIuCnHXGgRfSjw+ bJBX+C4QnGJFbX91QCw+cqs7Cp888gwpmWMga1aR3OApHtUwjXq15xswHVJky/WkSYg0 Dk0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773859185; x=1774463985; h=in-reply-to:content-disposition: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; bh=PUvTjxGjBip13gOAImg7DvrqpmVJiE6Xpjign68Hlwo=; b=NjnPipnaaSo97zEdp1Pf4b3FHWRRioWkgQhcEioaQLh5mnCeQPQAisCU0H72lgqI6H mmCWgrMz+/bppMhvhOwlajJLl1xN+1bJXCx+0RquM4wb0lbEtw+8vBjvpjyD4fqTDMql IsaFVeJdV/3Z5RTyQhgJB64ly+Xa+iNLlGDaGHCBC1yqFSxF5nVSTC8DxoxeeX/Ha0cA F+qxaOmIhxfhJyuROLC/pXjgFBEuCMDz8F/beJE7jDh+IdUS0dG/djL+AKhOk/pll/AU MvroMZIi/G9hsSXi+JmPGz/YqaQ/QXf7u5sfjams56WBRtQ6Iob+4RebEtAyqZ42nuT7 IuBw== X-Gm-Message-State: AOJu0YzFj0CoHlmpttIx1yWmM2WiAKavyEBLpsap59mUjHB5kZy+3Jqq ZDB6OzPzq2VOXrTY1RUGxz38lU26fWvZZVzyFmo8CLcZ9Z/7WV2NllVsji9yP6JhBA== X-Gm-Gg: ATEYQzxFV/+wQ6BHdn6XijTNzaunlSw1c8ZnQSlYrO1Kq5bP9pdpzyiU0yYp3Eb5WKV ZLO5nucwF/yWmB7nzfqUy7APVIS+RfscqTRzrcxaHBdMSK3q4RnRQ7oLQWn3szddil8YOmu+Vjd y9KcIgwdto3NaT6ok3VSpptfAKP/9JVEkIW1ZVkx2jhvZJIvNPx3PTkWzbKv8vETKZWkB6o7za7 mKlQ6geXlOyPmmfkuV/b01n8bKPny7m01Qx9Rh1mPGzOiHg8AUhuLpgFNV5G8jE5dFSKnrejw37 6gFCQAoQXMWh51BUT6XVxyAhxNhWVf55mRnmNMlxJe6aZ0URZ3PynM5+SDIxR6Eq+UFky4eSwbp 7bQgg2g9xj5iPDyfDiSV9UYXD0kL5Tst1AwFIENb59gY+/wyKVYMMm+Hv9wwMP6XeP5VEUchciO O7pIFLhbNDViVF4qMl2rwRN4YnqOQzmw+3B0OOyxdVhMxjgEaD/7Aq/bXTVykc4Q== X-Received: by 2002:a17:903:3003:b0:2b0:5e19:1862 with SMTP id d9443c01a7336-2b077f16cb7mr250545ad.5.1773859184178; Wed, 18 Mar 2026 11:39:44 -0700 (PDT) Received: from google.com (168.136.83.34.bc.googleusercontent.com. [34.83.136.168]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b06e6314c5sm33123665ad.79.2026.03.18.11.39.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2026 11:39:43 -0700 (PDT) Date: Wed, 18 Mar 2026 18:39:39 +0000 From: Samiullah Khawaja To: Jacob Pan Cc: linux-kernel@vger.kernel.org, "iommu@lists.linux.dev" , Jason Gunthorpe , Alex Williamson , Joerg Roedel , David Matlack , Robin Murphy , Nicolin Chen , "Tian, Kevin" , Yi Liu , pasha.tatashin@soleen.com, Will Deacon , Baolu Lu Subject: Re: [PATCH V2 02/11] iommufd: Move igroup allocation to a function Message-ID: References: <20260312155637.376854-1-jacob.pan@linux.microsoft.com> <20260312155637.376854-3-jacob.pan@linux.microsoft.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; format=flowed Content-Disposition: inline In-Reply-To: <20260312155637.376854-3-jacob.pan@linux.microsoft.com> On Thu, Mar 12, 2026 at 08:56:28AM -0700, Jacob Pan wrote: >From: Jason Gunthorpe > >So it can be reused in the next patch which allows binding to noiommu >device. > >Signed-off-by: Jason Gunthorpe >Signed-off-by: Jacob Pan >--- > drivers/iommu/iommufd/device.c | 48 +++++++++++++++++++++------------- > 1 file changed, 30 insertions(+), 18 deletions(-) > >diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c >index 344d620cdecc..54d73016468f 100644 >--- a/drivers/iommu/iommufd/device.c >+++ b/drivers/iommu/iommufd/device.c >@@ -30,8 +30,9 @@ 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); >+ 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); >@@ -56,6 +57,30 @@ static bool iommufd_group_try_get(struct iommufd_group *igroup, > return kref_get_unless_zero(&igroup->ref); > } > >+static struct iommufd_group *iommufd_alloc_group(struct iommufd_ctx *ictx, >+ struct iommu_group *group) >+{ >+ struct iommufd_group *new_igroup; >+ >+ new_igroup = kzalloc(sizeof(*new_igroup), GFP_KERNEL); >+ if (!new_igroup) >+ return ERR_PTR(-ENOMEM); >+ >+ kref_init(&new_igroup->ref); >+ mutex_init(&new_igroup->lock); >+ xa_init(&new_igroup->pasid_attach); >+ new_igroup->sw_msi_start = PHYS_ADDR_MAX; >+ /* group reference moves into new_igroup */ >+ new_igroup->group = group; >+ >+ /* >+ * The ictx is not additionally refcounted here becase all objects using >+ * an igroup must put it before their destroy completes. >+ */ >+ new_igroup->ictx = ictx; >+ return new_igroup; >+} >+ > /* > * iommufd needs to store some more data for each iommu_group, we keep a > * parallel xarray indexed by iommu_group id to hold this instead of putting it >@@ -87,25 +112,12 @@ static struct iommufd_group *iommufd_get_group(struct iommufd_ctx *ictx, > } > xa_unlock(&ictx->groups); > >- new_igroup = kzalloc_obj(*new_igroup); >- if (!new_igroup) { >+ new_igroup = iommufd_alloc_group(ictx, group); >+ if (IS_ERR(new_igroup)) { > iommu_group_put(group); >- return ERR_PTR(-ENOMEM); >+ return new_igroup; > } > >- kref_init(&new_igroup->ref); >- mutex_init(&new_igroup->lock); >- xa_init(&new_igroup->pasid_attach); >- new_igroup->sw_msi_start = PHYS_ADDR_MAX; >- /* group reference moves into new_igroup */ >- new_igroup->group = group; >- >- /* >- * The ictx is not additionally refcounted here becase all objects using >- * an igroup must put it before their destroy completes. >- */ >- new_igroup->ictx = ictx; >- > /* > * We dropped the lock so igroup is invalid. NULL is a safe and likely > * value to assume for the xa_cmpxchg algorithm. >-- >2.34.1 > Reviewed-by: Samiullah Khawaja Thanks, Sami