From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 30CCEC44501 for ; Tue, 14 Jul 2026 14:03:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=8Nf75dl29ixLQcbRkQR8mUiv2qwJeAxa8PXJ6B4M000=; b=iBq3e4uP5VVFr9 9pD1bYxaNsVMr+H4IfymQt8Dyw44+HciXrbVc0iAqwBNC0zO79Rd6KBQT0xRiN751XHYmWllmRkkz yAkevI9TL8j79cKVs6W1XYq5rKucyYC07sAGkSImEEEVU93j2RFOMxq8rf5Mw9/7P3I2Dz8Kv2uu5 WRRXHf0Jf6e8SMtQ0pBJ0+lwzkrKDY3Pu0ncL7b9tSLezhIe6fU/tk4994OWRmqZAq+k5miu2RZs6 VBhgLc8dNkRGxrvUFvrXMhZUAfC9uTrdDoig6VM/t+Pjp+MCJW7h+IIXPpvr0XeO+fPqTSBjMH7gQ 47XsJECHBAP2/zKu1Cnw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wjdjY-0000000CHIJ-3Hq5; Tue, 14 Jul 2026 14:03:40 +0000 Received: from mail-oo1-xc2e.google.com ([2607:f8b0:4864:20::c2e]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wjdjW-0000000CHHZ-2ZQU for linux-riscv@lists.infradead.org; Tue, 14 Jul 2026 14:03:39 +0000 Received: by mail-oo1-xc2e.google.com with SMTP id 006d021491bc7-6a376ad8fc0so1457420eaf.0 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=lists.infradead.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=XLGxbpZMJLLAmrx8MCp5lss78/iIWYZ3jKEt8GUfSTAJq0VPbn3iDJglCGulR7wwUu NjA5I8us6k3E9+LSj4QS0H0Ner/FkKRYAV5lcsAnsERN+tV6R6Y813YLU4VvaImLllRQ XiV9wD22xzfChdH4i9FTTtuvEDUYUBGEMg1E7+4cj+/LVY3zdd/IXRXGX2m6fUxiWPsc 6rhFwNU8QrJow6ARgHpunSzMAG4AHQot3PjCbnz79q4RxXcCx9966JZWUNgdJ2n4sImK cUC3WjReFcbk+BmXSa9db0pAULd4GiLQWk71m+cFgXe+Z5M0zoNshf6Vshx4Ar5iVUDe HcBQ== 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=TjKngeSlSkc+anv2GRBS2WkM10Q+0OuBxN4DEbe0RqPdLn4TwItxKt//vFCzTCsuI6 tUXRyKSXvuzmwN66u/Ndi8EXkBC8D9k+AbSY0oCzXvQhrgnN3IouP4mppXBN34pZsZQN bd6IO0/N6J5np6tHr4rq1oM4mKBvjJnxLCa2ix6ssFh5m9COnwhRQZDQvahzJQfy78Ku yxscGaBOEEYIvQLIqgp0Y8H3ixSVdxRF2AxohcloPdN5GacQiRzy0FW426PX13LF2dPw y1hQOz4xh4g6B/iHq/Fkn8TtXvpnz7oKa8xfMgkn/IIrCFkLrAF0uolLMVSJaPjq+sUd m15g== X-Forwarded-Encrypted: i=1; AFNElJ9iCZAVv167pdxTi2ZlV8vLtmHBcNE1CGndr4kfLzlcWXrfcfGYekCm3lkzzPfSkvljckAs/Cd5p6mt2Q==@lists.infradead.org X-Gm-Message-State: AOJu0YwxqbsAsd4jBXxfmwTKyTB3P1pu7GHWAY2nAjU1GPhXVy642pCZ bdDdjJTyvRGUdZRVbIUiYSV+Tz16Ds4n9jv0Zjhp/3tgyggZ1ACS+Si7cYdKOONOrXo= X-Gm-Gg: AfdE7cmJdTkAF7MReBTRlhKXz28pD9aRk2r+eTmcQylrif/RZhe5PkmsGzX7OqkFDYu 2zwIcLyzclVZ1XRJMgUCFsOTQJSYRX+KCiYeIRAvNsTxGFanqqvBFYuzirP8KA1lRhwlzb2U0nI vC0regpMWC9IvVxlf67biyOID1E5S5r1BfZcUcXpChH/rdnOja45cwVHi8J0u5W6aldntylaRiw 7dT+tVC6MjIoOyohSR/8wbOGOtQPPpJu5S4MCrnB3sBtLbFH7NBpXdmWuAjUXqF4DRzF/wSwRCY zunIlztPRK4FEwFIJUv3AFdgzAyP92Uk1wf7MwXyCHh6yMj47kh4M64N3IjnchJ55JCl8pf9x1Z H5uIhokhphKkcMz4eFoAhdW2WDFIlnsDuttuE4NmjdYXDQFWpKiGGWrqxc9gxtfRQgi+Z4J0= 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> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20260714130657.46963-2-zhangzhanpeng.jasper@bytedance.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260714_070338_670225_0C56AD04 X-CRM114-Status: GOOD ( 17.60 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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 _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oo1-f50.google.com (mail-oo1-f50.google.com [209.85.161.50]) (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 9AC8F3F1659 for ; Tue, 14 Jul 2026 14:03:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784037821; cv=none; b=PwHfjBXlBl2YO3hw85jbM/F5WDr7DtNUEJcdKbreYPG6puAizDtnM8HgGYT6gxb6bO3rk91twzBC+lm/YD3jOdZS0iSrf2EZVLx/fq/WOAuamJNmiQs7yy1Plu5OJyjCaQ8WqyvZyojQrFp+PO5Mf63OkiGwKwpbL+jEEeATWdg= 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.50 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-f50.google.com with SMTP id 006d021491bc7-6a397db52c1so2234355eaf.2 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=a+0+j2QGNa9C+OsX4+OaCDVC6Yc2ODl1IHj9rzdfRISNAKnouNZtBeHK5XiJyNUVB/ MZDCs4a0sPX5XilxzftT+y/orrHYRVbZ7SjUvvG9TYKJWATlVUUx8HaP0qPc/wq/edMR lYdhtmVRc2auHB+iEXKHrPKf4WQYhF9pqSizzoGm+sRRZbCvXUez1s6UEPnxwN1yvxt4 RZSfaDxk7Uhb5zJy/pAotX7EEuiNj13/lXcT3XfuNFywxDFnSFQQJCLpoTBWMj+MxfnV BaZI+qH6p3PMyQViqnsbrGi0QZJCrYgMV0eFYr4bW2XFCe9HXUQfaBSZ6HDCcIPzGT+0 na3Q== X-Forwarded-Encrypted: i=1; AFNElJ8OVzHDLrdhSf+snetzTMGVqFuKVFGawOeF5TdviEoJOzlUXu1qktuRiCopb/gRArajRJ/0bFXozZk=@vger.kernel.org X-Gm-Message-State: AOJu0YybByYLM9/ldU6ge1QIOZm2rWWA6TJ5v+BrZexwR799MSZZqF+j rvEjwmdrp0ZDy67OQvAoOPq3nXOZgvalGtsN583fNu4g/wPLaCx2vXq2s9IGyA0RGl4= X-Gm-Gg: AfdE7ck4PeVrmTmr1vdL1gOT4ZMH0mnnbb4yOx0qHJ/A+c9S9Kds3qk0jm+SfNTd5hh tBHGLOa8Xdmt0RZuoKMVCFN+q5wjmM48A7C2E0wE4q8gWxvZe/wWceyc0TzvgN9D+Tf6NGSfVE1 GPwQT6QfSJPnLtauWukyWnEH59q8uxTJaygr9GWRfG2qocMDaGhfWUfl0oZSg6/6pljp2Iv4jyz 64tqLQfWNc8UGcRwIeZBc/GGO+57L55K55U1zRGpMiQrhJrTYWmHdp3eRFhfynVfVgNLIonxqZq mdy84WHzCWtUffS0kGpERGMm2dEDCMIAa8rv5e+mJEoTVjUYiMcxBUHmYcQEq35lEX69zHt8Pan Y76Ovr4J0vo1WRUTEv+ltgugU3BCT54/cCFh6DQ/96NwdlQ3LGY5UnrRRInOZAOpsrZl8EMM= 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-doc@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