* [PATCH 0/2] Introduce helpers for carveout management
@ 2022-06-10 19:23 Chris Lew
2022-06-10 19:23 ` [PATCH 1/2] remoteproc: core: Introduce rproc_del_carveout Chris Lew
2022-06-10 19:23 ` [PATCH 2/2] remoteproc: core: Introduce rproc_mem_entry_free Chris Lew
0 siblings, 2 replies; 6+ messages in thread
From: Chris Lew @ 2022-06-10 19:23 UTC (permalink / raw)
To: bjorn.andersson, mathieu.poirier
Cc: linux-remoteproc, linux-arm-msm, linux-kernel, quic_clew
Currently remoteproc exposes APIs for devices outside of remoteproc
to allocate and add carveout resources to a remoteproc. These devices
may support the ability to reclaim these resources from a live
remoteproc. Add two helpers to help cleanup the references to the
carveout resources.
Chris Lew (2):
remoteproc: core: Introduce rproc_del_carveout
remoteproc: core: Introduce rproc_mem_entry_free
drivers/remoteproc/remoteproc_core.c | 33 +++++++++++++++++++++++++++++++++
include/linux/remoteproc.h | 2 ++
2 files changed, 35 insertions(+)
--
2.7.4
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] remoteproc: core: Introduce rproc_del_carveout
2022-06-10 19:23 [PATCH 0/2] Introduce helpers for carveout management Chris Lew
@ 2022-06-10 19:23 ` Chris Lew
2022-06-30 16:36 ` Arnaud POULIQUEN
2022-06-10 19:23 ` [PATCH 2/2] remoteproc: core: Introduce rproc_mem_entry_free Chris Lew
1 sibling, 1 reply; 6+ messages in thread
From: Chris Lew @ 2022-06-10 19:23 UTC (permalink / raw)
To: bjorn.andersson, mathieu.poirier
Cc: linux-remoteproc, linux-arm-msm, linux-kernel, quic_clew
To mirror the exported rproc_add_carveout(), add a rproc_del_carveout()
so memory carveout resources added by devices outside of remoteproc can
manage the resource lifetime more accurately.
Signed-off-by: Chris Lew <quic_clew@quicinc.com>
---
drivers/remoteproc/remoteproc_core.c | 20 ++++++++++++++++++++
include/linux/remoteproc.h | 1 +
2 files changed, 21 insertions(+)
diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index 02a04ab34a23..ee71fccae970 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -1001,6 +1001,26 @@ void rproc_add_carveout(struct rproc *rproc, struct rproc_mem_entry *mem)
EXPORT_SYMBOL(rproc_add_carveout);
/**
+ * rproc_del_carveout() - remove an allocated carveout region
+ * @rproc: rproc handle
+ * @mem: memory entry to register
+ *
+ * This function removes specified memory entry in @rproc carveouts list.
+ */
+void rproc_del_carveout(struct rproc *rproc, struct rproc_mem_entry *mem)
+{
+ struct rproc_mem_entry *entry, *tmp;
+
+ list_for_each_entry_safe(entry, tmp, &rproc->carveouts, node) {
+ if (entry == mem) {
+ list_del(&mem->node);
+ return;
+ }
+ }
+}
+EXPORT_SYMBOL(rproc_del_carveout);
+
+/**
* rproc_mem_entry_init() - allocate and initialize rproc_mem_entry struct
* @dev: pointer on device struct
* @va: virtual address
diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
index 7c943f0a2fc4..43112aa78ffe 100644
--- a/include/linux/remoteproc.h
+++ b/include/linux/remoteproc.h
@@ -658,6 +658,7 @@ struct rproc *devm_rproc_alloc(struct device *dev, const char *name,
int devm_rproc_add(struct device *dev, struct rproc *rproc);
void rproc_add_carveout(struct rproc *rproc, struct rproc_mem_entry *mem);
+void rproc_del_carveout(struct rproc *rproc, struct rproc_mem_entry *mem);
struct rproc_mem_entry *
rproc_mem_entry_init(struct device *dev,
--
2.7.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] remoteproc: core: Introduce rproc_mem_entry_free
2022-06-10 19:23 [PATCH 0/2] Introduce helpers for carveout management Chris Lew
2022-06-10 19:23 ` [PATCH 1/2] remoteproc: core: Introduce rproc_del_carveout Chris Lew
@ 2022-06-10 19:23 ` Chris Lew
2022-06-30 16:38 ` Arnaud POULIQUEN
1 sibling, 1 reply; 6+ messages in thread
From: Chris Lew @ 2022-06-10 19:23 UTC (permalink / raw)
To: bjorn.andersson, mathieu.poirier
Cc: linux-remoteproc, linux-arm-msm, linux-kernel, quic_clew
Introduce a helper to free the rproc_mem_entry allocated by
rproc_mem_entry_init(). This helper is to help manage rproc carveouts
added to an rproc outside of remoteproc.
Signed-off-by: Chris Lew <quic_clew@quicinc.com>
---
drivers/remoteproc/remoteproc_core.c | 13 +++++++++++++
include/linux/remoteproc.h | 1 +
2 files changed, 14 insertions(+)
diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index ee71fccae970..161691fd2e96 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -1069,6 +1069,19 @@ rproc_mem_entry_init(struct device *dev,
EXPORT_SYMBOL(rproc_mem_entry_init);
/**
+ * rproc_mem_entry_free() - free a rproc_mem_entry struct
+ * @mem: rproc_mem_entry allocated by rproc_mem_entry_init()
+ *
+ * This function frees a rproc_mem_entry_struct that was allocated by
+ * rproc_mem_entry_init().
+ */
+void rproc_mem_entry_free(struct rproc_mem_entry *mem)
+{
+ kfree(mem);
+}
+EXPORT_SYMBOL(rproc_mem_entry_free);
+
+/**
* rproc_of_resm_mem_entry_init() - allocate and initialize rproc_mem_entry struct
* from a reserved memory phandle
* @dev: pointer on device struct
diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
index 43112aa78ffe..9b039f37da12 100644
--- a/include/linux/remoteproc.h
+++ b/include/linux/remoteproc.h
@@ -666,6 +666,7 @@ rproc_mem_entry_init(struct device *dev,
int (*alloc)(struct rproc *, struct rproc_mem_entry *),
int (*release)(struct rproc *, struct rproc_mem_entry *),
const char *name, ...);
+void rproc_mem_entry_free(struct rproc_mem_entry *mem);
struct rproc_mem_entry *
rproc_of_resm_mem_entry_init(struct device *dev, u32 of_resm_idx, size_t len,
--
2.7.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] remoteproc: core: Introduce rproc_del_carveout
2022-06-10 19:23 ` [PATCH 1/2] remoteproc: core: Introduce rproc_del_carveout Chris Lew
@ 2022-06-30 16:36 ` Arnaud POULIQUEN
2022-07-06 4:57 ` Chris Lew
0 siblings, 1 reply; 6+ messages in thread
From: Arnaud POULIQUEN @ 2022-06-30 16:36 UTC (permalink / raw)
To: Chris Lew, bjorn.andersson, mathieu.poirier
Cc: linux-remoteproc, linux-arm-msm, linux-kernel
Hi,
On 6/10/22 21:23, Chris Lew wrote:
> To mirror the exported rproc_add_carveout(), add a rproc_del_carveout()
> so memory carveout resources added by devices outside of remoteproc can
> manage the resource lifetime more accurately.
>
> Signed-off-by: Chris Lew <quic_clew@quicinc.com>
> ---
> drivers/remoteproc/remoteproc_core.c | 20 ++++++++++++++++++++
> include/linux/remoteproc.h | 1 +
> 2 files changed, 21 insertions(+)
>
> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> index 02a04ab34a23..ee71fccae970 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -1001,6 +1001,26 @@ void rproc_add_carveout(struct rproc *rproc, struct rproc_mem_entry *mem)
> EXPORT_SYMBOL(rproc_add_carveout);
>
> /**
> + * rproc_del_carveout() - remove an allocated carveout region
> + * @rproc: rproc handle
> + * @mem: memory entry to register
> + *
> + * This function removes specified memory entry in @rproc carveouts list.
> + */
> +void rproc_del_carveout(struct rproc *rproc, struct rproc_mem_entry *mem)
> +{
> + struct rproc_mem_entry *entry, *tmp;
> +
> + list_for_each_entry_safe(entry, tmp, &rproc->carveouts, node) {
> + if (entry == mem) {
> + list_del(&mem->node);
> + return;
> + }
> + }
> +}
> +EXPORT_SYMBOL(rproc_del_carveout);
This API seems to me quite dangerous because it can be called while carveouts are in use.
At least some checks should be added...
What about using rproc_resource_cleanup instead?
Regards,
Arnaud
> +
> +/**
> * rproc_mem_entry_init() - allocate and initialize rproc_mem_entry struct
> * @dev: pointer on device struct
> * @va: virtual address
> diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
> index 7c943f0a2fc4..43112aa78ffe 100644
> --- a/include/linux/remoteproc.h
> +++ b/include/linux/remoteproc.h
> @@ -658,6 +658,7 @@ struct rproc *devm_rproc_alloc(struct device *dev, const char *name,
> int devm_rproc_add(struct device *dev, struct rproc *rproc);
>
> void rproc_add_carveout(struct rproc *rproc, struct rproc_mem_entry *mem);
> +void rproc_del_carveout(struct rproc *rproc, struct rproc_mem_entry *mem);
>
> struct rproc_mem_entry *
> rproc_mem_entry_init(struct device *dev,
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] remoteproc: core: Introduce rproc_mem_entry_free
2022-06-10 19:23 ` [PATCH 2/2] remoteproc: core: Introduce rproc_mem_entry_free Chris Lew
@ 2022-06-30 16:38 ` Arnaud POULIQUEN
0 siblings, 0 replies; 6+ messages in thread
From: Arnaud POULIQUEN @ 2022-06-30 16:38 UTC (permalink / raw)
To: Chris Lew, bjorn.andersson, mathieu.poirier
Cc: linux-remoteproc, linux-arm-msm, linux-kernel
On 6/10/22 21:23, Chris Lew wrote:
> Introduce a helper to free the rproc_mem_entry allocated by
> rproc_mem_entry_init(). This helper is to help manage rproc carveouts
> added to an rproc outside of remoteproc.
>
> Signed-off-by: Chris Lew <quic_clew@quicinc.com>
> ---
> drivers/remoteproc/remoteproc_core.c | 13 +++++++++++++
> include/linux/remoteproc.h | 1 +
> 2 files changed, 14 insertions(+)
>
> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> index ee71fccae970..161691fd2e96 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -1069,6 +1069,19 @@ rproc_mem_entry_init(struct device *dev,
> EXPORT_SYMBOL(rproc_mem_entry_init);
>
> /**
> + * rproc_mem_entry_free() - free a rproc_mem_entry struct
> + * @mem: rproc_mem_entry allocated by rproc_mem_entry_init()
> + *
> + * This function frees a rproc_mem_entry_struct that was allocated by
> + * rproc_mem_entry_init().
> + */
> +void rproc_mem_entry_free(struct rproc_mem_entry *mem)
> +{
> + kfree(mem);
> +}
> +EXPORT_SYMBOL(rproc_mem_entry_free);
Same concerns for this one.
> +
> +/**
> * rproc_of_resm_mem_entry_init() - allocate and initialize rproc_mem_entry struct
> * from a reserved memory phandle
> * @dev: pointer on device struct
> diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
> index 43112aa78ffe..9b039f37da12 100644
> --- a/include/linux/remoteproc.h
> +++ b/include/linux/remoteproc.h
> @@ -666,6 +666,7 @@ rproc_mem_entry_init(struct device *dev,
> int (*alloc)(struct rproc *, struct rproc_mem_entry *),
> int (*release)(struct rproc *, struct rproc_mem_entry *),
> const char *name, ...);
> +void rproc_mem_entry_free(struct rproc_mem_entry *mem);
>
> struct rproc_mem_entry *
> rproc_of_resm_mem_entry_init(struct device *dev, u32 of_resm_idx, size_t len,
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] remoteproc: core: Introduce rproc_del_carveout
2022-06-30 16:36 ` Arnaud POULIQUEN
@ 2022-07-06 4:57 ` Chris Lew
0 siblings, 0 replies; 6+ messages in thread
From: Chris Lew @ 2022-07-06 4:57 UTC (permalink / raw)
To: Arnaud POULIQUEN, bjorn.andersson, mathieu.poirier
Cc: linux-remoteproc, linux-arm-msm, linux-kernel
On 6/30/2022 9:36 AM, Arnaud POULIQUEN wrote:
> Hi,
>
> On 6/10/22 21:23, Chris Lew wrote:
>> To mirror the exported rproc_add_carveout(), add a rproc_del_carveout()
>> so memory carveout resources added by devices outside of remoteproc can
>> manage the resource lifetime more accurately.
>>
>> Signed-off-by: Chris Lew <quic_clew@quicinc.com>
>> ---
>> drivers/remoteproc/remoteproc_core.c | 20 ++++++++++++++++++++
>> include/linux/remoteproc.h | 1 +
>> 2 files changed, 21 insertions(+)
>>
>> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
>> index 02a04ab34a23..ee71fccae970 100644
>> --- a/drivers/remoteproc/remoteproc_core.c
>> +++ b/drivers/remoteproc/remoteproc_core.c
>> @@ -1001,6 +1001,26 @@ void rproc_add_carveout(struct rproc *rproc, struct rproc_mem_entry *mem)
>> EXPORT_SYMBOL(rproc_add_carveout);
>>
>> /**
>> + * rproc_del_carveout() - remove an allocated carveout region
>> + * @rproc: rproc handle
>> + * @mem: memory entry to register
>> + *
>> + * This function removes specified memory entry in @rproc carveouts list.
>> + */
>> +void rproc_del_carveout(struct rproc *rproc, struct rproc_mem_entry *mem)
>> +{
>> + struct rproc_mem_entry *entry, *tmp;
>> +
>> + list_for_each_entry_safe(entry, tmp, &rproc->carveouts, node) {
>> + if (entry == mem) {
>> + list_del(&mem->node);
>> + return;
>> + }
>> + }
>> +}
>> +EXPORT_SYMBOL(rproc_del_carveout);
>
> This API seems to me quite dangerous because it can be called while carveouts are in use.
> At least some checks should be added...
>
> What about using rproc_resource_cleanup instead?
>
> Regards,
> Arnaud
>
The intended users of this API would be devices who negotiate with the
device and know when the carveouts it has added are in use or can be
reclaimed. I had looked at rproc_resource_cleanup() and that seemed more
like a blanket cleanup rather than being able to cleanup a specific
carveout.
I agree the API seems dangerous, but I wasn't quite sure what kind of
checks could be put here since remoteproc itself doesn't have any
mechanisms to monitor the carveout state itself. We're relying on the
fact that the device who added the carveout shouldn't make any mistakes
which is fairly fragile.
Thanks!
Chris
>> +
>> +/**
>> * rproc_mem_entry_init() - allocate and initialize rproc_mem_entry struct
>> * @dev: pointer on device struct
>> * @va: virtual address
>> diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
>> index 7c943f0a2fc4..43112aa78ffe 100644
>> --- a/include/linux/remoteproc.h
>> +++ b/include/linux/remoteproc.h
>> @@ -658,6 +658,7 @@ struct rproc *devm_rproc_alloc(struct device *dev, const char *name,
>> int devm_rproc_add(struct device *dev, struct rproc *rproc);
>>
>> void rproc_add_carveout(struct rproc *rproc, struct rproc_mem_entry *mem);
>> +void rproc_del_carveout(struct rproc *rproc, struct rproc_mem_entry *mem);
>>
>> struct rproc_mem_entry *
>> rproc_mem_entry_init(struct device *dev,
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-07-06 4:58 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-10 19:23 [PATCH 0/2] Introduce helpers for carveout management Chris Lew
2022-06-10 19:23 ` [PATCH 1/2] remoteproc: core: Introduce rproc_del_carveout Chris Lew
2022-06-30 16:36 ` Arnaud POULIQUEN
2022-07-06 4:57 ` Chris Lew
2022-06-10 19:23 ` [PATCH 2/2] remoteproc: core: Introduce rproc_mem_entry_free Chris Lew
2022-06-30 16:38 ` Arnaud POULIQUEN
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).