From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 09F0C2EB0F for ; Sun, 22 Mar 2026 09:41:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774172485; cv=none; b=saxPVzlkkLcBxsC3YvN4OIQfiTLyGhEN3dHODU6FXqQM8pnifevRbPUxLmL5QYxJuV5dTBdKW+DHrakScjFqT3xoQblpraqYhK4+LA+Q3Bw2/WGUjGiGxiiMNrrPCvIZ3tCRebExtI6KlYMfjh0aIMs6r15r8wLEnREZ7daTFfo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774172485; c=relaxed/simple; bh=EozkUR9hJasHXQYFsF9AYzvHEHRQAu0xx+pbMFTVBVQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Ie4Ku2t6Sd2dD2yXIWqPuof9k/I2a3dUdOH91i8PxgnV0JxjsFku7lG/OIMQbT75OTEAmvVjBd0bMBb7fmDiWbPbu0JkDDjJkL6bWeRgdQg7Y6s9TJIW1/4noZAbVY4bmAF+XDMF4zkSIm7A+YRc+hTp9ioRKplKa40szzkEpoQ= 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=UXp5rmgS; arc=none smtp.client-ip=209.85.128.42 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="UXp5rmgS" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-486fb990b9eso88125e9.0 for ; Sun, 22 Mar 2026 02:41:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1774172482; x=1774777282; 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=FQXcszglpRn76zyaD4gcsl+CnRRTNeStc1QZosZqFUw=; b=UXp5rmgSt3BVnHhrqwgxn+8fAavO3mEiogNdL3yTxtnRE9xkrF2xM+azl802Elenc5 aJS/W/LqaPOHSC55QEmd/K03qJwaWQsnc8dWjnS171eif3EvCVnJqnMrNzhxH0+hYtUN FGEcqoXI4R/YjBRGBZ71D4qLLMTik8b+d7sHCgkQ4B6RxyhEX622yVnqRPHPzZ+jHWms Va01W4oTY+2MjX5JBQV83rUq8FwDOIQeco8k+JieZ2dptrTr6QnrewxNJSztHSQELZqb 6xhg2ylPoCw4XscxTr6AfzmJE5vknSSslyINzWs+xLn4EfxWl8qcwEHvmUGpe+wUm5rl aXHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774172482; x=1774777282; 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=FQXcszglpRn76zyaD4gcsl+CnRRTNeStc1QZosZqFUw=; b=A1f2b/an6ZcraRzGMm9t4SUOz3F9KkK7SqZ3zGzEPXmAmIwWnOehc5RUrznDbdZm+B /CknLCCInwRdFRPp0TYftx6vm7E/eatF7BUX86bGTYddhvEM6payZVOqsUuEkc9H2fW0 z8tmlgJFRxLW9CfVYzsBMxL01Qqeb4nuytZZLHhICAomJMKzcA7wDkJbLNSxaAO7Bf3K azXQWPFw4ZCBNJ86scjYrQmLq+A0uSCfYL63DR7x0TqGkjZMfrfGzoMrw4Ybu0a1CHTA asipPtvYgsaSUdFLM6SHZzO4NGYpSO0eBp63+UYggt64aEC6487yUiDrNUERqVUiAlVg 1jwg== X-Gm-Message-State: AOJu0YyF9d/0ldvntgdL2I2CV7hck1dwdlf8Hb8k7SCJPOernZVBJY3k 1LuUAbR+PgdDicxU6ZFNlxlwb60otRnsZxDFc77ZDCky7MozaWZYzMGzH2WEF0M8tg== X-Gm-Gg: ATEYQzxcLcEfg2YGDGIPJIVjFdxFjAvGUunsf0VCh7WaNyFbM1ardzvPV4YMPDblgDj fsBoH3KJC9Jsbed+raeUTgZWRPhksCjebmyHMq9RU6WHIJprQ293mVDDHGLqumQ8eJPMNxRldMi mgLu9qtlossrbZ2z2Q7AEqGNI8s0Zj8BhiPMmSbmyMkuzTHLgU26RDseOPBjgNlcJqlUd/mx8Gj EPqby9BsFZl23A/8ioQahV3YFFEtjwToDdTWfpMmY3Yz7EUO+Au7lKGkrumYgFU5vR1bLp8+bdQ pxpQF/mSt/Fo+ibTK3E+3GmUx5ew6bhaDJ+1hPHwvlaX2M1w0aYlq0aKsgI4HiRZGKQbG8JjjmT NakSBEyZtkUzLoksSo6xljTrezqolEKWnf940xf+SsKD/lrveEJ+JEyU7WFneuHnL4z1OJgB9Ri J4Ntxs0JVIO20a6Pwm9UeaJOgaMHMbV5bTGen6MVIs7K3UL0mAJOQWIkiA X-Received: by 2002:a05:600d:640f:20b0:47e:dc0a:8591 with SMTP id 5b1f17b1804b1-487034330d9mr965975e9.2.1774172482001; Sun, 22 Mar 2026 02:41:22 -0700 (PDT) Received: from google.com (54.95.38.34.bc.googleusercontent.com. [34.38.95.54]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-486f8b322d9sm258723025e9.8.2026.03.22.02.41.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Mar 2026 02:41:21 -0700 (PDT) Date: Sun, 22 Mar 2026 09:41:17 +0000 From: Mostafa Saleh 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 , skhawaja@google.com, 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 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); Is that a separate fix or perhaps belongs to the next patch making it possible to have NULL groups. Thanks, Mostafa > 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 >