linux-integrity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 00/17] tee: Use bus callbacks instead of driver callbacks
@ 2025-12-11 17:14 Uwe Kleine-König
  2025-12-11 17:15 ` [PATCH v1 14/17] KEYS: trusted: Migrate to use tee specific driver registration function Uwe Kleine-König
                   ` (4 more replies)
  0 siblings, 5 replies; 18+ messages in thread
From: Uwe Kleine-König @ 2025-12-11 17:14 UTC (permalink / raw)
  To: Jens Wiklander, Sumit Garg, Olivia Mackall, Herbert Xu,
	Clément Léger, Alexandre Belloni, Ard Biesheuvel,
	Maxime Coquelin, Alexandre Torgue, Sumit Garg, Ilias Apalodimas,
	Jan Kiszka, Sudeep Holla, Christophe JAILLET, Michael Chan,
	Pavan Chebbi, Rafał Miłecki, James Bottomley,
	Jarkko Sakkinen, Mimi Zohar, David Howells, Paul Moore,
	James Morris, Serge E. Hallyn, Peter Huewe
  Cc: op-tee, linux-kernel, linux-crypto, linux-rtc, linux-efi,
	linux-stm32, linux-arm-kernel, Cristian Marussi, arm-scmi, netdev,
	linux-mips, linux-integrity, keyrings, linux-security-module,
	Jason Gunthorpe

Hello,

