All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] firmware: arm_ffa: Add missing remove callback to ffa_bus_type
@ 2021-09-24  9:28 Sudeep Holla
  2021-09-24  9:28 ` [PATCH 2/2] firmware: arm_ffa: Fix __ffa_devices_unregister Sudeep Holla
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Sudeep Holla @ 2021-09-24  9:28 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Sudeep Holla, Jens Wiklander, Arunachalam Ganapathy, Marc Bonnici

Currently the arm_ffa firmware driver can be built as module and hence
all the users of FFA driver. If any driver on the ffa bus is removed or
unregistered, the remove callback on all the device bound to the driver
being removed should be callback. For that to happen, we must register
a remove callback on the ffa_bus which is currently missing. This results
in the probe getting called again without the previous remove callback
on a device which may result in kernel crash.

Fix the issue by registering the remove callback on the FFA bus.

Fixes: e781858488b9 ("firmware: arm_ffa: Add initial FFA bus support for device enumeration")
Reported-by: Jens Wiklander <jens.wiklander@linaro.org>
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
---
 drivers/firmware/arm_ffa/bus.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/firmware/arm_ffa/bus.c b/drivers/firmware/arm_ffa/bus.c
index 00fe595a5bc8..f01348e6cf1c 100644
--- a/drivers/firmware/arm_ffa/bus.c
+++ b/drivers/firmware/arm_ffa/bus.c
@@ -49,6 +49,13 @@ static int ffa_device_probe(struct device *dev)
 	return ffa_drv->probe(ffa_dev);
 }

+static void ffa_device_remove(struct device *dev)
+{
+	struct ffa_driver *ffa_drv = to_ffa_driver(dev->driver);
+
+	ffa_drv->remove(to_ffa_dev(dev));
+}
+
 static int ffa_device_uevent(struct device *dev, struct kobj_uevent_env *env)
 {
 	struct ffa_device *ffa_dev = to_ffa_dev(dev);
@@ -86,6 +93,7 @@ struct bus_type ffa_bus_type = {
 	.name		= "arm_ffa",
 	.match		= ffa_device_match,
 	.probe		= ffa_device_probe,
+	.remove		= ffa_device_remove,
 	.uevent		= ffa_device_uevent,
 	.dev_groups	= ffa_device_attributes_groups,
 };
--
2.25.1


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

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

* [PATCH 2/2] firmware: arm_ffa: Fix __ffa_devices_unregister
  2021-09-24  9:28 [PATCH 1/2] firmware: arm_ffa: Add missing remove callback to ffa_bus_type Sudeep Holla
@ 2021-09-24  9:28 ` Sudeep Holla
  2021-10-04 10:08   ` Jens Wiklander
  2021-10-04 10:09 ` [PATCH 1/2] firmware: arm_ffa: Add missing remove callback to ffa_bus_type Jens Wiklander
  2021-10-05  9:42 ` Sudeep Holla
  2 siblings, 1 reply; 5+ messages in thread
From: Sudeep Holla @ 2021-09-24  9:28 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Sudeep Holla, Jens Wiklander, Arunachalam Ganapathy, Marc Bonnici

When arm_ffa firmware driver module is unloaded or removed we call
__ffa_devices_unregister on all the devices on the ffa bus. It must
unregister all the devices instead it is currently just releasing the
devices without unregistering. That is pure wrong as when we try to
load the module back again, it will result in the kernel crash something
like below.

-->8
 CPU: 2 PID: 232 Comm: modprobe Not tainted 5.15.0-rc2+ #169
 Hardware name: FVP Base RevC (DT)
 Call trace:
  dump_backtrace+0x0/0x1cc
  show_stack+0x18/0x64
  dump_stack_lvl+0x64/0x7c
  dump_stack+0x18/0x38
  sysfs_create_dir_ns+0xe4/0x140
  kobject_add_internal+0x170/0x358
  kobject_add+0x94/0x100
  device_add+0x178/0x5f0
  device_register+0x20/0x30
  ffa_device_register+0x80/0xcc [ffa_module]
  ffa_setup_partitions+0x7c/0x108 [ffa_module]
  init_module+0x290/0x2dc [ffa_module]
  do_one_initcall+0xbc/0x230
  do_init_module+0x58/0x304
  load_module+0x15e0/0x1f68
  __arm64_sys_finit_module+0xb8/0xf4
  invoke_syscall+0x44/0x140
  el0_svc_common+0xb4/0xf0
  do_el0_svc+0x24/0x80
  el0_svc+0x20/0x50
  el0t_64_sync_handler+0x84/0xe4
  el0t_64_sync+0x1a0/0x1a4
 kobject_add_internal failed for arm-ffa-8001 with -EEXIST, don't try to
 register things with the same name in the same directory.
----

Fix the issue by calling device_unregister in __ffa_devices_unregister
which will also take care of calling device_release(which is mapped to
ffa_release_device)

Fixes: e781858488b9 ("firmware: arm_ffa: Add initial FFA bus support for device enumeration")
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
---
 drivers/firmware/arm_ffa/bus.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/firmware/arm_ffa/bus.c b/drivers/firmware/arm_ffa/bus.c
index f01348e6cf1c..641a91819088 100644
--- a/drivers/firmware/arm_ffa/bus.c
+++ b/drivers/firmware/arm_ffa/bus.c
@@ -135,7 +135,7 @@ static void ffa_release_device(struct device *dev)

 static int __ffa_devices_unregister(struct device *dev, void *data)
 {
-	ffa_release_device(dev);
+	device_unregister(dev);

 	return 0;
 }
--
2.25.1


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

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

* Re: [PATCH 2/2] firmware: arm_ffa: Fix __ffa_devices_unregister
  2021-09-24  9:28 ` [PATCH 2/2] firmware: arm_ffa: Fix __ffa_devices_unregister Sudeep Holla
