2020-07-29 17:43:09

by Siddharth Gupta

[permalink] [raw]
Subject: [PATCH v5 0/2] Add character device interface to remoteproc

This patch series adds a character device interface to remoteproc
framework. Currently there is only a sysfs interface which the userspace
clients can use. If a usersapce application crashes after booting
the remote processor through the sysfs interface the remote processor
does not get any indication about the crash. It might still assume
that the application is running.
For example modem uses remotefs service to data from disk/flash memory.
If the remotefs service crashes, modem still keeps on requesting data
which might lead to crash on modem. Even if the service is restarted the
file handles modem requested previously would become stale.
Adding a character device interface makes the remote processor tightly
coupled with the user space application. A crash of the application
leads to a close on the file descriptors therefore shutting down the
remoteproc.

Changelog:
v4 -> v5:
- Addressed comments from Bjorn and Mathieu.
- Added cdev_set_parent call to set remoteproc device as parent of cdev.
- Fixed error with rproc_major introduced in the last patch.
- Fixed implementation for compat calls. With previous implementation 64bit
userspace applications failed to perform the ioctl call, returning errno 25,
or "Inappropriate ioctl for device."
- Removed exit functions from the driver as remoteproc framework is statically
compiled.

v3 -> v4:
- Addressed comments from Mathieu and Arnaud.
- Added locks while writing/reading from the automatic-shutdown-on-release bool.
- Changed return value when failing to copy to/from userspace.
- Changed logic for calling shutdown on release.
- Moved around code after the increase of max line length from 80 to 100.
- Moved the call adding character device before device_add in rproc_add to add
both sysfs and character device interface together.

v2 -> v3:
- Move booting of remoteproc from open to a write call.
- Add ioctl interface for future functionality extension.
- Add an ioctl call to default to rproc shutdown on release.

v1 -> v2:
- Fixed comments from Bjorn and Matthew.

Siddharth Gupta (2):
remoteproc: Add remoteproc character device interface
remoteproc: core: Register the character device interface

Documentation/userspace-api/ioctl/ioctl-number.rst | 1 +
drivers/remoteproc/Kconfig | 9 ++
drivers/remoteproc/Makefile | 1 +
drivers/remoteproc/remoteproc_cdev.c | 124 +++++++++++++++++++++
drivers/remoteproc/remoteproc_core.c | 7 ++
drivers/remoteproc/remoteproc_internal.h | 28 +++++
include/linux/remoteproc.h | 5 +
include/uapi/linux/remoteproc_cdev.h | 37 ++++++
8 files changed, 212 insertions(+)
create mode 100644 drivers/remoteproc/remoteproc_cdev.c
create mode 100644 include/uapi/linux/remoteproc_cdev.h

--
Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


2020-07-29 17:43:37

by Siddharth Gupta

[permalink] [raw]
Subject: [PATCH v5 2/2] remoteproc: core: Register the character device interface

Add the character device during rproc_add. This would create
a character device node at /dev/remoteproc<index>. Userspace
applications can interact with the remote processor using this
interface.

Signed-off-by: Rishabh Bhatnagar <[email protected]>
Signed-off-by: Siddharth Gupta <[email protected]>
---
drivers/remoteproc/remoteproc_core.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index 277d3bf..7f90eee 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -1986,6 +1986,11 @@ int rproc_add(struct rproc *rproc)
/* create debugfs entries */
rproc_create_debug_dir(rproc);

