From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oo1-f51.google.com (mail-oo1-f51.google.com [209.85.161.51]) (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 9B94B3F9F38 for ; Tue, 14 Jul 2026 14:03:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784037821; cv=none; b=U0OSayXywD+Z27Y1ij6N2EciUHwQcrpTo1pCaKnmXtWA4b/0pwiUUpynkS+3AFpduh6vtFdB7hNu75KKfB6y+7JslKbjpokphH94E6rpOieIk14FQojGJmBLHOOMdKBzvjRvOcUL8ZelmBqHuPJ0YP7EQUuZphy3EO8TCQ6P7H0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784037821; c=relaxed/simple; bh=x7vkr5xuv03n5zI2/6X6/P9TOOIWoiQal4W8kv8GZCI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=T4+qq4LJJJVZVJWPlar0fpMQVdZJYr1g1RwYOj4ULNCkdqMarFe9eJKhFiCHV2/5TsGcT38Ip7g8Ys3UJBp48qfyd0XCK7oZL6VCE65/fAr/wkgZnEfXwPTMIF7mSZZpf8MXW6qabA6vrfTcuM6kP6B1bSnExrXrdNQEyAUglos= 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=LfD1dCie; arc=none smtp.client-ip=209.85.161.51 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="LfD1dCie" Received: by mail-oo1-f51.google.com with SMTP id 006d021491bc7-6a397a0e5d8so1721940eaf.3 for ; Tue, 14 Jul 2026 07:03:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1784037817; x=1784642617; 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=lIWNtYbjtsZ0PQI9/iIL6fWurRq5Hy1V2922aR85kK4=; b=LfD1dCiegdJE37ELt9oebGIyXbPcxFRMQ6YoHYmm/+LW0FfWf6YTFaO6D5uYvrZUdT Qvj4EWYiBbvvRiD8dZ3CW/P2N0jcKObP5KbUyhx89LCwqznKgDT5K8bdFwWixULJ3PSw H/F07f6MQ4il62sG/Tq/jVNGNjtxH0I+CFEg6MSgyDn03WtKo3p6MJ7cLxs7T3/Bvu09 8lUPSdIu5kDGGino2Ze6UhKQPH313+G35l34TaZcC6sVXd22Xj7XoBNRIp3NcqXt7Reo TMY6zkEQksLU+aMVznW0UmtwmIc0QcTbJ0mdR9/rfBnwOvaDNLRQjszHbuoq09qrpH90 oqWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784037817; x=1784642617; 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=lIWNtYbjtsZ0PQI9/iIL6fWurRq5Hy1V2922aR85kK4=; b=S9pE+Gs/g17SfGr3Bp1k7q6kuf49UZwJnlFY+kV6idky14mrWtvpCw7s2cIBhFO2sy FqGYm8jBspkzUt+gCvmdiPdSByy5FKuR9kuuFA/6y6qsHf/TMIulCtAx8tJ9tiledCnQ Z1nJBWYNrGK0Li0gyaxC+NQSRJFVIWzYb/++TCFHPs61wK1rD7HHerq0wYQXSES6GelZ 9JIRf4xZReJj1SIF17fS+POVChL+0s9R0YC8Lds6n0G513md4KXHZngnMXPIo5ekcoTw VbpKf25vcRMSkr6YJX8BBvwLEPGjkcvnhOKJCN9ksSJNCwK/0dhc3gEEzHWbJeYiRlh0 Tc+A== X-Forwarded-Encrypted: i=1; AFNElJ9bwTADf3j4CLd//mabk8RNDlLwAvqua1XZQPm6y7NvP1I5zX0cHf/14HMEA+bhCryiwK+QJ23ykAycyQA=@vger.kernel.org X-Gm-Message-State: AOJu0Yyi3UarH4dGz5Mva7tALFjCpk3Fq9ZG12pbYluRCy7Y8FZ+c2GZ LUuVkQj+TAv/nCqsRj52Q0MXgWtPr6N8H6nD4gDL5DiQIWQlHYj1lZWR4FN+XNBWgog= X-Gm-Gg: AfdE7cmVjTXxwfSPd7zpdzeHvcqM+uySE6BX/CW1+LPhxXeW4OiuIFhvlcmMjXVQSOZ sC560q38K1i6iSTtuNOmuQ2WZsi6JBTtpwGs8wlnmBcJtpD4vWB9gCt/rY+kPHjhk6Bz1s0Q7cM PqLr3wAbHEy5+tnZJKwd4k/QBqoXWpdtJUwT1d4UZGCUqB6gijILWBAMFwZ+FRkdqTRg/08kMN3 OYjmepcACaKvORoZPlzcUix6cza1e+laRNiSKAVtCa+BslVPM3jB7WCskyVIZKN2ZyNbhtWd/fE sIr4MWnjY14HVw4fxjcsL1cwo9So/K7p9IZcj7+qALiRprSIfrYN2ALC8NG+Gn34TjCHpwVeQPS 3spls18XnxtmYSMeBBbaKB5b8xrCd2cKrqjdQrLjzTzLe/MciAlP0jYsDCWRwEmk8jcIfFKc= X-Received: by 2002:a05:6820:1f12:b0:6a3:1dc5:3557 with SMTP id 006d021491bc7-6a39a5b34bbmr8055289eaf.16.1784037817485; Tue, 14 Jul 2026 07:03:37 -0700 (PDT) Received: from ziepe.ca ([159.2.72.92]) by smtp.gmail.com with ESMTPSA id af79cd13be357-92ee5d6a77csm1521115685a.45.2026.07.14.07.03.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2026 07:03:36 -0700 (PDT) Received: from jgg by wakko with local (Exim 4.97) (envelope-from ) id 1wjdjU-0000000FeUS-19dr; Tue, 14 Jul 2026 11:03:36 -0300 Date: Tue, 14 Jul 2026 11:03:36 -0300 From: Jason Gunthorpe To: Zhanpeng Zhang Cc: joro@8bytes.org, palmer@dabbelt.com, tony.luck@intel.com, reinette.chatre@intel.com, tomasz.jeznach@linux.dev, will@kernel.org, robin.murphy@arm.com, fustini@kernel.org, pjw@kernel.org, aou@eecs.berkeley.edu, alex@ghiti.fr, Dave.Martin@arm.com, james.morse@arm.com, babu.moger@amd.com, corbet@lwn.net, shuah@kernel.org, kevin.tian@intel.com, cuiyunhui@bytedance.com, yuanzhu@bytedance.com, iommu@lists.linux.dev, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, x86@kernel.org Subject: Re: [RFC PATCH 1/7] iommu: Add group lookup by ID Message-ID: <20260714140336.GA3716926@ziepe.ca> References: <20260714130657.46963-1-zhangzhanpeng.jasper@bytedance.com> <20260714130657.46963-2-zhangzhanpeng.jasper@bytedance.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: <20260714130657.46963-2-zhangzhanpeng.jasper@bytedance.com> On Tue, Jul 14, 2026 at 09:06:51PM +0800, Zhanpeng Zhang wrote: > Add iommu_group_get_by_id() so callers can resolve an IOMMU group from > the numeric ID used in /sys/kernel/iommu_groups. > > An ID lookup must keep the group object alive without also keeping an > otherwise empty group active. Embed the devices kobject in struct > iommu_group so its address remains valid until the parent group is > released, and return a reference on the parent kobject to ID lookup > callers. Add iommu_group_put_by_id() to release that reference and > iommu_group_is_active() to detect when the devices kobject has become > inactive. > > Serialize lookup against group teardown with iommu_group_kset_mutex and > only return groups whose devices kobject still has a live reference. > This prevents a concurrent lookup from dereferencing a stale child > kobject while allowing external users to discard bindings to empty > groups. > > Signed-off-by: Zhanpeng Zhang > --- > drivers/iommu/iommu.c | 107 +++++++++++++++++++++++++++++++++++++----- > include/linux/iommu.h | 17 +++++++ > 2 files changed, 113 insertions(+), 11 deletions(-) > > diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c > index e8f13dcebbde..da269d10f6bf 100644 > --- a/drivers/iommu/iommu.c > +++ b/drivers/iommu/iommu.c > @@ -40,6 +40,7 @@ > #include "iommu-priv.h" > > static struct kset *iommu_group_kset; > +static DEFINE_MUTEX(iommu_group_kset_mutex); > static DEFINE_IDA(iommu_group_ida); I think it would be better to change the ida to an xarray than to use a string search on a kset.. Jason