[RFC,v5,14/16] Add an ultravisor device tree in secure memory
diff mbox series

Message ID 20200227204023.22125-15-grimm@linux.ibm.com
State New
Headers show
Series
  • Ultravisor support in skiboot
Related show

Checks

Context Check Description
snowpatch_ozlabs/snowpatch_job_snowpatch-skiboot-dco success Signed-off-by present
snowpatch_ozlabs/snowpatch_job_snowpatch-skiboot success Test snowpatch/job/snowpatch-skiboot on branch master
snowpatch_ozlabs/apply_patch success Successfully applied on branch master (82aed17a5468aff6b600ee1694a10a60f942c018)

Commit Message

Ryan Grimm Feb. 27, 2020, 8:40 p.m. UTC
This patch adds a UV FDT created in secure memory.  It is allocated
directly after the ultravisor.

The UV FDT will contain information like the wrapping key.

The code uses libfdt directly to ensure only secure memory is used.

Signed-off-by: Ryan Grimm <grimm@linux.ibm.com>
Signed-off-by: Ram Pai <linuxram@us.ibm.com>
---
 hw/ultravisor.c      | 26 +++++++++++++++++++++++++-
 include/ultravisor.h |  1 +
 2 files changed, 26 insertions(+), 1 deletion(-)

Comments

Alexey Kardashevskiy March 12, 2020, 1:43 a.m. UTC | #1
On 28/02/2020 07:40, Ryan Grimm wrote:
> This patch adds a UV FDT created in secure memory.  It is allocated
> directly after the ultravisor.
> 
> The UV FDT will contain information like the wrapping key.

Who is the consumer of this FDT?


> 
> The code uses libfdt directly to ensure only secure memory is used.
> 
> Signed-off-by: Ryan Grimm <grimm@linux.ibm.com>
> Signed-off-by: Ram Pai <linuxram@us.ibm.com>
> ---
>  hw/ultravisor.c      | 26 +++++++++++++++++++++++++-
>  include/ultravisor.h |  1 +
>  2 files changed, 26 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/ultravisor.c b/hw/ultravisor.c
> index 277faeeb..da5b8346 100644
> --- a/hw/ultravisor.c
> +++ b/hw/ultravisor.c
> @@ -12,6 +12,7 @@
>  #include <console.h>
>  #include <chip.h>
>  #include <libstb/container.h>
> +#include <libfdt/libfdt.h>
>  
>  static struct dt_node *uv_fw_node;
>  static uint64_t uv_base_addr;
> @@ -115,9 +116,27 @@ static int uv_decompress_image(void)
>  	return OPAL_SUCCESS;
>  }
>  
> +static int create_dtb_uv(void *uv_fdt)
> +{
> +	if (fdt_create(uv_fdt, UV_FDT_MAX_SIZE)) {
> +		prerror("UV: Failed to create uv_fdt\n");
> +		return OPAL_NO_MEM;
> +	}
> +
> +	fdt_finish_reservemap(uv_fdt);
> +	fdt_begin_node(uv_fdt, "");
> +	fdt_property_string(uv_fdt, "description", "Ultravisor fdt");
> +	fdt_begin_node(uv_fdt, "ibm,uv-fdt");
> +	fdt_property_string(uv_fdt, "compatible", "ibm,uv-fdt");
> +	fdt_end_node(uv_fdt);
> +	fdt_finish(uv_fdt);


Every one of these fdt_xxxx() can fail.


> +
> +	return OPAL_SUCCESS;
> +}
> +
>  void init_uv()
>  {
> -	uint64_t uv_dt_src, uv_fw_sz;
> +	uint64_t uv_dt_src, uv_fw_sz, uv_fdt_addr;
>  	struct dt_node *reserved_mem;
>  	int ret;
>  
> @@ -151,6 +170,11 @@ void init_uv()
>  
>  	dt_add_property_u64(uv_fw_node, "memcons", (u64)&uv_memcons);
>  	debug_descriptor.uv_memcons_phys = (u64)&uv_memcons;
> +
> +	uv_base_addr = dt_get_address(uv_fw_node, 0, NULL);
> +	uv_fdt_addr = uv_base_addr + UV_LOAD_MAX_SIZE;
> +	create_dtb_uv((void *)uv_fdt_addr);


create_dtb_uv() can fail but we ignore it? Thanks,


> +	dt_add_property_u64(uv_fw_node, "uv-fdt", uv_fdt_addr);
>  err:
>  	local_free(uv_image);
>  }
> diff --git a/include/ultravisor.h b/include/ultravisor.h
> index 26a986cd..347b085d 100644
> --- a/include/ultravisor.h
> +++ b/include/ultravisor.h
> @@ -14,6 +14,7 @@
>  #define UCALL_BUFSIZE 4
>  #define UV_READ_SCOM  0xF114
>  #define UV_WRITE_SCOM 0xF118
> +#define UV_FDT_MAX_SIZE		0x100000
>  
>  extern long ucall(unsigned long opcode, unsigned long *retbuf, ...);
>  extern int start_uv(uint64_t entry, void *fdt);
>