+ /* add char device for this remoteproc */
+ ret = rproc_char_device_add(rproc);
+ if (ret < 0)
+ return ret;
+
/*
* Remind ourselves the remote processor has been attached to rather
* than booted by the remoteproc core. This is important because the
@@ -2262,6 +2267,7 @@ int rproc_del(struct rproc *rproc)
mutex_unlock(&rproc->lock);

rproc_delete_debug_dir(rproc);
+ rproc_char_device_remove(rproc);

/* the rproc is downref'ed as soon as it's removed from the klist */
mutex_lock(&rproc_list_mutex);
@@ -2430,6 +2436,7 @@ static int __init remoteproc_init(void)
{
rproc_init_sysfs();
rproc_init_debugfs();
+ rproc_init_cdev();
rproc_init_panic();

return 0;
--
Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

2020-07-29 19:23:44

by Bjorn Andersson

[permalink] [raw]
Subject: Re: [PATCH v5 2/2] remoteproc: core: Register the character device interface

On Wed 29 Jul 10:40 PDT 2020, Siddharth Gupta wrote:

> Add the character device during rproc_add. This would create
> a character device node at /dev/remoteproc<index>. Userspace
> applications can interact with the remote processor using this
> interface.
>

Reviewed-by: Bjorn Andersson <[email protected]>

> Signed-off-by: Rishabh Bhatnagar <[email protected]>
> Signed-off-by: Siddharth Gupta <[email protected]>
> ---
> drivers/remoteproc/remoteproc_core.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> index 277d3bf..7f90eee 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -1986,6 +1986,11 @@ int rproc_add(struct rproc *rproc)
> /* create debugfs entries */
> rproc_create_debug_dir(rproc);
>
> + /* add char device for this remoteproc */
> + ret = rproc_char_device_add(rproc);
> + if (ret < 0)
> + return ret;
> +
> /*
> * Remind ourselves the remote processor has been attached to rather
> * than booted by the remoteproc core. This is important because the
> @@ -2262,6 +2267,7 @@ int rproc_del(struct rproc *rproc)
> mutex_unlock(&rproc->lock);
>
> rproc_delete_debug_dir(rproc);
> + rproc_char_device_remove(rproc);
>
> /* the rproc is downref'ed as soon as it's removed from the klist */
> mutex_lock(&rproc_list_mutex);
> @@ -2430,6 +2436,7 @@ static int __init remoteproc_init(void)
> {
> rproc_init_sysfs();
> rproc_init_debugfs();
> + rproc_init_cdev();
> rproc_init_panic();
>
> return 0;
> --
> Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
>

2020-07-30 17:08:34

by Mathieu Poirier

[permalink] [raw]
Subject: Re: [PATCH v5 2/2] remoteproc: core: Register the character device interface

On Wed, Jul 29, 2020 at 10:40:01AM -0700, Siddharth Gupta wrote:
> Add the character device during rproc_add. This would create
> a character device node at /dev/remoteproc<index>. Userspace
> applications can interact with the remote processor using this
> interface.
>
> Signed-off-by: Rishabh Bhatnagar <[email protected]>
> Signed-off-by: Siddharth Gupta <[email protected]>

Reviewed-by: Mathieu Poirier <[email protected]>

> ---
> drivers/remoteproc/remoteproc_core.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> index 277d3bf..7f90eee 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -1986,6 +1986,11 @@ int rproc_add(struct rproc *rproc)
> /* create debugfs entries */
> rproc_create_debug_dir(rproc);
>
> + /* add char device for this remoteproc */
> + ret = rproc_char_device_add(rproc);
> + if (ret < 0)
> + return ret;
> +
> /*
> * Remind ourselves the remote processor has been attached to rather
> * than booted by the remoteproc core. This is important because the
> @@ -2262,6 +2267,7 @@ int rproc_del(struct rproc *rproc)
> mutex_unlock(&rproc->lock);
>
> rproc_delete_debug_dir(rproc);
> + rproc_char_device_remove(rproc);
>
> /* the rproc is downref'ed as soon as it's removed from the klist */
> mutex_lock(&rproc_list_mutex);
> @@ -2430,6 +2436,7 @@ static int __init remoteproc_init(void)
> {
> rproc_init_sysfs();
> rproc_init_debugfs();
> + rproc_init_cdev();
> rproc_init_panic();
>
> return 0;
> --
> Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
>