@ 2021-10-04 10:08   ` Jens Wiklander
  0 siblings, 0 replies; 5+ messages in thread
From: Jens Wiklander @ 2021-10-04 10:08 UTC (permalink / raw)
  To: Sudeep Holla; +Cc: Linux ARM, Arunachalam Ganapathy, Marc Bonnici

On Fri, Sep 24, 2021 at 11:29 AM Sudeep Holla <sudeep.holla@arm.com> wrote:
>
> When arm_ffa firmware driver module is unloaded or removed we call
> __ffa_devices_unregister on all the devices on the ffa bus. It must
> unregister all the devices instead it is currently just releasing the
> devices without unregistering. That is pure wrong as when we try to
> load the module back again, it will result in the kernel crash something
> like below.
>
> -->8
>  CPU: 2 PID: 232 Comm: modprobe Not tainted 5.15.0-rc2+ #169
>  Hardware name: FVP Base RevC (DT)
>  Call trace:
>   dump_backtrace+0x0/0x1cc
>   show_stack+0x18/0x64
>   dump_stack_lvl+0x64/0x7c
>   dump_stack+0x18/0x38
>   sysfs_create_dir_ns+0xe4/0x140
>   kobject_add_internal+0x170/0x358
>   kobject_add+0x94/0x100
>   device_add+0x178/0x5f0
>   device_register+0x20/0x30
>   ffa_device_register+0x80/0xcc [ffa_module]
>   ffa_setup_partitions+0x7c/0x108 [ffa_module]
>   init_module+0x290/0x2dc [ffa_module]
>   do_one_initcall+0xbc/0x230
>   do_init_module+0x58/0x304
>   load_module+0x15e0/0x1f68
>   __arm64_sys_finit_module+0xb8/0xf4
>   invoke_syscall+0x44/0x140
>   el0_svc_common+0xb4/0xf0
>   do_el0_svc+0x24/0x80
>   el0_svc+0x20/0x50
>   el0t_64_sync_handler+0x84/0xe4
>   el0t_64_sync+0x1a0/0x1a4
>  kobject_add_internal failed for arm-ffa-8001 with -EEXIST, don't try to
>  register things with the same name in the same directory.
> ----
>
> Fix the issue by calling device_unregister in __ffa_devices_unregister
> which will also take care of calling device_release(which is mapped to
> ffa_release_device)
>
> Fixes: e781858488b9 ("firmware: arm_ffa: Add initial FFA bus support for device enumeration")
> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
> ---
>  drivers/firmware/arm_ffa/bus.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>

Tested-by: Jens Wiklander <jens.wiklander@linaro.org>

> diff --git a/drivers/firmware/arm_ffa/bus.c b/drivers/firmware/arm_ffa/bus.c
> index f01348e6cf1c..641a91819088 100644
> --- a/drivers/firmware/arm_ffa/bus.c
> +++ b/drivers/firmware/arm_ffa/bus.c
> @@ -135,7 +135,7 @@ static void ffa_release_device(struct device *dev)
>
>  static int __ffa_devices_unregister(struct device *dev, void *data)
>  {
> -       ffa_release_device(dev);
> +       device_unregister(dev);
>
>         return 0;
>  }
> --
> 2.25.1
>

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

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

* Re: [PATCH 1/2] firmware: arm_ffa: Add missing remove callback to ffa_bus_type
  2021-09-24  9:28 [PATCH 1/2] firmware: arm_ffa: Add missing remove callback to ffa_bus_type Sudeep Holla
  2021-09-24  9:28 ` [PATCH 2/2] firmware: arm_ffa: Fix __ffa_devices_unregister Sudeep Holla
