From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.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 53EF63BE65A for ; Mon, 23 Mar 2026 16:46:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774284399; cv=none; b=dvWsAVj39KJTjGkFbiJVIwFxP6me34rb2V4U8+OMRHFGXZ06A+F52iwpW2075wSh/HJmVFCtAfAcx814F8SOWuzv2iIJjVswkAfcWCm0oIXxB+DLIcYHrEOQn2E6Npp45I8647JvTNhxaiT5yVpIhsMOBVA/OC2zriRqB9R/Ceg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774284399; c=relaxed/simple; bh=HKQDceImfXDgLYjADsrp6O76IrFmWlYgSMQDN99+TQ0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Pl6ffUi0vbZz5yJCveqFHG5j8IwJX4s2x7n43ty6Q+mrl4JpxTw/3Nhbhsyn8nHrUf7YmQUEFkCVuN5GfSH2y+KiVL+14iExvGD3K4ZPhD+f/j3XoCXmziCSf20OmO2adWJ0lw+Sg+G4OFw2s+s8lcLGJT5cJGM2wgpB7tjsX8w= 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=vOvYZpUT; arc=none smtp.client-ip=209.85.214.182 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="vOvYZpUT" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2b052ec7176so1765ad.1 for ; Mon, 23 Mar 2026 09:46:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1774284398; x=1774889198; 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=T3cHIDiGHIa38vn3Mqr4bq3z4kncPagusqX2rPGm+Ow=; b=vOvYZpUT4m3OV70vmIPMffE7x7Z5prYOXuFgmOZNOGua0tJX23dK1OBKPFN66n3IS5 PMg8IvjRTjJON4i7FkrMl+81eVtDkRHAoPwfSQdVxeB49ffgMU8jarr16JfGP1LAAmc+ E/IAdN4ix8RPwzwJbg0HpPixVozau+lP+WRn0+u56K3viMpJqCCVwW/cyjhna94CIKBO BbWXjRBZQg68oSHj+DJ/b3GW8QoKI9ucbQDuS8QchEJJ9hTLLnGCqFNW7LUBY5r8ZaZf P/o98bzwlZkdjlx5tOQwMw4GabIXuHfHWxqXmvMm3pAXFXZz8+6aJpdrKfZArYxKPoIx wzZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774284398; x=1774889198; 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=T3cHIDiGHIa38vn3Mqr4bq3z4kncPagusqX2rPGm+Ow=; b=iTdp1CdgilF1v0c6x2KfQme5yyt3zf1c7yazk1awS+HHr7t8hhA3MxSi9tLChL4eJo +0mDdMS1m1JDGWcIGdVZgffwoWhc2debUC/WnZ5X9o9eSDWtJezUsjhF9S5wS2MptLLK JGi8yxSw4vVgjJxV7mXWQVyyf+dAXzk+CdtuM/DvFQ/iIf7diNB4zzPxSWvRctOyEB3a +HNcRmeXxk4uNCmF/px4UEOTbI063ubPxQ6iANNaMtK6GgUWQ6gdSgiyhC15LUdBfxgs RnRh6wFRsuVLEmISVfnsAwaBpsW3P/UuVJzEDLX7y49VehMYLIvCZcwXOA5wVm5p3ADp hLmQ== X-Gm-Message-State: AOJu0Yx/CHcpiUUZyOaW1aNBr2KZeDqAYpou0yXb7MbA/3UujzF3e5kc uqQiXamIqQwhioSP0W5UZlN4aMKQJ4iJThA97wuCfNQfFo51eOKBETdaxkh/FuDg2U2eYWwl0/3 Z5gviNh+x X-Gm-Gg: ATEYQzxEOKdwVogrcy2JeK0lGTTSwvn+/BcFX1lCNyYWC8DAazFVtZStf5sVCNoPCj4 ifkaYjFW84mUPDcvgnzcS4BZl5i9XA6X6TXZbqWz8gGu5jdjPQ152SoF0Y9w+yPXaThlLkRFh9j LHw3CE4UL1md7ueR5tiH25BoJOy5FzMbSeCouA+xA0lEWVqL/h5i/87bJSqJh5wmp6NK2Rqjk+0 dVqrZJ6noacxJ3D7jmnOFKjeuAUrW3MJYNTfTSd6xgG+67Utz2jXIsGYkry8kB7uY02Q7aOIIqW Ct1/Gf0JjqRXvRsOeETbVn5UAk3wYztKRtVabfSfmTbMcivIFLQAtpzZxPeVywLyN0LRKPamGqQ yGs91SXk/WqNcmmaeaCGAaEczlyJYHl3RpoA5265vJ8kcbld4zlTbbXfycGt/Iu4z63bTWov6ad xUC3Xn2/4Da8Rd274FxV8F7bsKIWITPr35rXncDXWAMqlpwbdFhv0reSbLohPoiQ== X-Received: by 2002:a17:902:f541:b0:2ae:45cc:aeb6 with SMTP id d9443c01a7336-2b08b40ab79mr5435895ad.6.1774284397207; Mon, 23 Mar 2026 09:46:37 -0700 (PDT) Received: from google.com (168.136.83.34.bc.googleusercontent.com. [34.83.136.168]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82b040da438sm10054500b3a.43.2026.03.23.09.46.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2026 09:46:36 -0700 (PDT) Date: Mon, 23 Mar 2026 16:46:32 +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