the objective of this series is to make tee driver stop using callbacks
in struct device_driver. These were superseded by bus methods in 2006
(commit 594c8281f905 ("[PATCH] Add bus_type probe, remove, shutdown
methods.")) but nobody cared to convert all subsystems accordingly.

Here the tee drivers are converted. The first commit is somewhat
unrelated, but simplifies the conversion (and the drivers). It
introduces driver registration helpers that care about setting the bus
and owner. (The latter is missing in all drivers, so by using these
helpers the drivers become more correct.)

The patches #4 - #17 depend on the first two, so if they should be
applied to their respective subsystem trees these must contain the first
two patches first.

Note that after patch #2 is applied, unconverted drivers provoke a
warning in driver_register(), so it would be good for the user
experience if the whole series goes in during a single merge window. So
I guess an immutable branch containing the frist three patches that can
be merged into the other subsystem trees would be sensible.

After all patches are applied, tee_bus_type can be made private to
drivers/tee as it's not used in other places any more.

Best regards
Uwe

Uwe Kleine-König (17):
  tee: Add some helpers to reduce boilerplate for tee client drivers
  tee: Add probe, remove and shutdown bus callbacks to tee_client_driver
  tee: Adapt documentation to cover recent additions
  hwrng: optee - Make use of module_tee_client_driver()
  hwrng: optee - Make use of tee bus methods
  rtc: optee: Migrate to use tee specific driver registration function
  rtc: optee: Make use of tee bus methods
  efi: stmm: Make use of module_tee_client_driver()
  efi: stmm: Make use of tee bus methods
  firmware: arm_scmi: optee: Make use of module_tee_client_driver()
  firmware: arm_scmi: Make use of tee bus methods
  firmware: tee_bnxt: Make use of module_tee_client_driver()
  firmware: tee_bnxt: Make use of tee bus methods
  KEYS: trusted: Migrate to use tee specific driver registration
    function
  KEYS: trusted: Make use of tee bus methods
  tpm/tpm_ftpm_tee: Make use of tee specific driver registration
  tpm/tpm_ftpm_tee: Make use of tee bus methods

 Documentation/driver-api/tee.rst             | 18 +----
 drivers/char/hw_random/optee-rng.c           | 26 ++----
 drivers/char/tpm/tpm_ftpm_tee.c              | 31 +++++---
 drivers/firmware/arm_scmi/transports/optee.c | 32 +++-----
 drivers/firmware/broadcom/tee_bnxt_fw.c      | 30 ++-----
 drivers/firmware/efi/stmm/tee_stmm_efi.c     | 25 ++----
 drivers/rtc/rtc-optee.c                      | 27 ++-----
 drivers/tee/tee_core.c                       | 84 ++++++++++++++++++++
 include/linux/tee_drv.h                      | 12 +++
 security/keys/trusted-keys/trusted_tee.c     | 17 ++--
 10 files changed, 164 insertions(+), 138 deletions(-)


base-commit: 7d0a66e4bb9081d75c82ec4957c50034cb0ea449
-- 
2.47.3


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v1 14/17] KEYS: trusted: Migrate to use tee specific driver registration function
  2025-12-11 17:14 [PATCH v1 00/17] tee: Use bus callbacks instead of driver callbacks Uwe Kleine-König
@ 2025-12-11 17:15 ` Uwe Kleine-König
  2025-12-15  7:36   ` Sumit Garg
  2025-12-11 17:15 ` [PATCH v1 15/17] KEYS: trusted: Make use of tee bus methods Uwe Kleine-König
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 18+ messages in thread
From: Uwe Kleine-König @ 2025-12-11 17:15 UTC (permalink / raw)
  To: Jens Wiklander, Sumit Garg, James Bottomley, Jarkko Sakkinen,
	Mimi Zohar, David Howells, Paul Moore, James Morris,
	Serge E. Hallyn
  Cc: op-tee, linux-integrity, keyrings, linux-security-module,
	linux-kernel

The tee subsystem recently got a set of dedicated functions to register
(and unregister) a tee driver. Make use of them. These care for setting the
driver's bus (so the explicit assignment can be dropped) and the driver
owner (which is an improvement this driver benefits from).

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
---
 security/keys/trusted-keys/trusted_tee.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/security/keys/trusted-keys/trusted_tee.c b/security/keys/trusted-keys/trusted_tee.c
index aa3d477de6db..3cea9a377955 100644
--- a/security/keys/trusted-keys/trusted_tee.c
+++ b/security/keys/trusted-keys/trusted_tee.c
@@ -264,7 +264,6 @@ static struct tee_client_driver trusted_key_driver = {
 	.id_table	= trusted_key_id_table,
 	.driver		= {
 		.name		= DRIVER_NAME,
-		.bus		= &tee_bus_type,
 		.probe		= trusted_key_probe,
 		.remove		= trusted_key_remove,
 	},
@@ -272,12 +271,12 @@ static struct tee_client_driver trusted_key_driver = {
 
 static int trusted_tee_init(void)
 {
-	return driver_register(&trusted_key_driver.driver);
+	return tee_client_driver_register(&trusted_key_driver);
 }
 
 static void trusted_tee_exit(void)
 {
-	driver_unregister(&trusted_key_driver.driver);
+	tee_client_driver_unregister(&trusted_key_driver);
 }
 
 struct trusted_key_ops trusted_key_tee_ops = {
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v1 15/17] KEYS: trusted: Make use of tee bus methods
  2025-12-11 17:14 [PATCH v1 00/17] tee: Use bus callbacks instead of driver callbacks Uwe Kleine-König
  2025-12-11 17:15 ` [PATCH v1 14/17] KEYS: trusted: Migrate to use tee specific driver registration function Uwe Kleine-König
@ 2025-12-11 17:15 ` Uwe Kleine-König
  2025-12-15  7:36   ` Sumit Garg
  2025-12-11 17:15 ` [PATCH v1 16/17] tpm/tpm_ftpm_tee: Make use of tee specific driver registration Uwe Kleine-König
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 18+ messages in thread
From: Uwe Kleine-König @ 2025-12-11 17:15 UTC (permalink / raw)
  To: Jens Wiklander, Sumit Garg, James Bottomley, Jarkko Sakkinen,
	Mimi Zohar, David Howells, Paul Moore, James Morris,
	Serge E. Hallyn
  Cc: op-tee, linux-integrity, keyrings, linux-security-module,
	linux-kernel

The tee bus got dedicated callbacks for probe and remove.
Make use of these. This fixes a runtime warning about the driver needing
to be converted to the bus methods.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
---
 security/keys/trusted-keys/trusted_tee.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/security/keys/trusted-keys/trusted_tee.c b/security/keys/trusted-keys/trusted_tee.c
index 3cea9a377955..6e465c8bef5e 100644
--- a/security/keys/trusted-keys/trusted_tee.c
+++ b/security/keys/trusted-keys/trusted_tee.c
@@ -202,9 +202,9 @@ static int optee_ctx_match(struct tee_ioctl_version_data *ver, const void *data)
 		return 0;
 }
 
-static int trusted_key_probe(struct device *dev)
+static int trusted_key_probe(struct tee_client_device *rng_device)
 {
-	struct tee_client_device *rng_device = to_tee_client_device(dev);
+	struct device *dev = &rng_device->dev;
 	int ret;
 	struct tee_ioctl_open_session_arg sess_arg;
 
@@ -244,13 +244,11 @@ static int trusted_key_probe(struct device *dev)
 	return ret;
 }
 
-static int trusted_key_remove(struct device *dev)
+static void trusted_key_remove(struct tee_client_device *dev)
 {
 	unregister_key_type(&key_type_trusted);
 	tee_client_close_session(pvt_data.ctx, pvt_data.session_id);
 	tee_client_close_context(pvt_data.ctx);
-
-	return 0;
 }
 
 static const struct tee_client_device_id trusted_key_id_table[] = {
@@ -261,11 +259,11 @@ static const struct tee_client_device_id trusted_key_id_table[] = {
 MODULE_DEVICE_TABLE(tee, trusted_key_id_table);
 
 static struct tee_client_driver trusted_key_driver = {
+	.probe		= trusted_key_probe,
+	.remove		= trusted_key_remove,
 	.id_table	= trusted_key_id_table,
 	.driver		= {
 		.name		= DRIVER_NAME,
-		.probe		= trusted_key_probe,
-		.remove		= trusted_key_remove,
 	},
 };
 
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v1 16/17] tpm/tpm_ftpm_tee: Make use of tee specific driver registration
  2025-12-11 17:14 [PATCH v1 00/17] tee: Use bus callbacks instead of driver callbacks Uwe Kleine-König
  2025-12-11 17:15 ` [PATCH v1 14/17] KEYS: trusted: Migrate to use tee specific driver registration function Uwe Kleine-König
  2025-12-11 17:15 ` [PATCH v1 15/17] KEYS: trusted: Make use of tee bus methods Uwe Kleine-König
@ 2025-12-11 17:15 ` Uwe Kleine-König
  2025-12-15  7:38   ` Sumit Garg
  2025-12-11 17:15 ` [PATCH v1 17/17] tpm/tpm_ftpm_tee: Make use of tee bus methods Uwe Kleine-König
  2025-12-15  7:54 ` [PATCH v1 00/17] tee: Use bus callbacks instead of driver callbacks Sumit Garg
  4 siblings, 1 reply; 18+ messages in thread
From: Uwe Kleine-König @ 2025-12-11 17:15 UTC (permalink / raw)
  To: Jens Wiklander, Peter Huewe, Jarkko Sakkinen
  Cc: Jason Gunthorpe, Sumit Garg, op-tee, linux-integrity,
	linux-kernel

tee_client_driver_register() is typed more strongly and cares about
assigning the driver's bus. Similar for tee_client_driver_unregister().

Make use of these functions.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
---
 drivers/char/tpm/tpm_ftpm_tee.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/char/tpm/tpm_ftpm_tee.c b/drivers/char/tpm/tpm_ftpm_tee.c
index 4e63c30aeaf1..e5fbc70b0eca 100644
--- a/drivers/char/tpm/tpm_ftpm_tee.c
+++ b/drivers/char/tpm/tpm_ftpm_tee.c
@@ -338,7 +338,6 @@ static struct tee_client_driver ftpm_tee_driver = {
 	.id_table	= optee_ftpm_id_table,
 	.driver		= {
 		.name		= "optee-ftpm",
-		.bus		= &tee_bus_type,
 		.probe		= ftpm_tee_probe,
 		.remove		= ftpm_tee_remove,
 	},
@@ -352,7 +351,7 @@ static int __init ftpm_mod_init(void)
 	if (rc)
 		return rc;
 
-	rc = driver_register(&ftpm_tee_driver.driver);
+	rc = tee_client_driver_register(&ftpm_tee_driver);
 	if (rc) {
 		platform_driver_unregister(&ftpm_tee_plat_driver);
 		return rc;
@@ -364,7 +363,7 @@ static int __init ftpm_mod_init(void)
 static void __exit ftpm_mod_exit(void)
 {
 	platform_driver_unregister(&ftpm_tee_plat_driver);
-	driver_unregister(&ftpm_tee_driver.driver);
+	tee_client_driver_unregister(&ftpm_tee_driver);
 }
 
 module_init(ftpm_mod_init);
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v1 17/17] tpm/tpm_ftpm_tee: Make use of tee bus methods
  2025-12-11 17:14 [PATCH v1 00/17] tee: Use bus callbacks instead of driver callbacks Uwe Kleine-König
                   ` (2 preceding siblings ...)
  2025-12-11 17:15 ` [PATCH v1 16/17] tpm/tpm_ftpm_tee: Make use of tee specific driver registration Uwe Kleine-König
@ 2025-12-11 17:15 ` Uwe Kleine-König
  2025-12-11 20:22   ` Jarkko Sakkinen
                     ` (2 more replies)
  2025-12-15  7:54 ` [PATCH v1 00/17] tee: Use bus callbacks instead of driver callbacks Sumit Garg
  4 siblings, 3 replies; 18+ messages in thread
From: Uwe Kleine-König @ 2025-12-11 17:15 UTC (permalink / raw)
  To: Jens Wiklander, Peter Huewe, Jarkko Sakkinen
  Cc: Jason Gunthorpe, Sumit Garg, op-tee, linux-integrity,
	linux-kernel

The tee bus got dedicated callbacks for probe and remove.
Make use of these. This fixes a runtime warning about the driver needing
to be converted to the bus methods.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
---
 drivers/char/tpm/tpm_ftpm_tee.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/drivers/char/tpm/tpm_ftpm_tee.c b/drivers/char/tpm/tpm_ftpm_tee.c
index e5fbc70b0eca..20294d1953a3 100644
--- a/drivers/char/tpm/tpm_ftpm_tee.c
+++ b/drivers/char/tpm/tpm_ftpm_tee.c
@@ -169,7 +169,7 @@ static int ftpm_tee_match(struct tee_ioctl_version_data *ver, const void *data)
  * Return:
  *	On success, 0. On failure, -errno.
  */
-static int ftpm_tee_probe(struct device *dev)
+static int ftpm_tee_probe_generic(struct device *dev)
 {
 	int rc;
 	struct tpm_chip *chip;
@@ -251,11 +251,18 @@ static int ftpm_tee_probe(struct device *dev)
 	return rc;
 }
 
+static int ftpm_tee_probe(struct tee_client_device *tcdev)
+{
+	struct device *dev = &tcdev->dev;
+
+	return ftpm_tee_probe_generic(dev);
+}
+
 static int ftpm_plat_tee_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 
-	return ftpm_tee_probe(dev);
+	return ftpm_tee_probe_generic(dev);
 }
 
 /**
@@ -265,7 +272,7 @@ static int ftpm_plat_tee_probe(struct platform_device *pdev)
  * Return:
  *	0 always.
  */
-static int ftpm_tee_remove(struct device *dev)
+static void ftpm_tee_remove_generic(struct device *dev)
 {
 	struct ftpm_tee_private *pvt_data = dev_get_drvdata(dev);
 
@@ -285,15 +292,20 @@ static int ftpm_tee_remove(struct device *dev)
 	tee_client_close_context(pvt_data->ctx);
 
 	/* memory allocated with devm_kzalloc() is freed automatically */
+}
 
-	return 0;
+static void ftpm_tee_remove(struct tee_client_device *tcdev)
+{
+	struct device *dev = &tcdev->dev;
+
+	ftpm_tee_remove_generic(dev);
 }
 
 static void ftpm_plat_tee_remove(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 
-	ftpm_tee_remove(dev);
+	ftpm_tee_remove_generic(dev);
 }
 
 /**
@@ -335,11 +347,11 @@ static const struct tee_client_device_id optee_ftpm_id_table[] = {
 MODULE_DEVICE_TABLE(tee, optee_ftpm_id_table);
 
 static struct tee_client_driver ftpm_tee_driver = {
+	.probe		= ftpm_tee_probe,
+	.remove		= ftpm_tee_remove,
 	.id_table	= optee_ftpm_id_table,
 	.driver		= {
 		.name		= "optee-ftpm",
-		.probe		= ftpm_tee_probe,
-		.remove		= ftpm_tee_remove,
 	},
 };
 
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH v1 17/17] tpm/tpm_ftpm_tee: Make use of tee bus methods
  2025-12-11 17:15 ` [PATCH v1 17/17] tpm/tpm_ftpm_tee: Make use of tee bus methods Uwe Kleine-König
@ 2025-12-11 20:22   ` Jarkko Sakkinen
  2025-12-11 20:22   ` Jarkko Sakkinen
  2025-12-15  7:40   ` Sumit Garg
  2 siblings, 0 replies; 18+ messages in thread
From: Jarkko Sakkinen @ 2025-12-11 20:22 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Jens Wiklander, Peter Huewe, Jason Gunthorpe, Sumit Garg, op-tee,
	linux-integrity, linux-kernel

On Thu, Dec 11, 2025 at 06:15:11PM +0100, Uwe Kleine-König wrote:
> The tee bus got dedicated callbacks for probe and remove.
> Make use of these. This fixes a runtime warning about the driver needing
> to be converted to the bus methods.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
> ---
>  drivers/char/tpm/tpm_ftpm_tee.c | 26 +++++++++++++++++++-------
>  1 file changed, 19 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/char/tpm/tpm_ftpm_tee.c b/drivers/char/tpm/tpm_ftpm_tee.c
> index e5fbc70b0eca..20294d1953a3 100644
> --- a/drivers/char/tpm/tpm_ftpm_tee.c
> +++ b/drivers/char/tpm/tpm_ftpm_tee.c
> @@ -169,7 +169,7 @@ static int ftpm_tee_match(struct tee_ioctl_version_data *ver, const void *data)
>   * Return:
>   *	On success, 0. On failure, -errno.
>   */
> -static int ftpm_tee_probe(struct device *dev)
> +static int ftpm_tee_probe_generic(struct device *dev)
>  {
>  	int rc;
>  	struct tpm_chip *chip;
> @@ -251,11 +251,18 @@ static int ftpm_tee_probe(struct device *dev)
>  	return rc;
>  }
>  
> +static int ftpm_tee_probe(struct tee_client_device *tcdev)
> +{
> +	struct device *dev = &tcdev->dev;
> +
> +	return ftpm_tee_probe_generic(dev);
> +}
> +
>  static int ftpm_plat_tee_probe(struct platform_device *pdev)
>  {
>  	struct device *dev = &pdev->dev;
>  
> -	return ftpm_tee_probe(dev);
> +	return ftpm_tee_probe_generic(dev);
>  }
>  
>  /**
> @@ -265,7 +272,7 @@ static int ftpm_plat_tee_probe(struct platform_device *pdev)
>   * Return:
>   *	0 always.
>   */
> -static int ftpm_tee_remove(struct device *dev)
> +static void ftpm_tee_remove_generic(struct device *dev)
>  {
>  	struct ftpm_tee_private *pvt_data = dev_get_drvdata(dev);
>  
> @@ -285,15 +292,20 @@ static int ftpm_tee_remove(struct device *dev)
>  	tee_client_close_context(pvt_data->ctx);
>  
>  	/* memory allocated with devm_kzalloc() is freed automatically */
> +}
>  
> -	return 0;
> +static void ftpm_tee_remove(struct tee_client_device *tcdev)
> +{
> +	struct device *dev = &tcdev->dev;
> +
> +	ftpm_tee_remove_generic(dev);
>  }
>  
>  static void ftpm_plat_tee_remove(struct platform_device *pdev)
>  {
>  	struct device *dev = &pdev->dev;
>  
> -	ftpm_tee_remove(dev);
> +	ftpm_tee_remove_generic(dev);
>  }
>  
>  /**
> @@ -335,11 +347,11 @@ static const struct tee_client_device_id optee_ftpm_id_table[] = {
>  MODULE_DEVICE_TABLE(tee, optee_ftpm_id_table);
>  
>  static struct tee_client_driver ftpm_tee_driver = {
> +	.probe		= ftpm_tee_probe,
> +	.remove		= ftpm_tee_remove,
>  	.id_table	= optee_ftpm_id_table,
>  	.driver		= {
>  		.name		= "optee-ftpm",
> -		.probe		= ftpm_tee_probe,
> -		.remove		= ftpm_tee_remove,
>  	},
>  };
>  
> -- 
> 2.47.3
> 

I checked trusted key patches and ftpm patches. I don't have anything
against merging them.

So for those four patches:

Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>

BR, Jarkko

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v1 17/17] tpm/tpm_ftpm_tee: Make use of tee bus methods
  2025-12-11 17:15 ` [PATCH v1 17/17] tpm/tpm_ftpm_tee: Make use of tee bus methods Uwe Kleine-König
  2025-12-11 20:22   ` Jarkko Sakkinen
@ 2025-12-11 20:22   ` Jarkko Sakkinen
  2025-12-15  7:40   ` Sumit Garg
  2 siblings, 0 replies; 18+ messages in thread
From: Jarkko Sakkinen @ 2025-12-11 20:22 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Jens Wiklander, Peter Huewe, Jason Gunthorpe, Sumit Garg, op-tee,
	linux-integrity, linux-kernel

On Thu, Dec 11, 2025 at 06:15:11PM +0100, Uwe Kleine-König wrote:
> The tee bus got dedicated callbacks for probe and remove.
> Make use of these. This fixes a runtime warning about the driver needing
> to be converted to the bus methods.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
> ---
>  drivers/char/tpm/tpm_ftpm_tee.c | 26 +++++++++++++++++++-------
>  1 file changed, 19 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/char/tpm/tpm_ftpm_tee.c b/drivers/char/tpm/tpm_ftpm_tee.c
> index e5fbc70b0eca..20294d1953a3 100644
> --- a/drivers/char/tpm/tpm_ftpm_tee.c
> +++ b/drivers/char/tpm/tpm_ftpm_tee.c
> @@ -169,7 +169,7 @@ static int ftpm_tee_match(struct tee_ioctl_version_data *ver, const void *data)
>   * Return:
>   *	On success, 0. On failure, -errno.
>   */
> -static int ftpm_tee_probe(struct device *dev)
> +static int ftpm_tee_probe_generic(struct device *dev)
>  {
>  	int rc;
>  	struct tpm_chip *chip;
> @@ -251,11 +251,18 @@ static int ftpm_tee_probe(struct device *dev)
>  	return rc;
>  }
>  
> +static int ftpm_tee_probe(struct tee_client_device *tcdev)
> +{
> +	struct device *dev = &tcdev->dev;
> +
> +	return ftpm_tee_probe_generic(dev);
> +}
> +
>  static int ftpm_plat_tee_probe(struct platform_device *pdev)
>  {
>  	struct device *dev = &pdev->dev;
>  
> -	return ftpm_tee_probe(dev);
> +	return ftpm_tee_probe_generic(dev);
>  }
>  
>  /**
> @@ -265,7 +272,7 @@ static int ftpm_plat_tee_probe(struct platform_device *pdev)
>   * Return:
>   *	0 always.
>   */
> -static int ftpm_tee_remove(struct device *dev)
> +static void ftpm_tee_remove_generic(struct device *dev)
>  {
>  	struct ftpm_tee_private *pvt_data = dev_get_drvdata(dev);
>  
> @@ -285,15 +292,20 @@ static int ftpm_tee_remove(struct device *dev)
>  	tee_client_close_context(pvt_data->ctx);
>  
>  	/* memory allocated with devm_kzalloc() is freed automatically */
> +}
>  
> -	return 0;
> +static void ftpm_tee_remove(struct tee_client_device *tcdev)
> +{
> +	struct device *dev = &tcdev->dev;
> +
> +	ftpm_tee_remove_generic(dev);
>  }
>  
>  static void ftpm_plat_tee_remove(struct platform_device *pdev)
>  {
>  	struct device *dev = &pdev->dev;
>  
> -	ftpm_tee_remove(dev);
> +	ftpm_tee_remove_generic(dev);
>  }
>  
>  /**
> @@ -335,11 +347,11 @@ static const struct tee_client_device_id optee_ftpm_id_table[] = {
>  MODULE_DEVICE_TABLE(tee, optee_ftpm_id_table);
>  
>  static struct tee_client_driver ftpm_tee_driver = {
> +	.probe		= ftpm_tee_probe,
> +	.remove		= ftpm_tee_remove,
>  	.id_table	= optee_ftpm_id_table,
>  	.driver		= {
>  		.name		= "optee-ftpm",
> -		.probe		= ftpm_tee_probe,
> -		.remove		= ftpm_tee_remove,
>  	},
>  };
>  
> -- 
> 2.47.3
> 

And also for this:

Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>

BR, Jarkko

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v1 14/17] KEYS: trusted: Migrate to use tee specific driver registration function
  2025-12-11 17:15 ` [PATCH v1 14/17] KEYS: trusted: Migrate to use tee specific driver registration function Uwe Kleine-König
@ 2025-12-15  7:36   ` Sumit Garg
  0 siblings, 0 replies; 18+ messages in thread
From: Sumit Garg @ 2025-12-15  7:36 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Jens Wiklander, James Bottomley, Jarkko Sakkinen, Mimi Zohar,
	David Howells, Paul Moore, James Morris, Serge E. Hallyn, op-tee,
	linux-integrity, keyrings, linux-security-module, linux-kernel

On Thu, Dec 11, 2025 at 06:15:08PM +0100, Uwe Kleine-König wrote:
> The tee subsystem recently got a set of dedicated functions to register
> (and unregister) a tee driver. Make use of them. These care for setting the
> driver's bus (so the explicit assignment can be dropped) and the driver
> owner (which is an improvement this driver benefits from).
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
> ---
>  security/keys/trusted-keys/trusted_tee.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)

Reviewed-by: Sumit Garg <sumit.garg@oss.qualcomm.com>

-Sumit

> 
> diff --git a/security/keys/trusted-keys/trusted_tee.c b/security/keys/trusted-keys/trusted_tee.c
> index aa3d477de6db..3cea9a377955 100644
> --- a/security/keys/trusted-keys/trusted_tee.c
> +++ b/security/keys/trusted-keys/trusted_tee.c
> @@ -264,7 +264,6 @@ static struct tee_client_driver trusted_key_driver = {
>  	.id_table	= trusted_key_id_table,
>  	.driver		= {
>  		.name		= DRIVER_NAME,
> -		.bus		= &tee_bus_type,
>  		.probe		= trusted_key_probe,
>  		.remove		= trusted_key_remove,
>  	},
> @@ -272,12 +271,12 @@ static struct tee_client_driver trusted_key_driver = {
>  
>  static int trusted_tee_init(void)
>  {
> -	return driver_register(&trusted_key_driver.driver);
> +	return tee_client_driver_register(&trusted_key_driver);
>  }
>  
>  static void trusted_tee_exit(void)
>  {
> -	driver_unregister(&trusted_key_driver.driver);
> +	tee_client_driver_unregister(&trusted_key_driver);
>  }
>  
>  struct trusted_key_ops trusted_key_tee_ops = {
> -- 
> 2.47.3
> 

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v1 15/17] KEYS: trusted: Make use of tee bus methods
  2025-12-11 17:15 ` [PATCH v1 15/17] KEYS: trusted: Make use of tee bus methods Uwe Kleine-König
@ 2025-12-15  7:36   ` Sumit Garg
  0 siblings, 0 replies; 18+ messages in thread
From: Sumit Garg @ 2025-12-15  7:36 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Jens Wiklander, James Bottomley, Jarkko Sakkinen, Mimi Zohar,
	David Howells, Paul Moore, James Morris, Serge E. Hallyn, op-tee,
	linux-integrity, keyrings, linux-security-module, linux-kernel

On Thu, Dec 11, 2025 at 06:15:09PM +0100, Uwe Kleine-König wrote:
> The tee bus got dedicated callbacks for probe and remove.
> Make use of these. This fixes a runtime warning about the driver needing
> to be converted to the bus methods.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
> ---
>  security/keys/trusted-keys/trusted_tee.c | 12 +++++-------
>  1 file changed, 5 insertions(+), 7 deletions(-)

Reviewed-by: Sumit Garg <sumit.garg@oss.qualcomm.com>

-Sumit

> 
> diff --git a/security/keys/trusted-keys/trusted_tee.c b/security/keys/trusted-keys/trusted_tee.c
> index 3cea9a377955..6e465c8bef5e 100644
> --- a/security/keys/trusted-keys/trusted_tee.c
> +++ b/security/keys/trusted-keys/trusted_tee.c
> @@ -202,9 +202,9 @@ static int optee_ctx_match(struct tee_ioctl_version_data *ver, const void *data)
>  		return 0;
>  }
>  
> -static int trusted_key_probe(struct device *dev)
> +static int trusted_key_probe(struct tee_client_device *rng_device)
>  {
> -	struct tee_client_device *rng_device = to_tee_client_device(dev);
> +	struct device *dev = &rng_device->dev;
>  	int ret;
>  	struct tee_ioctl_open_session_arg sess_arg;
>  
> @@ -244,13 +244,11 @@ static int trusted_key_probe(struct device *dev)
>  	return ret;
>  }
>  
> -static int trusted_key_remove(struct device *dev)
> +static void trusted_key_remove(struct tee_client_device *dev)
>  {
>  	unregister_key_type(&key_type_trusted);
>  	tee_client_close_session(pvt_data.ctx, pvt_data.session_id);
>  	tee_client_close_context(pvt_data.ctx);
> -
> -	return 0;
>  }
>  
>  static const struct tee_client_device_id trusted_key_id_table[] = {
> @@ -261,11 +259,11 @@ static const struct tee_client_device_id trusted_key_id_table[] = {
>  MODULE_DEVICE_TABLE(tee, trusted_key_id_table);
>  
>  static struct tee_client_driver trusted_key_driver = {
> +	.probe		= trusted_key_probe,
> +	.remove		= trusted_key_remove,
>  	.id_table	= trusted_key_id_table,
>  	.driver		= {
>  		.name		= DRIVER_NAME,
> -		.probe		= trusted_key_probe,
> -		.remove		= trusted_key_remove,
>  	},
>  };
>  
> -- 
> 2.47.3
> 

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v1 16/17] tpm/tpm_ftpm_tee: Make use of tee specific driver registration
  2025-12-11 17:15 ` [PATCH v1 16/17] tpm/tpm_ftpm_tee: Make use of tee specific driver registration Uwe Kleine-König
@ 2025-12-15  7:38   ` Sumit Garg
  0 siblings, 0 replies; 18+ messages in thread
From: Sumit Garg @ 2025-12-15  7:38 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Jens Wiklander, Peter Huewe, Jarkko Sakkinen, Jason Gunthorpe,
	op-tee, linux-integrity, linux-kernel

On Thu, Dec 11, 2025 at 06:15:10PM +0100, Uwe Kleine-König wrote:
> tee_client_driver_register() is typed more strongly and cares about
> assigning the driver's bus. Similar for tee_client_driver_unregister().
> 
> Make use of these functions.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
> ---
>  drivers/char/tpm/tpm_ftpm_tee.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)

Reviewed-by: Sumit Garg <sumit.garg@oss.qualcomm.com>

-Sumit

> 
> diff --git a/drivers/char/tpm/tpm_ftpm_tee.c b/drivers/char/tpm/tpm_ftpm_tee.c
> index 4e63c30aeaf1..e5fbc70b0eca 100644
> --- a/drivers/char/tpm/tpm_ftpm_tee.c
> +++ b/drivers/char/tpm/tpm_ftpm_tee.c
> @@ -338,7 +338,6 @@ static struct tee_client_driver ftpm_tee_driver = {
>  	.id_table	= optee_ftpm_id_table,
>  	.driver		= {
>  		.name		= "optee-ftpm",
> -		.bus		= &tee_bus_type,
>  		.probe		= ftpm_tee_probe,
>  		.remove		= ftpm_tee_remove,
>  	},
> @@ -352,7 +351,7 @@ static int __init ftpm_mod_init(void)
>  	if (rc)
>  		return rc;
>  
> -	rc = driver_register(&ftpm_tee_driver.driver);
> +	rc = tee_client_driver_register(&ftpm_tee_driver);
>  	if (rc) {
>  		platform_driver_unregister(&ftpm_tee_plat_driver);
>  		return rc;
> @@ -364,7 +363,7 @@ static int __init ftpm_mod_init(void)
>  static void __exit ftpm_mod_exit(void)
>  {
>  	platform_driver_unregister(&ftpm_tee_plat_driver);
> -	driver_unregister(&ftpm_tee_driver.driver);
> +	tee_client_driver_unregister(&ftpm_tee_driver);
>  }
>  
>  module_init(ftpm_mod_init);
> -- 
> 2.47.3
> 
> 

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v1 17/17] tpm/tpm_ftpm_tee: Make use of tee bus methods
  2025-12-11 17:15 ` [PATCH v1 17/17] tpm/tpm_ftpm_tee: Make use of tee bus methods Uwe Kleine-König
  2025-12-11 20:22   ` Jarkko Sakkinen
  2025-12-11 20:22   ` Jarkko Sakkinen
@ 2025-12-15  7:40   ` Sumit Garg
  2 siblings, 0 replies; 18+ messages in thread
From: Sumit Garg @ 2025-12-15  7:40 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Jens Wiklander, Peter Huewe, Jarkko Sakkinen, Jason Gunthorpe,
	op-tee, linux-integrity, linux-kernel

On Thu, Dec 11, 2025 at 06:15:11PM +0100, Uwe Kleine-König wrote:
> The tee bus got dedicated callbacks for probe and remove.
> Make use of these. This fixes a runtime warning about the driver needing
> to be converted to the bus methods.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
> ---
>  drivers/char/tpm/tpm_ftpm_tee.c | 26 +++++++++++++++++++-------
>  1 file changed, 19 insertions(+), 7 deletions(-)

Reviewed-by: Sumit Garg <sumit.garg@oss.qualcomm.com>

-Sumit

> 
> diff --git a/drivers/char/tpm/tpm_ftpm_tee.c b/drivers/char/tpm/tpm_ftpm_tee.c
> index e5fbc70b0eca..20294d1953a3 100644
> --- a/drivers/char/tpm/tpm_ftpm_tee.c
> +++ b/drivers/char/tpm/tpm_ftpm_tee.c
> @@ -169,7 +169,7 @@ static int ftpm_tee_match(struct tee_ioctl_version_data *ver, const void *data)
>   * Return:
>   *	On success, 0. On failure, -errno.
>   */
> -static int ftpm_tee_probe(struct device *dev)
> +static int ftpm_tee_probe_generic(struct device *dev)
>  {
>  	int rc;
>  	struct tpm_chip *chip;
> @@ -251,11 +251,18 @@ static int ftpm_tee_probe(struct device *dev)
>  	return rc;
>  }
>  
> +static int ftpm_tee_probe(struct tee_client_device *tcdev)
> +{
> +	struct device *dev = &tcdev->dev;
> +
> +	return ftpm_tee_probe_generic(dev);
> +}
> +
>  static int ftpm_plat_tee_probe(struct platform_device *pdev)
>  {
>  	struct device *dev = &pdev->dev;
>  
> -	return ftpm_tee_probe(dev);
> +	return ftpm_tee_probe_generic(dev);
>  }
>  
>  /**
> @@ -265,7 +272,7 @@ static int ftpm_plat_tee_probe(struct platform_device *pdev)
>   * Return:
>   *	0 always.
>   */
> -static int ftpm_tee_remove(struct device *dev)
> +static void ftpm_tee_remove_generic(struct device *dev)
>  {
>  	struct ftpm_tee_private *pvt_data = dev_get_drvdata(dev);
>  
> @@ -285,15 +292,20 @@ static int ftpm_tee_remove(struct device *dev)
>  	tee_client_close_context(pvt_data->ctx);
>  
>  	/* memory allocated with devm_kzalloc() is freed automatically */
> +}
>  
> -	return 0;
> +static void ftpm_tee_remove(struct tee_client_device *tcdev)
> +{
> +	struct device *dev = &tcdev->dev;
> +
> +	ftpm_tee_remove_generic(dev);
>  }
>  
>  static void ftpm_plat_tee_remove(struct platform_device *pdev)
>  {
>  	struct device *dev = &pdev->dev;
>  
> -	ftpm_tee_remove(dev);
> +	ftpm_tee_remove_generic(dev);
>  }
>  
>  /**
> @@ -335,11 +347,11 @@ static const struct tee_client_device_id optee_ftpm_id_table[] = {
>  MODULE_DEVICE_TABLE(tee, optee_ftpm_id_table);
>  
>  static struct tee_client_driver ftpm_tee_driver = {
> +	.probe		= ftpm_tee_probe,
> +	.remove		= ftpm_tee_remove,
>  	.id_table	= optee_ftpm_id_table,
>  	.driver		= {
>  		.name		= "optee-ftpm",
> -		.probe		= ftpm_tee_probe,
> -		.remove		= ftpm_tee_remove,
>  	},
>  };
>  
> -- 
> 2.47.3
> 
> 

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v1 00/17] tee: Use bus callbacks instead of driver callbacks
  2025-12-11 17:14 [PATCH v1 00/17] tee: Use bus callbacks instead of driver callbacks Uwe Kleine-König
                   ` (3 preceding siblings ...)
  2025-12-11 17:15 ` [PATCH v1 17/17] tpm/tpm_ftpm_tee: Make use of tee bus methods Uwe Kleine-König
@ 2025-12-15  7:54 ` Sumit Garg
  2025-12-15  9:32   ` Uwe Kleine-König
  4 siblings, 1 reply; 18+ messages in thread
From: Sumit Garg @ 2025-12-15  7:54 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Jens Wiklander, Olivia Mackall, Herbert Xu,
	Clément Léger, Alexandre Belloni, Ard Biesheuvel,
	Maxime Coquelin, Alexandre Torgue, Sumit Garg, Ilias Apalodimas,
	Jan Kiszka, Sudeep Holla, Christophe JAILLET, Michael Chan,
	Pavan Chebbi, Rafał Miłecki, James Bottomley,
	Jarkko Sakkinen, Mimi Zohar, David Howells, Paul Moore,
	James Morris, Serge E. Hallyn, Peter Huewe, op-tee, linux-kernel,
	linux-crypto, linux-rtc, linux-efi, linux-stm32, linux-arm-kernel,
	Cristian Marussi, arm-scmi, netdev, linux-mips, linux-integrity,
	keyrings, linux-security-module, Jason Gunthorpe

On Thu, Dec 11, 2025 at 06:14:54PM +0100, Uwe Kleine-König wrote:
> Hello,
> 
> the objective of this series is to make tee driver stop using callbacks
> in struct device_driver. These were superseded by bus methods in 2006
> (commit 594c8281f905 ("[PATCH] Add bus_type probe, remove, shutdown
> methods.")) but nobody cared to convert all subsystems accordingly.
> 
> Here the tee drivers are converted. The first commit is somewhat
> unrelated, but simplifies the conversion (and the drivers). It
> introduces driver registration helpers that care about setting the bus
> and owner. (The latter is missing in all drivers, so by using these
> helpers the drivers become more correct.)
> 
> The patches #4 - #17 depend on the first two, so if they should be
> applied to their respective subsystem trees these must contain the first
> two patches first.

Thanks Uwe for your efforts to clean up the boilerplate code for TEE bus
drivers.

> 
> Note that after patch #2 is applied, unconverted drivers provoke a
> warning in driver_register(), so it would be good for the user
> experience if the whole series goes in during a single merge window.

+1

I suggest the whole series goes via the Jens tree since there shouldn't
be any chances for conflict here.

> So
> I guess an immutable branch containing the frist three patches that can
> be merged into the other subsystem trees would be sensible.
> 
> After all patches are applied, tee_bus_type can be made private to
> drivers/tee as it's not used in other places any more.
> 

Feel free to make the tee_bus_type private as the last patch in the series
such that any followup driver follows this clean approach.

-Sumit

> Best regards
> Uwe
> 
> Uwe Kleine-König (17):
>   tee: Add some helpers to reduce boilerplate for tee client drivers
>   tee: Add probe, remove and shutdown bus callbacks to tee_client_driver
>   tee: Adapt documentation to cover recent additions
>   hwrng: optee - Make use of module_tee_client_driver()
>   hwrng: optee - Make use of tee bus methods
>   rtc: optee: Migrate to use tee specific driver registration function
>   rtc: optee: Make use of tee bus methods
>   efi: stmm: Make use of module_tee_client_driver()
>   efi: stmm: Make use of tee bus methods
>   firmware: arm_scmi: optee: Make use of module_tee_client_driver()
>   firmware: arm_scmi: Make use of tee bus methods
>   firmware: tee_bnxt: Make use of module_tee_client_driver()
>   firmware: tee_bnxt: Make use of tee bus methods
>   KEYS: trusted: Migrate to use tee specific driver registration
>     function
>   KEYS: trusted: Make use of tee bus methods
>   tpm/tpm_ftpm_tee: Make use of tee specific driver registration
>   tpm/tpm_ftpm_tee: Make use of tee bus methods
> 
>  Documentation/driver-api/tee.rst             | 18 +----
>  drivers/char/hw_random/optee-rng.c           | 26 ++----
>  drivers/char/tpm/tpm_ftpm_tee.c              | 31 +++++---
>  drivers/firmware/arm_scmi/transports/optee.c | 32 +++-----
>  drivers/firmware/broadcom/tee_bnxt_fw.c      | 30 ++-----
>  drivers/firmware/efi/stmm/tee_stmm_efi.c     | 25 ++----
>  drivers/rtc/rtc-optee.c                      | 27 ++-----
>  drivers/tee/tee_core.c                       | 84 ++++++++++++++++++++
>  include/linux/tee_drv.h                      | 12 +++
>  security/keys/trusted-keys/trusted_tee.c     | 17 ++--
>  10 files changed, 164 insertions(+), 138 deletions(-)
> 
> 
> base-commit: 7d0a66e4bb9081d75c82ec4957c50034cb0ea449
> -- 
> 2.47.3
> 

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v1 00/17] tee: Use bus callbacks instead of driver callbacks
  2025-12-15  7:54 ` [PATCH v1 00/17] tee: Use bus callbacks instead of driver callbacks Sumit Garg
@ 2025-12-15  9:32   ` Uwe Kleine-König
  2025-12-16  7:38     ` Sumit Garg
  0 siblings, 1 reply; 18+ messages in thread
From: Uwe Kleine-König @ 2025-12-15  9:32 UTC (permalink / raw)
  To: Sumit Garg
  Cc: Jens Wiklander, Olivia Mackall, Herbert Xu,
	Clément Léger, Alexandre Belloni, Ard Biesheuvel,
	Maxime Coquelin, Alexandre Torgue, Sumit Garg, Ilias Apalodimas,
	Jan Kiszka, Sudeep Holla, Christophe JAILLET, Michael Chan,
	Pavan Chebbi, Rafał Miłecki, James Bottomley,
	Jarkko Sakkinen, Mimi Zohar, David Howells, Paul Moore,
	James Morris, Serge E. Hallyn, Peter Huewe, op-tee, linux-kernel,
	linux-crypto, linux-rtc, linux-efi, linux-stm32, linux-arm-kernel,
	Cristian Marussi, arm-scmi, netdev, linux-mips, linux-integrity,
	keyrings, linux-security-module, Jason Gunthorpe

[-- Attachment #1: Type: text/plain, Size: 3035 bytes --]

Hello Sumit,

On Mon, Dec 15, 2025 at 04:54:11PM +0900, Sumit Garg wrote:
> On Thu, Dec 11, 2025 at 06:14:54PM +0100, Uwe Kleine-König wrote:
> > Hello,
> > 
> > the objective of this series is to make tee driver stop using callbacks
> > in struct device_driver. These were superseded by bus methods in 2006
> > (commit 594c8281f905 ("[PATCH] Add bus_type probe, remove, shutdown
> > methods.")) but nobody cared to convert all subsystems accordingly.
> > 
> > Here the tee drivers are converted. The first commit is somewhat
> > unrelated, but simplifies the conversion (and the drivers). It
> > introduces driver registration helpers that care about setting the bus
> > and owner. (The latter is missing in all drivers, so by using these
> > helpers the drivers become more correct.)
> > 
> > The patches #4 - #17 depend on the first two, so if they should be
> > applied to their respective subsystem trees these must contain the first
> > two patches first.
> 
> Thanks Uwe for your efforts to clean up the boilerplate code for TEE bus
> drivers.

Thanks for your feedback. I will prepare a v2 and address your comments
(whitespace issues and wrong callback in the shutdown method).

> > Note that after patch #2 is applied, unconverted drivers provoke a
> > warning in driver_register(), so it would be good for the user
> > experience if the whole series goes in during a single merge window.
> 
> +1
> 
> I suggest the whole series goes via the Jens tree since there shouldn't
> be any chances for conflict here.
> 
> > So
> > I guess an immutable branch containing the frist three patches that can
> > be merged into the other subsystem trees would be sensible.
> > 
> > After all patches are applied, tee_bus_type can be made private to
> > drivers/tee as it's not used in other places any more.
> > 
> 
> Feel free to make the tee_bus_type private as the last patch in the series
> such that any followup driver follows this clean approach.

There is a bit more to do for that than I'm willing to invest. With my
patch series applied `tee_bus_type` is still used in
drivers/tee/optee/device.c and drivers/tee/tee_core.c. Maybe it's
sensible to merge these two files into a single one.

The things I wonder about additionally are:

 - if CONFIG_OPTEE=n and CONFIG_TEE=y|m the tee bus is only used for
   drivers but not devices.

 - optee_register_device() calls device_create_file() on
   &optee_device->dev after device_register(&optee_device->dev).
   (Attention half-knowledge!) I think device_create_file() should not
   be called on an already registered device (or you have to send a
   uevent afterwards). This should probably use type attribute groups.
   (Or the need_supplicant attribute should be dropped as it isn't very
   useful. This would maybe be considered an ABI change however.)

 - Why does optee_probe() in drivers/tee/optee/smc_abi.c unregister all
   optee devices in its error path (optee_unregister_devices())?

Best regards
Uwe

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v1 00/17] tee: Use bus callbacks instead of driver callbacks
  2025-12-15  9:32   ` Uwe Kleine-König
@ 2025-12-16  7:38     ` Sumit Garg
  2025-12-16 11:08       ` Uwe Kleine-König
  0 siblings, 1 reply; 18+ messages in thread
From: Sumit Garg @ 2025-12-16  7:38 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Sumit Garg, Jens Wiklander, Olivia Mackall, Herbert Xu,
	Clément Léger, Alexandre Belloni, Ard Biesheuvel,
	Maxime Coquelin, Alexandre Torgue, Ilias Apalodimas, Jan Kiszka,
	Sudeep Holla, Christophe JAILLET, Michael Chan, Pavan Chebbi,
	Rafał Miłecki, James Bottomley, Jarkko Sakkinen,
	Mimi Zohar, David Howells, Paul Moore, James Morris,
	Serge E. Hallyn, Peter Huewe, op-tee, linux-kernel, linux-crypto,
	linux-rtc, linux-efi, linux-stm32, linux-arm-kernel,
	Cristian Marussi, arm-scmi, netdev, linux-mips, linux-integrity,
	keyrings, linux-security-module, Jason Gunthorpe

Hi Uwe,

On Mon, Dec 15, 2025 at 3:02 PM Uwe Kleine-König
<u.kleine-koenig@baylibre.com> wrote:
>
> Hello Sumit,
>
> On Mon, Dec 15, 2025 at 04:54:11PM +0900, Sumit Garg wrote:
> > On Thu, Dec 11, 2025 at 06:14:54PM +0100, Uwe Kleine-König wrote:
> > > Hello,
> > >
> > > the objective of this series is to make tee driver stop using callbacks
> > > in struct device_driver. These were superseded by bus methods in 2006
> > > (commit 594c8281f905 ("[PATCH] Add bus_type probe, remove, shutdown
> > > methods.")) but nobody cared to convert all subsystems accordingly.
> > >
> > > Here the tee drivers are converted. The first commit is somewhat
> > > unrelated, but simplifies the conversion (and the drivers). It
> > > introduces driver registration helpers that care about setting the bus
> > > and owner. (The latter is missing in all drivers, so by using these
> > > helpers the drivers become more correct.)
> > >
> > > The patches #4 - #17 depend on the first two, so if they should be
> > > applied to their respective subsystem trees these must contain the first
> > > two patches first.
> >
> > Thanks Uwe for your efforts to clean up the boilerplate code for TEE bus
> > drivers.
>
> Thanks for your feedback. I will prepare a v2 and address your comments
> (whitespace issues and wrong callback in the shutdown method).
>
> > > Note that after patch #2 is applied, unconverted drivers provoke a
> > > warning in driver_register(), so it would be good for the user
> > > experience if the whole series goes in during a single merge window.
> >
> > +1
> >
> > I suggest the whole series goes via the Jens tree since there shouldn't
> > be any chances for conflict here.
> >
> > > So
> > > I guess an immutable branch containing the frist three patches that can
> > > be merged into the other subsystem trees would be sensible.
> > >
> > > After all patches are applied, tee_bus_type can be made private to
> > > drivers/tee as it's not used in other places any more.
> > >
> >
> > Feel free to make the tee_bus_type private as the last patch in the series
> > such that any followup driver follows this clean approach.
>
> There is a bit more to do for that than I'm willing to invest. With my
> patch series applied `tee_bus_type` is still used in
> drivers/tee/optee/device.c and drivers/tee/tee_core.c.

Oh I see, I guess we need to come with some helpers around device
register/unregister from TEE subsystem as well. Let's plan that for a
followup patch-set, I don't want this patch-set to be bloated more.

> Maybe it's
> sensible to merge these two files into a single one.

It's not possible as the design for TEE bus is to have TEE
implementation drivers like OP-TEE, AMD-TEE, TS-TEE, QTEE and so on to
register devices on the bus.

>
> The things I wonder about additionally are:
>
>  - if CONFIG_OPTEE=n and CONFIG_TEE=y|m the tee bus is only used for
>    drivers but not devices.

Yeah since the devices are rather added by the TEE implementation driver.

>
>  - optee_register_device() calls device_create_file() on
>    &optee_device->dev after device_register(&optee_device->dev).
>    (Attention half-knowledge!) I think device_create_file() should not
>    be called on an already registered device (or you have to send a
>    uevent afterwards). This should probably use type attribute groups.
>    (Or the need_supplicant attribute should be dropped as it isn't very
>    useful. This would maybe be considered an ABI change however.)

The reasoning for this attribute should be explained by commit:
7269cba53d90 ("tee: optee: Fix supplicant based device enumeration").
In summary it's due to a weird dependency for devices we have with the
user-space daemon: tee-supplicant.

>
>  - Why does optee_probe() in drivers/tee/optee/smc_abi.c unregister all
>    optee devices in its error path (optee_unregister_devices())?

This is mostly to take care of if any device got registered before the
failure occured. Let me know if you have a better way to address that.

-Sumit

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v1 00/17] tee: Use bus callbacks instead of driver callbacks
  2025-12-16  7:38     ` Sumit Garg
@ 2025-12-16 11:08       ` Uwe Kleine-König
  2025-12-17  7:55         ` Sumit Garg
  0 siblings, 1 reply; 18+ messages in thread
From: Uwe Kleine-König @ 2025-12-16 11:08 UTC (permalink / raw)
  To: Sumit Garg
  Cc: Sumit Garg, Jens Wiklander, Olivia Mackall, Herbert Xu,
	Clément Léger, Alexandre Belloni, Ard Biesheuvel,
	Maxime Coquelin, Alexandre Torgue, Ilias Apalodimas, Jan Kiszka,
	Sudeep Holla, Christophe JAILLET, Michael Chan, Pavan Chebbi,
	Rafał Miłecki, James Bottomley, Jarkko Sakkinen,
	Mimi Zohar, David Howells, Paul Moore, James Morris,
	Serge E. Hallyn, Peter Huewe, op-tee, linux-kernel, linux-crypto,
	linux-rtc, linux-efi, linux-stm32, linux-arm-kernel,
	Cristian Marussi, arm-scmi, netdev, linux-mips, linux-integrity,
	keyrings, linux-security-module, Jason Gunthorpe

[-- Attachment #1: Type: text/plain, Size: 2840 bytes --]

Hello,

On Tue, Dec 16, 2025 at 01:08:38PM +0530, Sumit Garg wrote:
> On Mon, Dec 15, 2025 at 3:02 PM Uwe Kleine-König
> <u.kleine-koenig@baylibre.com> wrote:
> > On Mon, Dec 15, 2025 at 04:54:11PM +0900, Sumit Garg wrote:
> > > Feel free to make the tee_bus_type private as the last patch in the series
> > > such that any followup driver follows this clean approach.
> >
> > There is a bit more to do for that than I'm willing to invest. With my
> > patch series applied `tee_bus_type` is still used in
> > drivers/tee/optee/device.c and drivers/tee/tee_core.c.
> 
> Oh I see, I guess we need to come with some helpers around device
> register/unregister from TEE subsystem as well. Let's plan that for a
> followup patch-set, I don't want this patch-set to be bloated more.

Don't consider me in for that. But it sounds like a nice addition.

> > Maybe it's
> > sensible to merge these two files into a single one.
> 
> It's not possible as the design for TEE bus is to have TEE
> implementation drivers like OP-TEE, AMD-TEE, TS-TEE, QTEE and so on to
> register devices on the bus.

So only OP-TEE uses the bus for devices and the other *-TEE don't. Also
sounds like something worth to be fixed.

> > The things I wonder about additionally are:
> >
> >  - if CONFIG_OPTEE=n and CONFIG_TEE=y|m the tee bus is only used for
> >    drivers but not devices.
> 
> Yeah since the devices are rather added by the TEE implementation driver.
> 
> >
> >  - optee_register_device() calls device_create_file() on
> >    &optee_device->dev after device_register(&optee_device->dev).
> >    (Attention half-knowledge!) I think device_create_file() should not
> >    be called on an already registered device (or you have to send a
> >    uevent afterwards). This should probably use type attribute groups.
> >    (Or the need_supplicant attribute should be dropped as it isn't very
> >    useful. This would maybe be considered an ABI change however.)
> 
> The reasoning for this attribute should be explained by commit:
> 7269cba53d90 ("tee: optee: Fix supplicant based device enumeration").
> In summary it's due to a weird dependency for devices we have with the
> user-space daemon: tee-supplicant.

From reading that once I don't understand it. (But no need to explain
:-)

Still the file should better be added before device_add() is called.

> >  - Why does optee_probe() in drivers/tee/optee/smc_abi.c unregister all
> >    optee devices in its error path (optee_unregister_devices())?
> 
> This is mostly to take care of if any device got registered before the
> failure occured. Let me know if you have a better way to address that.

Without understanding the tee stuff, I'd say: Don't bother and only undo
the things that probe did before the failure.

Best regards
Uwe

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v1 00/17] tee: Use bus callbacks instead of driver callbacks
  2025-12-16 11:08       ` Uwe Kleine-König
@ 2025-12-17  7:55         ` Sumit Garg
  2025-12-17  8:21           ` Uwe Kleine-König
  0 siblings, 1 reply; 18+ messages in thread
From: Sumit Garg @ 2025-12-17  7:55 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Sumit Garg, Jens Wiklander, Olivia Mackall, Herbert Xu,
	Clément Léger, Alexandre Belloni, Ard Biesheuvel,
	Maxime Coquelin, Alexandre Torgue, Ilias Apalodimas, Jan Kiszka,
	Sudeep Holla, Christophe JAILLET, Michael Chan, Pavan Chebbi,
	Rafał Miłecki, James Bottomley, Jarkko Sakkinen,
	Mimi Zohar, David Howells, Paul Moore, James Morris,
	Serge E. Hallyn, Peter Huewe, op-tee, linux-kernel, linux-crypto,
	linux-rtc, linux-efi, linux-stm32, linux-arm-kernel,
	Cristian Marussi, arm-scmi, netdev, linux-mips, linux-integrity,
	keyrings, linux-security-module, Jason Gunthorpe

On Tue, Dec 16, 2025 at 12:08:38PM +0100, Uwe Kleine-König wrote:
> Hello,
> 
> On Tue, Dec 16, 2025 at 01:08:38PM +0530, Sumit Garg wrote:
> > On Mon, Dec 15, 2025 at 3:02 PM Uwe Kleine-König
> > <u.kleine-koenig@baylibre.com> wrote:
> > > On Mon, Dec 15, 2025 at 04:54:11PM +0900, Sumit Garg wrote:
> > > > Feel free to make the tee_bus_type private as the last patch in the series
> > > > such that any followup driver follows this clean approach.
> > >
> > > There is a bit more to do for that than I'm willing to invest. With my
> > > patch series applied `tee_bus_type` is still used in
> > > drivers/tee/optee/device.c and drivers/tee/tee_core.c.
> > 
> > Oh I see, I guess we need to come with some helpers around device
> > register/unregister from TEE subsystem as well. Let's plan that for a
> > followup patch-set, I don't want this patch-set to be bloated more.
> 
> Don't consider me in for that. But it sounds like a nice addition.
>

No worries, the current cleanup is fine for now.

> > > Maybe it's
> > > sensible to merge these two files into a single one.
> > 
> > It's not possible as the design for TEE bus is to have TEE
> > implementation drivers like OP-TEE, AMD-TEE, TS-TEE, QTEE and so on to
> > register devices on the bus.
> 
> So only OP-TEE uses the bus for devices and the other *-TEE don't. Also
> sounds like something worth to be fixed.

The TEE bus is common for all the TEE implementation drivers which need
to support kernel TEE client drivers. I am aware there will be QTEE and
TS-TEE from past discussion that they will be exposing devices on the
TEE bus.

> 
> > > The things I wonder about additionally are:
> > >
> > >  - if CONFIG_OPTEE=n and CONFIG_TEE=y|m the tee bus is only used for
> > >    drivers but not devices.
> > 
> > Yeah since the devices are rather added by the TEE implementation driver.
> > 
> > >
> > >  - optee_register_device() calls device_create_file() on
> > >    &optee_device->dev after device_register(&optee_device->dev).
> > >    (Attention half-knowledge!) I think device_create_file() should not
> > >    be called on an already registered device (or you have to send a
> > >    uevent afterwards). This should probably use type attribute groups.
> > >    (Or the need_supplicant attribute should be dropped as it isn't very
> > >    useful. This would maybe be considered an ABI change however.)
> > 
> > The reasoning for this attribute should be explained by commit:
> > 7269cba53d90 ("tee: optee: Fix supplicant based device enumeration").
> > In summary it's due to a weird dependency for devices we have with the
> > user-space daemon: tee-supplicant.
> 
> From reading that once I don't understand it. (But no need to explain
> :-)
> 
> Still the file should better be added before device_add() is called.

Noted, let me see if I can get to fix this until someone jumps in before
me.

> 
> > >  - Why does optee_probe() in drivers/tee/optee/smc_abi.c unregister all
> > >    optee devices in its error path (optee_unregister_devices())?
> > 
> > This is mostly to take care of if any device got registered before the
> > failure occured. Let me know if you have a better way to address that.
> 
> Without understanding the tee stuff, I'd say: Don't bother and only undo
> the things that probe did before the failure.
> 

True, but this is special case where if there is any leftover device
registered from the TEE implementation then it is likely going to cause
the corresponding kernel client driver crash.

-Sumit

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v1 00/17] tee: Use bus callbacks instead of driver callbacks
  2025-12-17  7:55         ` Sumit Garg
@ 2025-12-17  8:21           ` Uwe Kleine-König
  2025-12-17  9:02             ` Sumit Garg
  0 siblings, 1 reply; 18+ messages in thread
From: Uwe Kleine-König @ 2025-12-17  8:21 UTC (permalink / raw)
  To: Sumit Garg
  Cc: Sumit Garg, Jens Wiklander, Olivia Mackall, Herbert Xu,
	Clément Léger, Alexandre Belloni, Ard Biesheuvel,
	Maxime Coquelin, Alexandre Torgue, Ilias Apalodimas, Jan Kiszka,
	Sudeep Holla, Christophe JAILLET, Michael Chan, Pavan Chebbi,
	Rafał Miłecki, James Bottomley, Jarkko Sakkinen,
	Mimi Zohar, David Howells, Paul Moore, James Morris,
	Serge E. Hallyn, Peter Huewe, op-tee, linux-kernel, linux-crypto,
	linux-rtc, linux-efi, linux-stm32, linux-arm-kernel,
	Cristian Marussi, arm-scmi, netdev, linux-mips, linux-integrity,
	keyrings, linux-security-module, Jason Gunthorpe

[-- Attachment #1: Type: text/plain, Size: 1171 bytes --]

Hello Sumit,

On Wed, Dec 17, 2025 at 01:25:39PM +0530, Sumit Garg wrote:
> On Tue, Dec 16, 2025 at 12:08:38PM +0100, Uwe Kleine-König wrote:
> > On Tue, Dec 16, 2025 at 01:08:38PM +0530, Sumit Garg wrote:
> > > On Mon, Dec 15, 2025 at 3:02 PM Uwe Kleine-König
> > > <u.kleine-koenig@baylibre.com> wrote:
> > > >  - Why does optee_probe() in drivers/tee/optee/smc_abi.c unregister all
> > > >    optee devices in its error path (optee_unregister_devices())?
> > > 
> > > This is mostly to take care of if any device got registered before the
> > > failure occured. Let me know if you have a better way to address that.
> > 
> > Without understanding the tee stuff, I'd say: Don't bother and only undo
> > the things that probe did before the failure.
> 
> True, but this is special case where if there is any leftover device
> registered from the TEE implementation then it is likely going to cause
> the corresponding kernel client driver crash.

You are aware that this is racy? So if a driver crashes e.g. after
teedev_close_context() it might happen that it is registered just after
optee_unregister_devices() returns.

Best regards
Uwe

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v1 00/17] tee: Use bus callbacks instead of driver callbacks
  2025-12-17  8:21           ` Uwe Kleine-König
@ 2025-12-17  9:02             ` Sumit Garg
  0 siblings, 0 replies; 18+ messages in thread
From: Sumit Garg @ 2025-12-17  9:02 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Sumit Garg, Jens Wiklander, Olivia Mackall, Herbert Xu,
	Clément Léger, Alexandre Belloni, Ard Biesheuvel,
	Maxime Coquelin, Alexandre Torgue, Ilias Apalodimas, Jan Kiszka,
	Sudeep Holla, Christophe JAILLET, Michael Chan, Pavan Chebbi,
	Rafał Miłecki, James Bottomley, Jarkko Sakkinen,
	Mimi Zohar, David Howells, Paul Moore, James Morris,
	Serge E. Hallyn, Peter Huewe, op-tee, linux-kernel, linux-crypto,
	linux-rtc, linux-efi, linux-stm32, linux-arm-kernel,
	Cristian Marussi, arm-scmi, netdev, linux-mips, linux-integrity,
	keyrings, linux-security-module, Jason Gunthorpe

On Wed, Dec 17, 2025 at 09:21:41AM +0100, Uwe Kleine-König wrote:
> Hello Sumit,
> 
> On Wed, Dec 17, 2025 at 01:25:39PM +0530, Sumit Garg wrote:
> > On Tue, Dec 16, 2025 at 12:08:38PM +0100, Uwe Kleine-König wrote:
> > > On Tue, Dec 16, 2025 at 01:08:38PM +0530, Sumit Garg wrote:
> > > > On Mon, Dec 15, 2025 at 3:02 PM Uwe Kleine-König
> > > > <u.kleine-koenig@baylibre.com> wrote:
> > > > >  - Why does optee_probe() in drivers/tee/optee/smc_abi.c unregister all
> > > > >    optee devices in its error path (optee_unregister_devices())?
> > > > 
> > > > This is mostly to take care of if any device got registered before the
> > > > failure occured. Let me know if you have a better way to address that.
> > > 
> > > Without understanding the tee stuff, I'd say: Don't bother and only undo
> > > the things that probe did before the failure.
> > 
> > True, but this is special case where if there is any leftover device
> > registered from the TEE implementation then it is likely going to cause
> > the corresponding kernel client driver crash.
> 
> You are aware that this is racy? So if a driver crashes e.g. after
> teedev_close_context() it might happen that it is registered just after
> optee_unregister_devices() returns.
> 

I see your point about the unavoidable race. Maybe it's better to not
try anything and let the kernel client driver fail.

-Sumit

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2025-12-17  9:02 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-11 17:14 [PATCH v1 00/17] tee: Use bus callbacks instead of driver callbacks Uwe Kleine-König
2025-12-11 17:15 ` [PATCH v1 14/17] KEYS: trusted: Migrate to use tee specific driver registration function Uwe Kleine-König
2025-12-15  7:36   ` Sumit Garg
2025-12-11 17:15 ` [PATCH v1 15/17] KEYS: trusted: Make use of tee bus methods Uwe Kleine-König
2025-12-15  7:36   ` Sumit Garg
2025-12-11 17:15 ` [PATCH v1 16/17] tpm/tpm_ftpm_tee: Make use of tee specific driver registration Uwe Kleine-König
2025-12-15  7:38   ` Sumit Garg
2025-12-11 17:15 ` [PATCH v1 17/17] tpm/tpm_ftpm_tee: Make use of tee bus methods Uwe Kleine-König
2025-12-11 20:22   ` Jarkko Sakkinen
2025-12-11 20:22   ` Jarkko Sakkinen
2025-12-15  7:40   ` Sumit Garg
2025-12-15  7:54 ` [PATCH v1 00/17] tee: Use bus callbacks instead of driver callbacks Sumit Garg
2025-12-15  9:32   ` Uwe Kleine-König
2025-12-16  7:38     ` Sumit Garg
2025-12-16 11:08       ` Uwe Kleine-König
2025-12-17  7:55         ` Sumit Garg
2025-12-17  8:21           ` Uwe Kleine-König
2025-12-17  9:02             ` Sumit Garg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).