All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] firmware: arm_ffa: Add support for MEM_LEND
@ 2021-10-07 17:44 Marc Bonnici
  2021-10-08  7:48 ` Jens Wiklander
  0 siblings, 1 reply; 3+ messages in thread
From: Marc Bonnici @ 2021-10-07 17:44 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Achin Gupta, Jens Wiklander, Arunachalam Ganapathy, Marc Bonnici,
	Sudeep Holla, Coboy Chen, Lukas Hanel, Lionel Pacoud

As part of the FF-A spec, an endpoint is allowed to
transfer access of, or lend, a memory region to one
or more borrowers.

Extend the existing memory sharing implementation to
support FF-A MEM_LEND functionality and expose this
to other kernel drivers.

Signed-off-by: Marc Bonnici <marc.bonnici@arm.com>
---
 drivers/firmware/arm_ffa/driver.c | 10 ++++++++++
 include/linux/arm_ffa.h           |  2 ++
 2 files changed, 12 insertions(+)

diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c
index 6e0c883ab708..41661ae4ee04 100644
--- a/drivers/firmware/arm_ffa/driver.c
+++ b/drivers/firmware/arm_ffa/driver.c
@@ -613,6 +613,15 @@ ffa_memory_share(struct ffa_device *dev, struct ffa_mem_ops_args *args)
 	return ffa_memory_ops(FFA_FN_NATIVE(MEM_SHARE), args);
 }
 
+static int
+ffa_memory_lend(struct ffa_device *dev, struct ffa_mem_ops_args *args)
+{
+	if (dev->mode_32bit)
+		return ffa_memory_ops(FFA_MEM_LEND, args);
+
+	return ffa_memory_ops(FFA_FN_NATIVE(MEM_LEND), args);
+}
+
 static const struct ffa_dev_ops ffa_ops = {
 	.api_version_get = ffa_api_version_get,
 	.partition_info_get = ffa_partition_info_get,
@@ -620,6 +629,7 @@ static const struct ffa_dev_ops ffa_ops = {
 	.sync_send_receive = ffa_sync_send_receive,
 	.memory_reclaim = ffa_memory_reclaim,
 	.memory_share = ffa_memory_share,
+	.memory_lend = ffa_memory_lend,
 };
 
 const struct ffa_dev_ops *ffa_dev_ops_get(struct ffa_device *dev)
diff --git a/include/linux/arm_ffa.h b/include/linux/arm_ffa.h
index 505c679b6a9b..85651e41ded8 100644
--- a/include/linux/arm_ffa.h
+++ b/include/linux/arm_ffa.h
@@ -262,6 +262,8 @@ struct ffa_dev_ops {
 	int (*memory_reclaim)(u64 g_handle, u32 flags);
 	int (*memory_share)(struct ffa_device *dev,
 			    struct ffa_mem_ops_args *args);
+	int (*memory_lend)(struct ffa_device *dev,
+			   struct ffa_mem_ops_args *args);
 };
 
 #endif /* _LINUX_ARM_FFA_H */
-- 
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] 3+ messages in thread

* Re: [PATCH] firmware: arm_ffa: Add support for MEM_LEND
  2021-10-07 17:44 [PATCH] firmware: arm_ffa: Add support for MEM_LEND Marc Bonnici
@ 2021-10-08  7:48 ` Jens Wiklander
  2021-10-11 10:26   ` Marc Bonnici
  0 siblings, 1 reply; 3+ messages in thread
From: Jens Wiklander @ 2021-10-08  7:48 UTC (permalink / raw)
  To: Marc Bonnici
  Cc: Linux ARM, Achin Gupta, Arunachalam Ganapathy, Sudeep Holla,
	Coboy Chen, Lukas Hanel, Lionel Pacoud

Hi Marc,

On Thu, Oct 7, 2021 at 7:44 PM Marc Bonnici <marc.bonnici@arm.com> wrote:
>
> As part of the FF-A spec, an endpoint is allowed to
> transfer access of, or lend, a memory region to one
> or more borrowers.
>
> Extend the existing memory sharing implementation to
> support FF-A MEM_LEND functionality and expose this
> to other kernel drivers.
>
> Signed-off-by: Marc Bonnici <marc.bonnici@arm.com>
> ---
>  drivers/firmware/arm_ffa/driver.c | 10 ++++++++++
>  include/linux/arm_ffa.h           |  2 ++
>  2 files changed, 12 insertions(+)

This is similar to MEM_SHARE, but with one significant difference, the
memory lent may become inaccessible by the kernel once this has
succeeded. In case there's no hypervisor in the system the
responsibility falls on the kernel itself to make sure that it will
keep off the lent memory. Even if it may not be the responsibility of
this driver to enforce this it might be worth a comment to help the
caller on the right track.

Cheers,
Jens

>
> diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c
> index 6e0c883ab708..41661ae4ee04 100644
> --- a/drivers/firmware/arm_ffa/driver.c
> +++ b/drivers/firmware/arm_ffa/driver.c
> @@ -613,6 +613,15 @@ ffa_memory_share(struct ffa_device *dev, struct ffa_mem_ops_args *args)
>         return ffa_memory_ops(FFA_FN_NATIVE(MEM_SHARE), args);
>  }
>
> +static int
> +ffa_memory_lend(struct ffa_device *dev, struct ffa_mem_ops_args *args)
> +{
> +       if (dev->mode_32bit)
> +               return ffa_memory_ops(FFA_MEM_LEND, args);
> +
> +       return ffa_memory_ops(FFA_FN_NATIVE(MEM_LEND), args);
> +}
> +
>  static const struct ffa_dev_ops ffa_ops = {
>         .api_version_get = ffa_api_version_get,
>         .partition_info_get = ffa_partition_info_get,
> @@ -620,6 +629,7 @@ static const struct ffa_dev_ops ffa_ops = {
>         .sync_send_receive = ffa_sync_send_receive,
>         .memory_reclaim = ffa_memory_reclaim,
>         .memory_share = ffa_memory_share,
> +       .memory_lend = ffa_memory_lend,
>  };
>
>  const struct ffa_dev_ops *ffa_dev_ops_get(struct ffa_device *dev)
> diff --git a/include/linux/arm_ffa.h b/include/linux/arm_ffa.h
> index 505c679b6a9b..85651e41ded8 100644
> --- a/include/linux/arm_ffa.h
> +++ b/include/linux/arm_ffa.h
> @@ -262,6 +262,8 @@ struct ffa_dev_ops {
>         int (*memory_reclaim)(u64 g_handle, u32 flags);
>         int (*memory_share)(struct ffa_device *dev,
>                             struct ffa_mem_ops_args *args);
> +       int (*memory_lend)(struct ffa_device *dev,
> +                          struct ffa_mem_ops_args *args);
>  };
>
>  #endif /* _LINUX_ARM_FFA_H */
> --
> 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] 3+ messages in thread

* RE: [PATCH] firmware: arm_ffa: Add support for MEM_LEND
  2021-10-08  7:48 ` Jens Wiklander