@ 2021-10-04 10:09 ` Jens Wiklander
  2021-10-05  9:42 ` Sudeep Holla
  2 siblings, 0 replies; 5+ messages in thread
From: Jens Wiklander @ 2021-10-04 10:09 UTC (permalink / raw)
  To: Sudeep Holla; +Cc: Linux ARM, Arunachalam Ganapathy, Marc Bonnici

On Fri, Sep 24, 2021 at 11:29 AM Sudeep Holla <sudeep.holla@arm.com> wrote:
>
> Currently the arm_ffa firmware driver can be built as module and hence
> all the users of FFA driver. If any driver on the ffa bus is removed or
> unregistered, the remove callback on all the device bound to the driver
> being removed should be callback. For that to happen, we must register
> a remove callback on the ffa_bus which is currently missing. This results
> in the probe getting called again without the previous remove callback
> on a device which may result in kernel crash.
>
> Fix the issue by registering the remove callback on the FFA bus.
>
> Fixes: e781858488b9 ("firmware: arm_ffa: Add initial FFA bus support for device enumeration")
> Reported-by: Jens Wiklander <jens.wiklander@linaro.org>
> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
> ---
>  drivers/firmware/arm_ffa/bus.c | 8 ++++++++
>  1 file changed, 8 insertions(+)

Tested-by: Jens Wiklander <jens.wiklander@linaro.org>

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

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

* Re: [PATCH 1/2] firmware: arm_ffa: Add missing remove callback to ffa_bus_type
  2021-09-24  9:28 [PATCH 1/2] firmware: arm_ffa: Add missing remove callback to ffa_bus_type Sudeep Holla
  2021-09-24  9:28 ` [PATCH 2/2] firmware: arm_ffa: Fix __ffa_devices_unregister Sudeep Holla
  2021-10-04 10:09 ` [PATCH 1/2] firmware: arm_ffa: Add missing remove callback to ffa_bus_type Jens Wiklander
@ 2021-10-05  9:42 ` Sudeep Holla
  2 siblings, 0 replies; 5+ messages in thread
From: Sudeep Holla @ 2021-10-05  9:42 UTC (permalink / raw)
  To: linux-arm-kernel, Sudeep Holla
  Cc: Marc Bonnici, Arunachalam Ganapathy, Jens Wiklander

On Fri, 24 Sep 2021 10:28:58 +0100, Sudeep Holla wrote:
> Currently the arm_ffa firmware driver can be built as module and hence
> all the users of FFA driver. If any driver on the ffa bus is removed or
> unregistered, the remove callback on all the device bound to the driver
> being removed should be callback. For that to happen, we must register
> a remove callback on the ffa_bus which is currently missing. This results
> in the probe getting called again without the previous remove callback
> on a device which may result in kernel crash.
> 
> [...]


Applied to sudeep.holla/linux (for-next/ffa), thanks!




[1/2] firmware: arm_ffa: Add missing remove callback to ffa_bus_type
      https://git.kernel.org/sudeep.holla/c/244f5d597e
[2/2] firmware: arm_ffa: Fix __ffa_devices_unregister
      https://git.kernel.org/sudeep.holla/c/eb7b52e6db

--

Regards,
Sudeep


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

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

end of thread, other threads:[~2021-10-05  9:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-24  9:28 [PATCH 1/2] firmware: arm_ffa: Add missing remove callback to ffa_bus_type Sudeep Holla
2021-09-24  9:28 ` [PATCH 2/2] firmware: arm_ffa: Fix __ffa_devices_unregister Sudeep Holla
2021-10-04 10:08   ` Jens Wiklander
2021-10-04 10:09 ` [PATCH 1/2] firmware: arm_ffa: Add missing remove callback to ffa_bus_type Jens Wiklander
2021-10-05  9:42 ` Sudeep Holla

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.