Re: [Xen-devel] [PATCH v6 7/7] xen/arm: export shared memory regions as reserved-memory on device tree

2018-08-03 Thread Julien Grall

Hi Stefano,

On 08/01/2018 11:25 PM, Stefano Stabellini wrote:

On Wed, 1 Aug 2018, Julien Grall wrote:

Hi,

On 31/07/18 19:23, Stefano Stabellini wrote:

Shared memory regions need to be advertised to the guest. Fortunately, a
device tree binding for special memory regions already exist:
reserved-memory.

Add a reserved-memory node for each shared memory region, for both
masters and slaves.

Signed-off-by: Stefano Stabellini 
---
   tools/libxl/libxl_arch.h |  2 +-
   tools/libxl/libxl_arm.c  | 52
+---
   tools/libxl/libxl_dom.c  |  2 +-
   tools/libxl/libxl_x86.c  |  2 +-
   4 files changed, 52 insertions(+), 6 deletions(-)

diff --git a/tools/libxl/libxl_arch.h b/tools/libxl/libxl_arch.h
index 6a07ccf..3626e4a 100644
--- a/tools/libxl/libxl_arch.h
+++ b/tools/libxl/libxl_arch.h
@@ -36,7 +36,7 @@ int libxl__arch_domain_create(libxl__gc *gc,
libxl_domain_config *d_config,
   /* setup arch specific hardware description, i.e. DTB on ARM */
   _hidden
   int libxl__arch_domain_init_hw_description(libxl__gc *gc,
-   libxl_domain_build_info *info,
+   libxl_domain_config *d_config,
  libxl__domain_build_state
*state,
  struct xc_dom_image *dom);
   /* finalize arch specific hardware description. */
diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c
index 5f62e78..4020453 100644
--- a/tools/libxl/libxl_arm.c
+++ b/tools/libxl/libxl_arm.c
@@ -461,6 +461,49 @@ static int make_memory_nodes(libxl__gc *gc, void *fdt,
   return 0;
   }
   +static int make_reserved_nodes(libxl__gc *gc, void *fdt,
+   libxl_domain_config *d_config)
+{
+int res, i;
+const char *name;
+
+if (d_config->num_sshms == 0)
+return 0;
+
+res = fdt_begin_node(fdt, "reserved-memory");
+if (res) return res;
+
+res = fdt_property_cell(fdt, "#address-cells", ROOT_ADDRESS_CELLS);
+if (res) return res;
+
+res = fdt_property_cell(fdt, "#size-cells", ROOT_SIZE_CELLS);
+if (res) return res;
+
+res = fdt_property(fdt, "ranges", NULL, 0);
+if (res) return res;
+
+for (i = 0; i < d_config->num_sshms; i++) {
+uint64_t start = d_config->sshms[i].begin;
+if (d_config->sshms[i].role == LIBXL_SSHM_ROLE_SLAVE)
+start += d_config->sshms[i].offset;
+name = GCSPRINTF("memory@%"PRIx64, start);


I understand the node will be useful for avoid the guest using as a normal
memory.


Yes, that's right.



We also need to make sure the guest can detect what it is used for
(imagine a driver for it). So you probably want a need compatible and more
information in it.


Something like "xen,shared-memory" ?


The name sounds good to me. We might also want to expose the ID used for 
the share. I think this would help the guest to know what to do with it.


Cheers,

--
Julien Grall

___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH v6 7/7] xen/arm: export shared memory regions as reserved-memory on device tree

2018-08-01 Thread Stefano Stabellini
On Wed, 1 Aug 2018, Julien Grall wrote:
> Hi,
> 
> On 31/07/18 19:23, Stefano Stabellini wrote:
> > Shared memory regions need to be advertised to the guest. Fortunately, a
> > device tree binding for special memory regions already exist:
> > reserved-memory.
> > 
> > Add a reserved-memory node for each shared memory region, for both
> > masters and slaves.
> > 
> > Signed-off-by: Stefano Stabellini 
> > ---
> >   tools/libxl/libxl_arch.h |  2 +-
> >   tools/libxl/libxl_arm.c  | 52
> > +---
> >   tools/libxl/libxl_dom.c  |  2 +-
> >   tools/libxl/libxl_x86.c  |  2 +-
> >   4 files changed, 52 insertions(+), 6 deletions(-)
> > 
> > diff --git a/tools/libxl/libxl_arch.h b/tools/libxl/libxl_arch.h
> > index 6a07ccf..3626e4a 100644
> > --- a/tools/libxl/libxl_arch.h
> > +++ b/tools/libxl/libxl_arch.h
> > @@ -36,7 +36,7 @@ int libxl__arch_domain_create(libxl__gc *gc,
> > libxl_domain_config *d_config,
> >   /* setup arch specific hardware description, i.e. DTB on ARM */
> >   _hidden
> >   int libxl__arch_domain_init_hw_description(libxl__gc *gc,
> > -   libxl_domain_build_info *info,
> > +   libxl_domain_config *d_config,
> >  libxl__domain_build_state
> > *state,
> >  struct xc_dom_image *dom);
> >   /* finalize arch specific hardware description. */
> > diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c
> > index 5f62e78..4020453 100644
> > --- a/tools/libxl/libxl_arm.c
> > +++ b/tools/libxl/libxl_arm.c
> > @@ -461,6 +461,49 @@ static int make_memory_nodes(libxl__gc *gc, void *fdt,
> >   return 0;
> >   }
> >   +static int make_reserved_nodes(libxl__gc *gc, void *fdt,
> > +   libxl_domain_config *d_config)
> > +{
> > +int res, i;
> > +const char *name;
> > +
> > +if (d_config->num_sshms == 0)
> > +return 0;
> > +
> > +res = fdt_begin_node(fdt, "reserved-memory");
> > +if (res) return res;
> > +
> > +res = fdt_property_cell(fdt, "#address-cells", ROOT_ADDRESS_CELLS);
> > +if (res) return res;
> > +
> > +res = fdt_property_cell(fdt, "#size-cells", ROOT_SIZE_CELLS);
> > +if (res) return res;
> > +
> > +res = fdt_property(fdt, "ranges", NULL, 0);
> > +if (res) return res;
> > +
> > +for (i = 0; i < d_config->num_sshms; i++) {
> > +uint64_t start = d_config->sshms[i].begin;
> > +if (d_config->sshms[i].role == LIBXL_SSHM_ROLE_SLAVE)
> > +start += d_config->sshms[i].offset;
> > +name = GCSPRINTF("memory@%"PRIx64, start);
> 
> I understand the node will be useful for avoid the guest using as a normal
> memory. 

Yes, that's right.


> We also need to make sure the guest can detect what it is used for
> (imagine a driver for it). So you probably want a need compatible and more
> information in it.

Something like "xen,shared-memory" ?


> Also, this would be clearer if the name is called xen-shmem@ rather than
> memory@.

Sure, we are free to choose the node name.


> > +
> > +res = fdt_begin_node(fdt, name);
> > +if (res) return res;
> > +
> > +res = fdt_property_regs(gc, fdt, ROOT_ADDRESS_CELLS,
> > ROOT_SIZE_CELLS,
> > +1, start, d_config->sshms[i].size);
> > +
> > +res = fdt_end_node(fdt);
> > +if (res) return res;
> > +}
> > +
> > +res = fdt_end_node(fdt);
> > +if (res) return res;
> > +
> > +return 0;
> > +}

___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH v6 7/7] xen/arm: export shared memory regions as reserved-memory on device tree

2018-08-01 Thread Julien Grall

Hi,

On 31/07/18 19:23, Stefano Stabellini wrote:

Shared memory regions need to be advertised to the guest. Fortunately, a
device tree binding for special memory regions already exist:
reserved-memory.

Add a reserved-memory node for each shared memory region, for both
masters and slaves.

Signed-off-by: Stefano Stabellini 
---
  tools/libxl/libxl_arch.h |  2 +-
  tools/libxl/libxl_arm.c  | 52 +---
  tools/libxl/libxl_dom.c  |  2 +-
  tools/libxl/libxl_x86.c  |  2 +-
  4 files changed, 52 insertions(+), 6 deletions(-)

diff --git a/tools/libxl/libxl_arch.h b/tools/libxl/libxl_arch.h
index 6a07ccf..3626e4a 100644
--- a/tools/libxl/libxl_arch.h
+++ b/tools/libxl/libxl_arch.h
@@ -36,7 +36,7 @@ int libxl__arch_domain_create(libxl__gc *gc, 
libxl_domain_config *d_config,
  /* setup arch specific hardware description, i.e. DTB on ARM */
  _hidden
  int libxl__arch_domain_init_hw_description(libxl__gc *gc,
-   libxl_domain_build_info *info,
+   libxl_domain_config *d_config,
 libxl__domain_build_state *state,
 struct xc_dom_image *dom);
  /* finalize arch specific hardware description. */
diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c
index 5f62e78..4020453 100644
--- a/tools/libxl/libxl_arm.c
+++ b/tools/libxl/libxl_arm.c
@@ -461,6 +461,49 @@ static int make_memory_nodes(libxl__gc *gc, void *fdt,
  return 0;
  }
  
+static int make_reserved_nodes(libxl__gc *gc, void *fdt,

+   libxl_domain_config *d_config)
+{
+int res, i;
+const char *name;
+
+if (d_config->num_sshms == 0)
+return 0;
+
+res = fdt_begin_node(fdt, "reserved-memory");
+if (res) return res;
+
+res = fdt_property_cell(fdt, "#address-cells", ROOT_ADDRESS_CELLS);
+if (res) return res;
+
+res = fdt_property_cell(fdt, "#size-cells", ROOT_SIZE_CELLS);
+if (res) return res;
+
+res = fdt_property(fdt, "ranges", NULL, 0);
+if (res) return res;
+
+for (i = 0; i < d_config->num_sshms; i++) {
+uint64_t start = d_config->sshms[i].begin;
+if (d_config->sshms[i].role == LIBXL_SSHM_ROLE_SLAVE)
+start += d_config->sshms[i].offset;
+name = GCSPRINTF("memory@%"PRIx64, start);


I understand the node will be useful for avoid the guest using as a 
normal memory. We also need to make sure the guest can detect what it is 
used for (imagine a driver for it). So you probably want a need 
compatible and more information in it.


Also, this would be clearer if the name is called xen-shmem@ rather than 
memory@.



+
+res = fdt_begin_node(fdt, name);
+if (res) return res;
+
+res = fdt_property_regs(gc, fdt, ROOT_ADDRESS_CELLS, ROOT_SIZE_CELLS,
+1, start, d_config->sshms[i].size);
+
+res = fdt_end_node(fdt);
+if (res) return res;
+}
+
+res = fdt_end_node(fdt);
+if (res) return res;
+
+return 0;
+}
+


Cheers,

--
Julien Grall

___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

[Xen-devel] [PATCH v6 7/7] xen/arm: export shared memory regions as reserved-memory on device tree

2018-07-31 Thread Stefano Stabellini
Shared memory regions need to be advertised to the guest. Fortunately, a
device tree binding for special memory regions already exist:
reserved-memory.

Add a reserved-memory node for each shared memory region, for both
masters and slaves.

Signed-off-by: Stefano Stabellini 
---
 tools/libxl/libxl_arch.h |  2 +-
 tools/libxl/libxl_arm.c  | 52 +---
 tools/libxl/libxl_dom.c  |  2 +-
 tools/libxl/libxl_x86.c  |  2 +-
 4 files changed, 52 insertions(+), 6 deletions(-)

diff --git a/tools/libxl/libxl_arch.h b/tools/libxl/libxl_arch.h
index 6a07ccf..3626e4a 100644
--- a/tools/libxl/libxl_arch.h
+++ b/tools/libxl/libxl_arch.h
@@ -36,7 +36,7 @@ int libxl__arch_domain_create(libxl__gc *gc, 
libxl_domain_config *d_config,
 /* setup arch specific hardware description, i.e. DTB on ARM */
 _hidden
 int libxl__arch_domain_init_hw_description(libxl__gc *gc,
-   libxl_domain_build_info *info,
+   libxl_domain_config *d_config,
libxl__domain_build_state *state,
struct xc_dom_image *dom);
 /* finalize arch specific hardware description. */
diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c
index 5f62e78..4020453 100644
--- a/tools/libxl/libxl_arm.c
+++ b/tools/libxl/libxl_arm.c
@@ -461,6 +461,49 @@ static int make_memory_nodes(libxl__gc *gc, void *fdt,
 return 0;
 }
 
+static int make_reserved_nodes(libxl__gc *gc, void *fdt,
+   libxl_domain_config *d_config)
+{
+int res, i;
+const char *name;
+
+if (d_config->num_sshms == 0)
+return 0;
+
+res = fdt_begin_node(fdt, "reserved-memory");
+if (res) return res;
+
+res = fdt_property_cell(fdt, "#address-cells", ROOT_ADDRESS_CELLS);
+if (res) return res;
+
+res = fdt_property_cell(fdt, "#size-cells", ROOT_SIZE_CELLS);
+if (res) return res;
+
+res = fdt_property(fdt, "ranges", NULL, 0);
+if (res) return res;
+
+for (i = 0; i < d_config->num_sshms; i++) {
+uint64_t start = d_config->sshms[i].begin;
+if (d_config->sshms[i].role == LIBXL_SSHM_ROLE_SLAVE)
+start += d_config->sshms[i].offset;
+name = GCSPRINTF("memory@%"PRIx64, start);
+
+res = fdt_begin_node(fdt, name);
+if (res) return res;
+
+res = fdt_property_regs(gc, fdt, ROOT_ADDRESS_CELLS, ROOT_SIZE_CELLS,
+1, start, d_config->sshms[i].size);
+
+res = fdt_end_node(fdt);
+if (res) return res;
+}
+
+res = fdt_end_node(fdt);
+if (res) return res;
+
+return 0;
+}
+
 static int make_gicv2_node(libxl__gc *gc, void *fdt,
uint64_t gicd_base, uint64_t gicd_size,
uint64_t gicc_base, uint64_t gicc_size)
@@ -836,10 +879,11 @@ static int copy_partial_fdt(libxl__gc *gc, void *fdt, 
void *pfdt)
 
 #define FDT_MAX_SIZE (1<<20)
 
-static int libxl__prepare_dtb(libxl__gc *gc, libxl_domain_build_info *info,
+static int libxl__prepare_dtb(libxl__gc *gc, libxl_domain_config *d_config,
   libxl__domain_build_state *state,
   struct xc_dom_image *dom)
 {
+libxl_domain_build_info *info = _config->b_info;
 void *fdt = NULL;
 void *pfdt = NULL;
 int rc, res;
@@ -922,6 +966,7 @@ next_resize:
 FDT( make_psci_node(gc, fdt) );
 
 FDT( make_memory_nodes(gc, fdt, dom) );
+FDT( make_reserved_nodes(gc, fdt, d_config) );
 
 switch (info->arch_arm.gic_version) {
 case LIBXL_GIC_VERSION_V2:
@@ -971,12 +1016,13 @@ out:
 }
 
 int libxl__arch_domain_init_hw_description(libxl__gc *gc,
-   libxl_domain_build_info *info,
+   libxl_domain_config *d_config,
libxl__domain_build_state *state,
struct xc_dom_image *dom)
 {
 int rc;
 uint64_t val;
+libxl_domain_build_info *info = _config->b_info;
 
 assert(info->type == LIBXL_DOMAIN_TYPE_PV);
 
@@ -992,7 +1038,7 @@ int libxl__arch_domain_init_hw_description(libxl__gc *gc,
 if (rc)
 return rc;
 
-rc = libxl__prepare_dtb(gc, info, state, dom);
+rc = libxl__prepare_dtb(gc, d_config, state, dom);
 if (rc) goto out;
 
 if (!libxl_defbool_val(info->acpi)) {
diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
index 3cfe0d4..4ab52df 100644
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -719,7 +719,7 @@ static int libxl__build_dom(libxl__gc *gc, uint32_t domid,
 LOG(ERROR, "xc_dom_parse_image failed");
 goto out;
 }
-if ( (ret = libxl__arch_domain_init_hw_description(gc, info, state, dom)) 
!= 0 ) {
+if ( (ret = libxl__arch_domain_init_hw_description(gc, d_config, state, 
dom)) !=