All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@ziepe.ca>
To: Zhanpeng Zhang <zhangzhanpeng.jasper@bytedance.com>
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
Date: Tue, 14 Jul 2026 11:03:36 -0300	[thread overview]
Message-ID: <20260714140336.GA3716926@ziepe.ca> (raw)
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 <zhangzhanpeng.jasper@bytedance.com>
> ---
>  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

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

WARNING: multiple messages have this Message-ID (diff)
From: Jason Gunthorpe <jgg@ziepe.ca>
To: Zhanpeng Zhang <zhangzhanpeng.jasper@bytedance.com>
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
Date: Tue, 14 Jul 2026 11:03:36 -0300	[thread overview]
Message-ID: <20260714140336.GA3716926@ziepe.ca> (raw)
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 <zhangzhanpeng.jasper@bytedance.com>
> ---
>  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

  reply	other threads:[~2026-07-14 14:03 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-14 13:06 [RFC PATCH 0/7] riscv: iommu: Add QoS ID support for resctrl device assignment Zhanpeng Zhang
2026-07-14 13:06 ` Zhanpeng Zhang
2026-07-14 13:06 ` [RFC PATCH 1/7] iommu: Add group lookup by ID Zhanpeng Zhang
2026-07-14 13:06   ` Zhanpeng Zhang
2026-07-14 14:03   ` Jason Gunthorpe [this message]
2026-07-14 14:03     ` Jason Gunthorpe
2026-07-15  2:54     ` Zhanpeng Zhang
2026-07-15  2:54       ` Zhanpeng Zhang
2026-07-15  2:55     ` Zhanpeng Zhang
2026-07-15  2:55       ` Zhanpeng Zhang
2026-07-14 13:06 ` [RFC PATCH 2/7] iommu: Add checked group device update helper Zhanpeng Zhang
2026-07-14 13:06   ` Zhanpeng Zhang
2026-07-14 13:06 ` [RFC PATCH 3/7] resctrl: Add a devices file for external requester assignment Zhanpeng Zhang
2026-07-14 13:06   ` Zhanpeng Zhang
2026-08-12  2:19   ` Drew Fustini
2026-08-12  2:19     ` Drew Fustini
2026-08-12  2:58     ` Zhanpeng Zhang
2026-08-12  2:58       ` Zhanpeng Zhang
2026-07-14 13:06 ` [RFC PATCH 4/7] iommu/riscv: Program QoS IDs for assigned groups Zhanpeng Zhang
2026-07-14 13:06   ` Zhanpeng Zhang
2026-08-08 17:07   ` Drew Fustini
2026-08-08 17:07     ` Drew Fustini
2026-08-12  2:33     ` Zhanpeng Zhang
2026-08-12  2:33       ` Zhanpeng Zhang
2026-07-14 13:06 ` [RFC PATCH 5/7] iommu/riscv: Expose global QoS IDs in sysfs Zhanpeng Zhang
2026-07-14 13:06   ` Zhanpeng Zhang
2026-08-08 17:09   ` Drew Fustini
2026-08-08 17:09     ` Drew Fustini
2026-08-12  2:38     ` Zhanpeng Zhang
2026-08-12  2:38       ` Zhanpeng Zhang
2026-08-11 21:21   ` Drew Fustini
2026-08-11 21:21     ` Drew Fustini
2026-08-12  2:42     ` Zhanpeng Zhang
2026-08-12  2:42       ` Zhanpeng Zhang
2026-07-14 13:06 ` [RFC PATCH 6/7] riscv_cbqri: Assign IOMMU groups to resource groups Zhanpeng Zhang
2026-07-14 13:06   ` Zhanpeng Zhang
2026-07-14 13:06 ` [RFC PATCH 7/7] selftests/iommu: Add RISC-V IOMMU QoS smoke test Zhanpeng Zhang
2026-07-14 13:06   ` Zhanpeng Zhang
2026-08-06  5:23 ` [RFC PATCH 0/7] riscv: iommu: Add QoS ID support for resctrl device assignment Drew Fustini
2026-08-06  5:23   ` Drew Fustini
2026-08-06  8:42   ` Ben Horgan
2026-08-06  8:42     ` Ben Horgan
2026-08-09  4:13     ` [External] " Zhanpeng Zhang
2026-08-09  4:13       ` Zhanpeng Zhang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260714140336.GA3716926@ziepe.ca \
    --to=jgg@ziepe.ca \
    --cc=Dave.Martin@arm.com \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=babu.moger@amd.com \
    --cc=corbet@lwn.net \
    --cc=cuiyunhui@bytedance.com \
    --cc=fustini@kernel.org \
    --cc=iommu@lists.linux.dev \
    --cc=james.morse@arm.com \
    --cc=joro@8bytes.org \
    --cc=kevin.tian@intel.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@dabbelt.com \
    --cc=pjw@kernel.org \
    --cc=reinette.chatre@intel.com \
    --cc=robin.murphy@arm.com \
    --cc=shuah@kernel.org \
    --cc=tomasz.jeznach@linux.dev \
    --cc=tony.luck@intel.com \
    --cc=will@kernel.org \
    --cc=x86@kernel.org \
    --cc=yuanzhu@bytedance.com \
    --cc=zhangzhanpeng.jasper@bytedance.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.