From nobody Mon Jun 15 23:17:21 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E68D8288C30; Tue, 14 Apr 2026 16:31:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776184281; cv=none; b=WxEL3Ka4B8dgPSP3uNkZ6i/yrwpLukE84+rTQ/iCfwmFCOhbhD6CMWsKih+wUXVxZrOBiZAhFeOGw23q3zc5QEIf7GJFz8OAYrf2NH/d+TUPhV/JePjCu9xbViqtnuwP+B2EstPaSQur3254M+JxCFJn8U4aSlDhbeoavJTaG9A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776184281; c=relaxed/simple; bh=Xcje/jed8ZwOn7gRcR4WUVa/XkNJGc5sFLasaQZsHEo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rUKh1FEAMxt2mIEPg83e4TYgwqQR8nxNPhe73EBXM7dI98txqGQW5493R1L559/dUresInp4mrwMs3SEpaWttZQTeYcZWlHmBuc+prV93as0VgZA6Kd+NguoS2Bd7LrnH0HlSypTWydDrwAf9KclcX1p+I/d3tGIgAZSCD4Ax7Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Sl23EOQO; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Sl23EOQO" Received: by smtp.kernel.org (Postfix) with ESMTPS id 6EB9AC2BCB5; Tue, 14 Apr 2026 16:31:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776184280; bh=Xcje/jed8ZwOn7gRcR4WUVa/XkNJGc5sFLasaQZsHEo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Sl23EOQOrOUSm+TNf/WDDX6GJXmyjo1lPHEAT2oe79CFibRS8Al27zKKghKKgz5sS jb2Dk9Fj0VLuMBnKB+h3nMed+ZqCj5buBgv1R3fbASvUAhqVvTsy1E5XxsUVpEkMQ7 O+9+a+gF4Dxf/PhWz4Tuwv1aJo0bDQDxrcfKV+oQyugQltQYmfPE2EU+3WptXIWmE6 rK53tfASjizMPyrovDO6BY8C3RFTqFHbcktC5jpXvct6jh1dsnZVpnTUPjo7Bmz5N0 h1dX63c6DcVK+V8mY7Hl/+qKq/bzhUjXJXjDoqZYM1dr98LX9/7RuzswlOChPoyXzU JrROHtlfrym9g== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D462F9D0E7; Tue, 14 Apr 2026 16:31:20 +0000 (UTC) From: Ekansh Gupta via B4 Relay Date: Tue, 14 Apr 2026 22:01:15 +0530 Subject: [PATCH 1/3] drivers: base: Add generic context device bus 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260414-computebus-v1-1-4d904d40926a@oss.qualcomm.com> References: <20260414-computebus-v1-0-4d904d40926a@oss.qualcomm.com> In-Reply-To: <20260414-computebus-v1-0-4d904d40926a@oss.qualcomm.com> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Thierry Reding , Mikko Perttunen , David Airlie , Simona Vetter , Joerg Roedel , Will Deacon , Robin Murphy , Arnd Bergmann , Srinivas Kandagatla , Dmitry Baryshkov , Bharath Kumar , Chenna Kesava Raju Cc: linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org, iommu@lists.linux.dev, linux-arm-msm@vger.kernel.org, Ekansh Gupta X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1776184278; l=3013; i=ekansh.gupta@oss.qualcomm.com; s=20260223; h=from:subject:message-id; bh=GiaW9KX6EnyHl15uXUaLI85Eugyx6gIsQQrGnKwyVVk=; b=g7ZvTKbHA9UTo3rRc56oQRClDN77YoCoOIyf0Ch0pvK4S/d5lszMPmM5fNmU56g6YpXEOAu9x J6BS+tcG340ACkYknZbhTqxrn/ex62ByFElTbD0dzk54v75d4aqeryz X-Developer-Key: i=ekansh.gupta@oss.qualcomm.com; a=ed25519; pk=n0SepARizye+pYjhjg1RA5J+Nq4+IJbyRcBybU+/ERQ= X-Endpoint-Received: by B4 Relay for ekansh.gupta@oss.qualcomm.com/20260223 with auth_id=647 X-Original-From: Ekansh Gupta Reply-To: ekansh.gupta@oss.qualcomm.com From: Ekansh Gupta Introduce a new generic bus type for synthetic context bank devices that require IOMMU context isolation. This bus provides a shared infrastructure for accelerator and GPU drivers that create virtual devices representing IOMMU context banks. Currently, drivers like host1x implement their own bus types for context devices. This generic implementation allows multiple drivers to share the same bus infrastructure, simplifying the IOMMU subsystem integration and reducing code duplication. Signed-off-by: Ekansh Gupta --- drivers/base/Kconfig | 3 +++ drivers/base/Makefile | 1 + drivers/base/context_bus.c | 24 ++++++++++++++++++++++++ include/linux/context_bus.h | 15 +++++++++++++++ 4 files changed, 43 insertions(+) diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig index f7d385cbd3ba..479bc4bb442b 100644 --- a/drivers/base/Kconfig +++ b/drivers/base/Kconfig @@ -4,6 +4,9 @@ menu "Generic Driver Options" config AUXILIARY_BUS bool =20 +config CONTEXT_DEVICE_BUS + bool + config UEVENT_HELPER bool "Support for uevent helper" help diff --git a/drivers/base/Makefile b/drivers/base/Makefile index 8074a10183dc..ab9a0b2dc73b 100644 --- a/drivers/base/Makefile +++ b/drivers/base/Makefile @@ -8,6 +8,7 @@ obj-y :=3D component.o core.o bus.o dd.o syscore.o \ topology.o container.o property.o cacheinfo.o \ swnode.o faux.o obj-$(CONFIG_AUXILIARY_BUS) +=3D auxiliary.o +obj-$(CONFIG_CONTEXT_DEVICE_BUS) +=3D context_bus.o obj-$(CONFIG_DEVTMPFS) +=3D devtmpfs.o obj-y +=3D power/ obj-$(CONFIG_ISA_BUS_API) +=3D isa.o diff --git a/drivers/base/context_bus.c b/drivers/base/context_bus.c new file mode 100644 index 000000000000..6ddb6c27bf69 --- /dev/null +++ b/drivers/base/context_bus.c @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: GPL-2.0-only +// Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. + +#include +#include + +const struct bus_type context_device_bus_type =3D { + .name =3D "context-device", +}; +EXPORT_SYMBOL_GPL(context_device_bus_type); + +static int __init context_device_bus_init(void) +{ + int err; + + err =3D bus_register(&context_device_bus_type); + if (err < 0) { + pr_err("context-device bus registration failed: %d\n", err); + return err; + } + + return 0; +} +postcore_initcall(context_device_bus_init); diff --git a/include/linux/context_bus.h b/include/linux/context_bus.h new file mode 100644 index 000000000000..0cd44cb5b147 --- /dev/null +++ b/include/linux/context_bus.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. + */ + +#ifndef __LINUX_CONTEXT_BUS_H +#define __LINUX_CONTEXT_BUS_H + +#include + +#ifdef CONFIG_CONTEXT_DEVICE_BUS +extern const struct bus_type context_device_bus_type; +#endif + +#endif /* __LINUX_CONTEXT_BUS_H */ --=20 2.34.1 From nobody Mon Jun 15 23:17:21 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1D16288C2C; Tue, 14 Apr 2026 16:31:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776184280; cv=none; b=VYpFZTtGKtWONNCBg3J7MtmUaZ2OxLR40TSBV29BWbTarg2n/P3rlP97o7bU+a1qAsvGc+wBjU6pJMOIRdBv6eJf+AnweWF9zPiPan6koc0GohsNQzmiyDLlahsTyS5ChTRdpXPgDXsGF/RTM0rivJA3udM1qn9gn1vK3x0tfEU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776184280; c=relaxed/simple; bh=ZM2pWoeOuo+RG4s6jFjQePRcse27xHjB7V24etmkYmU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=M2dsarXpAByQIsLEKVtCo3OZm7BIrAwUHN/n85cuScz4ldZS7E9S7s4OgOgIbBq3VaMlK7PL/jjTaWbarzvgfP31Sz/qVy1tVDC+mMNIFA5GqSaDyB0X9FGuOHX+/Xxv59qUYD8kTmxaivTEZH7cGAj/c+GnpIdxqdHkY9G+IE0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=P+CTp9l3; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="P+CTp9l3" Received: by smtp.kernel.org (Postfix) with ESMTPS id 7F3CFC4AF0D; Tue, 14 Apr 2026 16:31:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776184280; bh=ZM2pWoeOuo+RG4s6jFjQePRcse27xHjB7V24etmkYmU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=P+CTp9l39ZoNB3R5OzORxl9YEzVfDLqEjN+vjAHMdcttu4HcslQHZ1+rnfx2HPjZT nkML5lv8NSAhtA+v0A5NCj3ChCx3FiRRSD5wkLCC/YuDXQ8J79yAuc2HkxIr87ByKb q12LWkfagQ5X2uvdAKavph82ON35tpO3ZIkFtenp1l70opxuqmPAn9COXi/5x2F9bd TuI77JKICfIoJ8P6LzAsgoD6RW3DcV3QIoyKVCzuhpMSNeYi3VMp5R7c2cI+ub21Wr pw5pBXpQvA7tPt+c5KWaCR6BcNTeS808l8eWBsburUlMHamUeDB/6NKzPhCuvlBE4G qHzx+UFUfcYQQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70C4AF9D0E9; Tue, 14 Apr 2026 16:31:20 +0000 (UTC) From: Ekansh Gupta via B4 Relay Date: Tue, 14 Apr 2026 22:01:16 +0530 Subject: [PATCH 2/3] gpu: host1x: Migrate to generic context device bus 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260414-computebus-v1-2-4d904d40926a@oss.qualcomm.com> References: <20260414-computebus-v1-0-4d904d40926a@oss.qualcomm.com> In-Reply-To: <20260414-computebus-v1-0-4d904d40926a@oss.qualcomm.com> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Thierry Reding , Mikko Perttunen , David Airlie , Simona Vetter , Joerg Roedel , Will Deacon , Robin Murphy , Arnd Bergmann , Srinivas Kandagatla , Dmitry Baryshkov , Bharath Kumar , Chenna Kesava Raju Cc: linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org, iommu@lists.linux.dev, linux-arm-msm@vger.kernel.org, Ekansh Gupta X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1776184278; l=4839; i=ekansh.gupta@oss.qualcomm.com; s=20260223; h=from:subject:message-id; bh=DQ1olxxNHseU94rnbtsHQ4+BWgV7NjVl53Fj2nX92ag=; b=LNNS8pXQotH116K8rf8Vjr5wHJV7xKAjMrOpuqvSIYb2fF05W7RU2RHTSCAtKIlqBJ/gG+DKE ePcI9NgORtfD6ngTYZwsvy+E+hgJBXDVF5vXGtcMu8cja0X8Cx7XpLm X-Developer-Key: i=ekansh.gupta@oss.qualcomm.com; a=ed25519; pk=n0SepARizye+pYjhjg1RA5J+Nq4+IJbyRcBybU+/ERQ= X-Endpoint-Received: by B4 Relay for ekansh.gupta@oss.qualcomm.com/20260223 with auth_id=647 X-Original-From: Ekansh Gupta Reply-To: ekansh.gupta@oss.qualcomm.com From: Ekansh Gupta Replace the host1x-specific context device bus with the generic context_device_bus_type. This eliminates driver-specific bus infrastructure in favor of shared code in the driver core. The host1x driver creates synthetic context bank devices to represent IOMMU contexts for memory isolation. These devices were previously registered on a host1x-specific bus ("host1x-context"), but this functionality is now provided by the generic "context-device" bus. The IOMMU subsystem is updated to recognize the generic bus instead of the host1x-specific one, allowing proper IOMMU operations on context devices. This change maintains functional equivalence - context devices still work the same way, just on a different bus. The device names remain "host1x-ctx.N" to preserve any userspace dependencies. Signed-off-by: Ekansh Gupta --- drivers/gpu/host1x/Kconfig | 5 +---- drivers/gpu/host1x/Makefile | 1 - drivers/gpu/host1x/context.c | 2 +- drivers/gpu/host1x/context.h | 3 +-- drivers/gpu/host1x/context_bus.c | 26 -------------------------- drivers/iommu/iommu.c | 6 +++--- 6 files changed, 6 insertions(+), 37 deletions(-) diff --git a/drivers/gpu/host1x/Kconfig b/drivers/gpu/host1x/Kconfig index e6c78ae2003a..e3e3896f4d71 100644 --- a/drivers/gpu/host1x/Kconfig +++ b/drivers/gpu/host1x/Kconfig @@ -1,13 +1,10 @@ # SPDX-License-Identifier: GPL-2.0-only =20 -config TEGRA_HOST1X_CONTEXT_BUS - bool - config TEGRA_HOST1X tristate "NVIDIA Tegra host1x driver" depends on ARCH_TEGRA || COMPILE_TEST select DMA_SHARED_BUFFER - select TEGRA_HOST1X_CONTEXT_BUS + select CONTEXT_DEVICE_BUS select IOMMU_IOVA help Driver for the NVIDIA Tegra host1x hardware. diff --git a/drivers/gpu/host1x/Makefile b/drivers/gpu/host1x/Makefile index fead483af0b4..2ccd9a5f1c65 100644 --- a/drivers/gpu/host1x/Makefile +++ b/drivers/gpu/host1x/Makefile @@ -23,4 +23,3 @@ host1x-$(CONFIG_IOMMU_API) +=3D \ context.o =20 obj-$(CONFIG_TEGRA_HOST1X) +=3D host1x.o -obj-$(CONFIG_TEGRA_HOST1X_CONTEXT_BUS) +=3D context_bus.o diff --git a/drivers/gpu/host1x/context.c b/drivers/gpu/host1x/context.c index d50d41c20561..6411c17cc060 100644 --- a/drivers/gpu/host1x/context.c +++ b/drivers/gpu/host1x/context.c @@ -54,7 +54,7 @@ int host1x_memory_context_list_init(struct host1x *host1x) ctx->dev.dma_mask =3D &ctx->dma_mask; ctx->dev.coherent_dma_mask =3D ctx->dma_mask; dev_set_name(&ctx->dev, "host1x-ctx.%d", i); - ctx->dev.bus =3D &host1x_context_device_bus_type; + ctx->dev.bus =3D &context_device_bus_type; ctx->dev.parent =3D host1x->dev; ctx->dev.release =3D host1x_memory_context_release; =20 diff --git a/drivers/gpu/host1x/context.h b/drivers/gpu/host1x/context.h index 3e03bc1d3bac..87ae522fafc7 100644 --- a/drivers/gpu/host1x/context.h +++ b/drivers/gpu/host1x/context.h @@ -8,13 +8,12 @@ #ifndef __HOST1X_CONTEXT_H #define __HOST1X_CONTEXT_H =20 +#include #include #include =20 struct host1x; =20 -extern struct bus_type host1x_context_device_bus_type; - struct host1x_memory_context_list { struct mutex lock; struct host1x_memory_context *devs; diff --git a/drivers/gpu/host1x/context_bus.c b/drivers/gpu/host1x/context_= bus.c deleted file mode 100644 index 7cd0e1a5edd1..000000000000 --- a/drivers/gpu/host1x/context_bus.c +++ /dev/null @@ -1,26 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (c) 2021, NVIDIA Corporation. - */ - -#include -#include - -const struct bus_type host1x_context_device_bus_type =3D { - .name =3D "host1x-context", -}; -EXPORT_SYMBOL_GPL(host1x_context_device_bus_type); - -static int __init host1x_context_device_bus_init(void) -{ - int err; - - err =3D bus_register(&host1x_context_device_bus_type); - if (err < 0) { - pr_err("bus type registration failed: %d\n", err); - return err; - } - - return 0; -} -postcore_initcall(host1x_context_device_bus_init); diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 61c12ba78206..f01a13e2e634 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include #include @@ -173,8 +173,8 @@ static const struct bus_type * const iommu_buses[] =3D { #ifdef CONFIG_FSL_MC_BUS &fsl_mc_bus_type, #endif -#ifdef CONFIG_TEGRA_HOST1X_CONTEXT_BUS - &host1x_context_device_bus_type, +#ifdef CONFIG_CONTEXT_DEVICE_BUS + &context_device_bus_type, #endif #ifdef CONFIG_CDX_BUS &cdx_bus_type, --=20 2.34.1 From nobody Mon Jun 15 23:17:21 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DB90326ED37; Tue, 14 Apr 2026 16:31:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776184281; cv=none; b=NvwFKM3vEcheJN0pLlRkxWHB+b6NwVoN5e7GF9Z214tyFVp61/IOFYdm9S/6Rz0YrMgkju/X3pVEBgcLMlm4oEIxKnpz1drdyqbiugSBNB0UXHm6sX1v4nXI4flBgbv667t02jb19Otsr/k4CewBXck/HwN/SvwX6j5u2YzNms8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776184281; c=relaxed/simple; bh=pUbOjyVZ1noVB3Ygi4q/A3KNcIJK+FNptLPioAtmGQE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eUIpP1F4Wxa7XLx5RH6Qmo4EEzCZDslmNYS4mcf1hxD+ERu2GUvROWq/KbraEcPGk1/ct8VFRhErO3GLud0d25Z7bpn7f6fAMVT+UhKYsymXKAW1rP0KKvTnq55hD7wRvg2p7XImYa67pyLtDszPOqvlM7Cng+u4dD5M9DY0UNM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PphvYmGu; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PphvYmGu" Received: by smtp.kernel.org (Postfix) with ESMTPS id 8EBA7C2BCB8; Tue, 14 Apr 2026 16:31:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776184280; bh=pUbOjyVZ1noVB3Ygi4q/A3KNcIJK+FNptLPioAtmGQE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=PphvYmGuin9F38OzPvCp7msgfJ7HYUPFZRjDRWS8Uppz3+G/fubAY4Dyh2YAH4t37 kpgWQGZ94PzjzCrtxy1K/MvYC9gD4ME4ix/3p/u8Pitk09Yq2m3lNiChd8mUHTCgdX mA2J4SStdx2lF+qBTxCY6sOAUuIKf4HyuQcicT9gGVmjWEbZOVgOEWX7Va0Hp+D/Yk aC8wtrgDO2yxly7VwyfzhrCSYoyKs8dnlSZ+LwpS/AeSuI8nYhEtgHa8WaBVPiS4w+ Wv0VzbYU6t8Xq+HzTO7kqJzmFeXFuJnxANC5kfauZK1/x+21jt1X8WBNlveiT8E5wG xS0XG/h1qgbvA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 838EAF9D0DA; Tue, 14 Apr 2026 16:31:20 +0000 (UTC) From: Ekansh Gupta via B4 Relay Date: Tue, 14 Apr 2026 22:01:17 +0530 Subject: [PATCH 3/3] misc: fastrpc: Use context device bus for compute banks 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260414-computebus-v1-3-4d904d40926a@oss.qualcomm.com> References: <20260414-computebus-v1-0-4d904d40926a@oss.qualcomm.com> In-Reply-To: <20260414-computebus-v1-0-4d904d40926a@oss.qualcomm.com> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Thierry Reding , Mikko Perttunen , David Airlie , Simona Vetter , Joerg Roedel , Will Deacon , Robin Murphy , Arnd Bergmann , Srinivas Kandagatla , Dmitry Baryshkov , Bharath Kumar , Chenna Kesava Raju Cc: linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org, iommu@lists.linux.dev, linux-arm-msm@vger.kernel.org, Ekansh Gupta X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1776184278; l=9736; i=ekansh.gupta@oss.qualcomm.com; s=20260223; h=from:subject:message-id; bh=o6iny1LWE3z7mcZmAk9jzq3tTNYPqB65PUC0PwHJvS8=; b=A0Yhanj3vlPKRDGFbJ31fb+GP3yvJ3vVGI/TW8GczKwhQXoHfKEAqo8oQ+ryO8I/vlHnPX3da vt4BrUk/2XYBeE3DODY4IDLuujnk3xKRlrjczVYtz6ZuLPXhdc6lNOU X-Developer-Key: i=ekansh.gupta@oss.qualcomm.com; a=ed25519; pk=n0SepARizye+pYjhjg1RA5J+Nq4+IJbyRcBybU+/ERQ= X-Endpoint-Received: by B4 Relay for ekansh.gupta@oss.qualcomm.com/20260223 with auth_id=647 X-Original-From: Ekansh Gupta Reply-To: ekansh.gupta@oss.qualcomm.com From: Ekansh Gupta Replace the platform driver approach for compute bank (CB) devices with the generic context_device_bus_type. Compute bank devices are synthetic IOMMU context banks, not real platform devices, so using the context device bus provides a more accurate representation in the device model. Currently, fastrpc used of_platform_populate() to create platform devices for each "qcom,fastrpc-compute-cb" DT node, with a platform driver (fastrpc_cb_driver) to handle probe/remove. This approach had a race condition: device nodes were created before channel resources (like spin_lock) were initialized, and probe was async, so applications could open the device before sessions were available. This patch addresses the race by manually creating and configuring CB devices synchronously during fastrpc_rpmsg_probe(), after all channel resources are initialized. The approach follows the pattern used in host1x_memory_context_list_init(). Signed-off-by: Ekansh Gupta --- drivers/misc/Kconfig | 1 + drivers/misc/fastrpc.c | 180 ++++++++++++++++++++++++++++++++++-----------= ---- 2 files changed, 125 insertions(+), 56 deletions(-) diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index 00683bf06258..b501462a4548 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -304,6 +304,7 @@ config QCOM_FASTRPC depends on RPMSG select DMA_SHARED_BUFFER select QCOM_SCM + select CONTEXT_DEVICE_BUS help Provides a communication mechanism that allows for clients to make remote method invocations across processor boundary to diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 1080f9acf70a..f66fd3eea5fa 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -13,9 +13,9 @@ #include #include #include -#include +#include #include -#include +#include #include #include #include @@ -250,6 +250,18 @@ struct fastrpc_invoke_ctx { struct fastrpc_channel_ctx *cctx; }; =20 +/** + * struct fastrpc_cb_device - Compute bank device wrapper + * @dev: Device structure + * @sess: Back-pointer to the session context + */ +struct fastrpc_cb_device { + struct device dev; + struct fastrpc_session_ctx *sess; +}; + +#define to_fastrpc_cb_device(d) container_of(d, struct fastrpc_cb_device, = dev) + struct fastrpc_session_ctx { struct device *dev; int sid; @@ -2190,92 +2202,156 @@ static const struct file_operations fastrpc_fops = =3D { .compat_ioctl =3D fastrpc_device_ioctl, }; =20 -static int fastrpc_cb_probe(struct platform_device *pdev) +static void fastrpc_cb_dev_release(struct device *dev) +{ + struct fastrpc_cb_device *cb_dev =3D to_fastrpc_cb_device(dev); + + of_node_put(dev->of_node); + kfree(cb_dev); +} + +static int fastrpc_create_cb_device(struct fastrpc_channel_ctx *cctx, + struct device *parent, + struct device_node *cb_node) { - struct fastrpc_channel_ctx *cctx; struct fastrpc_session_ctx *sess; - struct device *dev =3D &pdev->dev; - int i, sessions =3D 0; + struct fastrpc_cb_device *cb_dev; unsigned long flags; - int rc; - u32 dma_bits; - - cctx =3D dev_get_drvdata(dev->parent); - if (!cctx) - return -EINVAL; + int i, sessions =3D 0, rc; + u32 dma_bits, sid =3D 0; =20 - of_property_read_u32(dev->of_node, "qcom,nsessions", &sessions); + /* Read SID early so it can be used in the device name */ + of_property_read_u32(cb_node, "reg", &sid); + of_property_read_u32(cb_node, "qcom,nsessions", &sessions); =20 spin_lock_irqsave(&cctx->lock, flags); if (cctx->sesscount >=3D FASTRPC_MAX_SESSIONS) { - dev_err(&pdev->dev, "too many sessions\n"); + dev_err(parent, "too many sessions\n"); spin_unlock_irqrestore(&cctx->lock, flags); return -ENOSPC; } dma_bits =3D cctx->soc_data->dma_addr_bits_default; + if (cctx->domain_id =3D=3D CDSP_DOMAIN_ID) + dma_bits =3D cctx->soc_data->dma_addr_bits_cdsp; + sess =3D &cctx->session[cctx->sesscount++]; sess->used =3D false; sess->valid =3D true; - sess->dev =3D dev; - dev_set_drvdata(dev, sess); + sess->sid =3D sid; + spin_unlock_irqrestore(&cctx->lock, flags); =20 - if (cctx->domain_id =3D=3D CDSP_DOMAIN_ID) - dma_bits =3D cctx->soc_data->dma_addr_bits_cdsp; + cb_dev =3D kzalloc_obj(*cb_dev); + if (!cb_dev) + return -ENOMEM; =20 - if (of_property_read_u32(dev->of_node, "reg", &sess->sid)) - dev_info(dev, "FastRPC Session ID not specified in DT\n"); + cb_dev->sess =3D sess; =20 - if (sessions > 0) { - struct fastrpc_session_ctx *dup_sess; + device_initialize(&cb_dev->dev); + cb_dev->dev.parent =3D parent; + cb_dev->dev.bus =3D &context_device_bus_type; + cb_dev->dev.release =3D fastrpc_cb_dev_release; + cb_dev->dev.of_node =3D of_node_get(cb_node); + cb_dev->dev.dma_mask =3D &cb_dev->dev.coherent_dma_mask; + cb_dev->dev.coherent_dma_mask =3D DMA_BIT_MASK(32); + dev_set_name(&cb_dev->dev, "%s:compute-cb@%u", dev_name(parent), sid); =20 + rc =3D device_add(&cb_dev->dev); + if (rc) { + dev_err(parent, "failed to add CB device: %d\n", rc); + goto err_put; + } + + rc =3D of_dma_configure(&cb_dev->dev, cb_node, true); + if (rc) { + dev_err(parent, "of_dma_configure failed for CB device: %d\n", rc); + goto err_del; + } + + rc =3D dma_set_mask(&cb_dev->dev, DMA_BIT_MASK(dma_bits)); + if (rc) { + dev_err(parent, "%u-bit DMA enable failed\n", dma_bits); + goto err_del; + } + + sess->dev =3D &cb_dev->dev; + + if (sessions > 0) { + spin_lock_irqsave(&cctx->lock, flags); for (i =3D 1; i < sessions; i++) { + struct fastrpc_session_ctx *dup_sess; + if (cctx->sesscount >=3D FASTRPC_MAX_SESSIONS) break; dup_sess =3D &cctx->session[cctx->sesscount++]; memcpy(dup_sess, sess, sizeof(*dup_sess)); } - } - spin_unlock_irqrestore(&cctx->lock, flags); - rc =3D dma_set_mask(dev, DMA_BIT_MASK(dma_bits)); - if (rc) { - dev_err(dev, "%u-bit DMA enable failed\n", dma_bits); - return rc; + spin_unlock_irqrestore(&cctx->lock, flags); } =20 return 0; + +err_del: + device_del(&cb_dev->dev); +err_put: + of_node_put(cb_dev->dev.of_node); + put_device(&cb_dev->dev); + return rc; } =20 -static void fastrpc_cb_remove(struct platform_device *pdev) +static void fastrpc_depopulate_cb_devices(struct fastrpc_channel_ctx *cctx) { - struct fastrpc_channel_ctx *cctx =3D dev_get_drvdata(pdev->dev.parent); - struct fastrpc_session_ctx *sess =3D dev_get_drvdata(&pdev->dev); unsigned long flags; - int i; + int i, j; =20 spin_lock_irqsave(&cctx->lock, flags); for (i =3D 0; i < FASTRPC_MAX_SESSIONS; i++) { - if (cctx->session[i].sid =3D=3D sess->sid) { + if (cctx->session[i].valid) { cctx->session[i].valid =3D false; cctx->sesscount--; } } spin_unlock_irqrestore(&cctx->lock, flags); + + for (i =3D 0; i < FASTRPC_MAX_SESSIONS; i++) { + struct device *dev =3D cctx->session[i].dev; + + if (!dev) + continue; + + /* Unregister the device once */ + device_unregister(dev); + + /* Clear this dev pointer from all sessions that share it */ + for (j =3D i; j < FASTRPC_MAX_SESSIONS; j++) { + if (cctx->session[j].dev =3D=3D dev) + cctx->session[j].dev =3D NULL; + } + } } =20 -static const struct of_device_id fastrpc_match_table[] =3D { - { .compatible =3D "qcom,fastrpc-compute-cb", }, - {} -}; +static int fastrpc_populate_cb_devices(struct fastrpc_channel_ctx *cctx, + struct device *parent, + struct device_node *parent_node) +{ + struct device_node *child; + int ret =3D 0; =20 -static struct platform_driver fastrpc_cb_driver =3D { - .probe =3D fastrpc_cb_probe, - .remove =3D fastrpc_cb_remove, - .driver =3D { - .name =3D "qcom,fastrpc-cb", - .of_match_table =3D fastrpc_match_table, - .suppress_bind_attrs =3D true, - }, -}; + for_each_child_of_node(parent_node, child) { + if (!of_device_is_compatible(child, "qcom,fastrpc-compute-cb")) + continue; + + ret =3D fastrpc_create_cb_device(cctx, parent, child); + if (ret) { + dev_err(parent, "failed to create CB device for %s: %d\n", + child->name, ret); + of_node_put(child); + fastrpc_depopulate_cb_devices(cctx); + return ret; + } + } + + return 0; +} =20 static int fastrpc_device_register(struct device *dev, struct fastrpc_chan= nel_ctx *cctx, bool is_secured, const char *domain) @@ -2441,7 +2517,7 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *r= pdev) data->domain_id =3D domain_id; data->rpdev =3D rpdev; =20 - err =3D of_platform_populate(rdev->of_node, NULL, NULL, rdev); + err =3D fastrpc_populate_cb_devices(data, rdev, rdev->of_node); if (err) goto err_deregister_fdev; =20 @@ -2496,7 +2572,7 @@ static void fastrpc_rpmsg_remove(struct rpmsg_device = *rpdev) if (cctx->remote_heap) fastrpc_buf_free(cctx->remote_heap); =20 - of_platform_depopulate(&rpdev->dev); + fastrpc_depopulate_cb_devices(cctx); =20 fastrpc_channel_ctx_put(cctx); } @@ -2558,16 +2634,9 @@ static int fastrpc_init(void) { int ret; =20 - ret =3D platform_driver_register(&fastrpc_cb_driver); - if (ret < 0) { - pr_err("fastrpc: failed to register cb driver\n"); - return ret; - } - ret =3D register_rpmsg_driver(&fastrpc_driver); if (ret < 0) { pr_err("fastrpc: failed to register rpmsg driver\n"); - platform_driver_unregister(&fastrpc_cb_driver); return ret; } =20 @@ -2577,7 +2646,6 @@ module_init(fastrpc_init); =20 static void fastrpc_exit(void) { - platform_driver_unregister(&fastrpc_cb_driver); unregister_rpmsg_driver(&fastrpc_driver); } module_exit(fastrpc_exit); --=20 2.34.1