Patch
diff mbox series

diff --git a/hw/ultravisor.c b/hw/ultravisor.c
index 277faeeb..da5b8346 100644
--- a/hw/ultravisor.c
+++ b/hw/ultravisor.c
@@ -12,6 +12,7 @@ 
 #include <console.h>
 #include <chip.h>
 #include <libstb/container.h>
+#include <libfdt/libfdt.h>
 
 static struct dt_node *uv_fw_node;
 static uint64_t uv_base_addr;
@@ -115,9 +116,27 @@  static int uv_decompress_image(void)
 	return OPAL_SUCCESS;
 }
 
+static int create_dtb_uv(void *uv_fdt)
+{
+	if (fdt_create(uv_fdt, UV_FDT_MAX_SIZE)) {
+		prerror("UV: Failed to create uv_fdt\n");
+		return OPAL_NO_MEM;
+	}
+
+	fdt_finish_reservemap(uv_fdt);
+	fdt_begin_node(uv_fdt, "");
+	fdt_property_string(uv_fdt, "description", "Ultravisor fdt");
+	fdt_begin_node(uv_fdt, "ibm,uv-fdt");
+	fdt_property_string(uv_fdt, "compatible", "ibm,uv-fdt");
+	fdt_end_node(uv_fdt);
+	fdt_finish(uv_fdt);
+
+	return OPAL_SUCCESS;
+}
+
 void init_uv()
 {
-	uint64_t uv_dt_src, uv_fw_sz;
+	uint64_t uv_dt_src, uv_fw_sz, uv_fdt_addr;
 	struct dt_node *reserved_mem;
 	int ret;
 
@@ -151,6 +170,11 @@  void init_uv()
 
 	dt_add_property_u64(uv_fw_node, "memcons", (u64)&uv_memcons);
 	debug_descriptor.uv_memcons_phys = (u64)&uv_memcons;
+
+	uv_base_addr = dt_get_address(uv_fw_node, 0, NULL);
+	uv_fdt_addr = uv_base_addr + UV_LOAD_MAX_SIZE;
+	create_dtb_uv((void *)uv_fdt_addr);
+	dt_add_property_u64(uv_fw_node, "uv-fdt", uv_fdt_addr);
 err:
 	local_free(uv_image);
 }
diff --git a/include/ultravisor.h b/include/ultravisor.h
index 26a986cd..347b085d 100644
--- a/include/ultravisor.h
+++ b/include/ultravisor.h
@@ -14,6 +14,7 @@ 
 #define UCALL_BUFSIZE 4
 #define UV_READ_SCOM  0xF114
 #define UV_WRITE_SCOM 0xF118
+#define UV_FDT_MAX_SIZE		0x100000
 
 extern long ucall(unsigned long opcode, unsigned long *retbuf, ...);
 extern int start_uv(uint64_t entry, void *fdt);