@ 2021-10-11 10:26   ` Marc Bonnici
  0 siblings, 0 replies; 3+ messages in thread
From: Marc Bonnici @ 2021-10-11 10:26 UTC (permalink / raw)
  To: Jens Wiklander, Sudeep Holla
  Cc: Linux ARM, Achin Gupta, Arunachalam Ganapathy, Coboy Chen,
	Lukas Hanel, Lionel Pacoud

Hi Jens,

> -----Original Message-----
> From: Jens Wiklander <jens.wiklander@linaro.org>
> Sent: 08 October 2021 08:49
> To: Marc Bonnici <Marc.Bonnici@arm.com>
> Cc: Linux ARM <linux-arm-kernel@lists.infradead.org>; Achin Gupta
> <Achin.Gupta@arm.com>; Arunachalam Ganapathy
> <Arunachalam.Ganapathy@arm.com>; Sudeep Holla <Sudeep.Holla@arm.com>;
> Coboy Chen <Coboy.Chen@mediatek.com>; Lukas Hanel
> <lukas.hanel@trustonic.com>; Lionel Pacoud
> <lionel.pacoud@trustonic.com>
> Subject: Re: [PATCH] firmware: arm_ffa: Add support for MEM_LEND
> 
> Hi Marc,
> 
> On Thu, Oct 7, 2021 at 7:44 PM Marc Bonnici <marc.bonnici@arm.com>
> wrote:
> >
> > As part of the FF-A spec, an endpoint is allowed to transfer
> access
> > of, or lend, a memory region to one or more borrowers.
> >
> > Extend the existing memory sharing implementation to support FF-A
> > MEM_LEND functionality and expose this to other kernel drivers.
> >
> > Signed-off-by: Marc Bonnici <marc.bonnici@arm.com>
> > ---
> >  drivers/firmware/arm_ffa/driver.c | 10 ++++++++++
> >  include/linux/arm_ffa.h           |  2 ++
> >  2 files changed, 12 insertions(+)
> 
> This is similar to MEM_SHARE, but with one significant difference,
> the memory lent may become inaccessible by the kernel once this has
> succeeded. In case there's no hypervisor in the system the
> responsibility falls on the kernel itself to make sure that it will
> keep off the lent memory. Even if it may not be the responsibility
> of this driver to enforce this it might be worth a comment to help
> the caller on the right track.
> 

Agreed, I don't think the responsibility itself should fall to this 
driver but a comment for a potential caller would certainly be useful,
shall update to include. 

Thanks,

Kind Regards
Marc Bonnici


> Cheers,
> Jens
> 
> >
> > diff --git a/drivers/firmware/arm_ffa/driver.c
> > b/drivers/firmware/arm_ffa/driver.c
> > index 6e0c883ab708..41661ae4ee04 100644
> > --- a/drivers/firmware/arm_ffa/driver.c
> > +++ b/drivers/firmware/arm_ffa/driver.c
> > @@ -613,6 +613,15 @@ ffa_memory_share(struct ffa_device *dev,
> struct ffa_mem_ops_args *args)
> >         return ffa_memory_ops(FFA_FN_NATIVE(MEM_SHARE), args);  }
> >
> > +static int
> > +ffa_memory_lend(struct ffa_device *dev, struct ffa_mem_ops_args
> > +*args) {
> > +       if (dev->mode_32bit)
> > +               return ffa_memory_ops(FFA_MEM_LEND, args);
> > +
> > +       return ffa_memory_ops(FFA_FN_NATIVE(MEM_LEND), args); }
> > +
> >  static const struct ffa_dev_ops ffa_ops = {
> >         .api_version_get = ffa_api_version_get,
> >         .partition_info_get = ffa_partition_info_get, @@ -620,6
> +629,7
> > @@ static const struct ffa_dev_ops ffa_ops = {
> >         .sync_send_receive = ffa_sync_send_receive,
> >         .memory_reclaim = ffa_memory_reclaim,
> >         .memory_share = ffa_memory_share,
> > +       .memory_lend = ffa_memory_lend,
> >  };
> >
> >  const struct ffa_dev_ops *ffa_dev_ops_get(struct ffa_device *dev)
> > diff --git a/include/linux/arm_ffa.h b/include/linux/arm_ffa.h
> index
> > 505c679b6a9b..85651e41ded8 100644
> > --- a/include/linux/arm_ffa.h
> > +++ b/include/linux/arm_ffa.h
> > @@ -262,6 +262,8 @@ struct ffa_dev_ops {
> >         int (*memory_reclaim)(u64 g_handle, u32 flags);
> >         int (*memory_share)(struct ffa_device *dev,
> >                             struct ffa_mem_ops_args *args);
> > +       int (*memory_lend)(struct ffa_device *dev,
> > +                          struct ffa_mem_ops_args *args);
> >  };
> >
> >  #endif /* _LINUX_ARM_FFA_H */
> > --
> > 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] 3+ messages in thread

end of thread, other threads:[~2021-10-11 10:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-07 17:44 [PATCH] firmware: arm_ffa: Add support for MEM_LEND Marc Bonnici
2021-10-08  7:48 ` Jens Wiklander
2021-10-11 10:26   ` Marc Bonnici

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.