qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/2] spapr: Move rtas and device-tree higher
@ 2014-07-21  3:02 Alexey Kardashevskiy
  2014-07-21  3:02 ` [Qemu-devel] [PATCH 1/2] loader: Add load_image_size() to replace load_image() Alexey Kardashevskiy
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Alexey Kardashevskiy @ 2014-07-21  3:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: Alexey Kardashevskiy, qemu-ppc, Alexander Graf

At the moment RTAS and device tree are located at 256MB max
which leaves too little space for huge initramdisk images and kernels.
This relaxes the limitation.

This is checkpatch.pl'ed version of:
[PATCH 1/2] loader: Add load_image_size() to replace load_image()
[PATCH 2/2] ppc/spapr: Locate RTAS and device-tree based on real RMA

Please comment. Thanks.


Benjamin Herrenschmidt (2):
  loader: Add load_image_size() to replace load_image()
  spapr: Locate RTAS and device-tree based on real RMA

 hw/core/loader.c       | 21 +++++++++++++++++++++
 hw/ppc/spapr.c         | 32 +++++++++++++++++++++-----------
 include/hw/loader.h    |  1 +
 include/hw/ppc/spapr.h |  3 ++-
 4 files changed, 45 insertions(+), 12 deletions(-)

-- 
2.0.0

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Qemu-devel] [PATCH 1/2] loader: Add load_image_size() to replace load_image()
  2014-07-21  3:02 [Qemu-devel] [PATCH 0/2] spapr: Move rtas and device-tree higher Alexey Kardashevskiy
@ 2014-07-21  3:02 ` Alexey Kardashevskiy
  2014-07-21  3:02 ` [Qemu-devel] [PATCH 2/2] spapr: Locate RTAS and device-tree based on real RMA Alexey Kardashevskiy
  2014-07-28 11:23 ` [Qemu-devel] [PATCH 0/2] spapr: Move rtas and device-tree higher Alexander Graf
  2 siblings, 0 replies; 4+ messages in thread
From: Alexey Kardashevskiy @ 2014-07-21  3:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: Alexey Kardashevskiy, qemu-ppc, Alexander Graf

From: Benjamin Herrenschmidt <benh@kernel.crashing.org>

A subsequent patch to ppc/spapr needs to load the RTAS blob into
qemu memory rather than target memory (so it can later be copied
into the right spot at machine reset time).

I would use load_image() but it is marked deprecated because it
doesn't take a buffer size as argument, so let's add load_image_size()
that does.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
[aik: fixed errors from checkpatch.pl]
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
---
 hw/core/loader.c    | 21 +++++++++++++++++++++
 include/hw/loader.h |  1 +
 2 files changed, 22 insertions(+)

diff --git a/hw/core/loader.c b/hw/core/loader.c
index 2bf6b8f..5e2b6cd 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -89,6 +89,27 @@ int load_image(const char *filename, uint8_t *addr)
     return size;
 }
 
+/* return the size or -1 if error */
+ssize_t load_image_size(const char *filename, void *addr, size_t size)
+{
+    int fd;
+    ssize_t actsize;
+
+    fd = open(filename, O_RDONLY | O_BINARY);
+    if (fd < 0) {
+        return -1;
+    }
+
+    actsize = read(fd, addr, size);
+    if (actsize < 0) {
+        close(fd);
+        return -1;
+    }
+    close(fd);
+
+    return actsize;
+}
+
 /* read()-like version */
 ssize_t read_targphys(const char *name,
                       int fd, hwaddr dst_addr, size_t nbytes)
diff --git a/include/hw/loader.h b/include/hw/loader.h
index 796cbf9..991f84a 100644
--- a/include/hw/loader.h
+++ b/include/hw/loader.h
@@ -13,6 +13,7 @@
  */
 int get_image_size(const char *filename);
 int load_image(const char *filename, uint8_t *addr); /* deprecated */
+ssize_t load_image_size(const char *filename, void *addr, size_t size);
 int load_image_targphys(const char *filename, hwaddr,
                         uint64_t max_sz);
 
-- 
2.0.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [Qemu-devel] [PATCH 2/2] spapr: Locate RTAS and device-tree based on real RMA
  2014-07-21  3:02 [Qemu-devel] [PATCH 0/2] spapr: Move rtas and device-tree higher Alexey Kardashevskiy
  2014-07-21  3:02 ` [Qemu-devel] [PATCH 1/2] loader: Add load_image_size() to replace load_image() Alexey Kardashevskiy
@ 2014-07-21  3:02 ` Alexey Kardashevskiy
  2014-07-28 11:23 ` [Qemu-devel] [PATCH 0/2] spapr: Move rtas and device-tree higher Alexander Graf
  2 siblings, 0 replies; 4+ messages in thread
From: Alexey Kardashevskiy @ 2014-07-21  3:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: Alexey Kardashevskiy, qemu-ppc, Alexander Graf

From: Benjamin Herrenschmidt <benh@kernel.crashing.org>

We currently calculate the final RTAS and FDT location based on
the early estimate of the RMA size, cropped to 256M on KVM since
we only know the real RMA size at reset time which happens much
later in the boot process.

This means the FDT and RTAS end up right below 256M while they
could be much higher, using precious RMA space and limiting
what the OS bootloader can put there which has proved to be
a problem with some OSes (such as when using very large initrd's)

Fortunately, we do the actual copy of the device-tree into guest
memory much later, during reset, late enough to be able to do it
using the final RMA value, we just need to move the calculation
to the right place.

However, RTAS is still loaded too early, so we change the code to
load the tiny blob into qemu memory early on, and then copy it into
guest memory at reset time. It's small enough that the memory usage
doesn't matter.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
[aik: fixed errors from checkpatch.pl, defined RTAS_MAX_ADDR]
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
---
 hw/ppc/spapr.c         | 32 +++++++++++++++++++++-----------
 include/hw/ppc/spapr.h |  3 ++-
 2 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 6b48a26..a4fe7a6 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -70,6 +70,7 @@
  */
 #define FDT_MAX_SIZE            0x40000
 #define RTAS_MAX_SIZE           0x10000
+#define RTAS_MAX_ADDR           0x80000000 /* RTAS must stay below that */
 #define FW_MAX_SIZE             0x400000
 #define FW_FILE_NAME            "slof.bin"
 #define FW_OVERHEAD             0x2800000
@@ -837,16 +838,30 @@ static void spapr_reset_htab(sPAPREnvironment *spapr)
 static void ppc_spapr_reset(void)
 {
     PowerPCCPU *first_ppc_cpu;
+    uint32_t rtas_limit;
 
     /* Reset the hash table & recalc the RMA */
     spapr_reset_htab(spapr);
 
     qemu_devices_reset();
 
+    /*
+     * We place the device tree and RTAS just below either the top of the RMA,
+     * or just below 2GB, whichever is lowere, so that it can be
+     * processed with 32-bit real mode code if necessary
+     */
+    rtas_limit = MIN(spapr->rma_size, RTAS_MAX_ADDR);
+    spapr->rtas_addr = rtas_limit - RTAS_MAX_SIZE;
+    spapr->fdt_addr = spapr->rtas_addr - FDT_MAX_SIZE;
+
     /* Load the fdt */
     spapr_finalize_fdt(spapr, spapr->fdt_addr, spapr->rtas_addr,
                        spapr->rtas_size);
 
+    /* Copy RTAS over */
+    cpu_physical_memory_write(spapr->rtas_addr, spapr->rtas_blob,
+                              spapr->rtas_size);
+
     /* Set up the entry state */
     first_ppc_cpu = POWERPC_CPU(first_cpu);
     first_ppc_cpu->env.gpr[3] = spapr->fdt_addr;
@@ -1266,7 +1281,7 @@ static void ppc_spapr_init(MachineState *machine)
     hwaddr node0_size = (nb_numa_nodes > 1) ? numa_info[0].node_mem : ram_size;
     uint32_t initrd_base = 0;
     long kernel_size = 0, initrd_size = 0;
-    long load_limit, rtas_limit, fw_size;
+    long load_limit, fw_size;
     bool kernel_le = false;
     char *filename;
 
@@ -1311,13 +1326,8 @@ static void ppc_spapr_init(MachineState *machine)
         exit(1);
     }
 
-    /* We place the device tree and RTAS just below either the top of the RMA,
-     * or just below 2GB, whichever is lowere, so that it can be
-     * processed with 32-bit real mode code if necessary */
-    rtas_limit = MIN(spapr->rma_size, 0x80000000);
-    spapr->rtas_addr = rtas_limit - RTAS_MAX_SIZE;
-    spapr->fdt_addr = spapr->rtas_addr - FDT_MAX_SIZE;
-    load_limit = spapr->fdt_addr - FW_OVERHEAD;
+    /* Setup a load limit for the ramdisk leaving room for SLOF and FDT */
+    load_limit = MIN(spapr->rma_size, RTAS_MAX_ADDR) - FW_OVERHEAD;
 
     /* We aim for a hash table of size 1/128 the size of RAM.  The
      * normal rule of thumb is 1/64 the size of RAM, but that's much
@@ -1385,9 +1395,9 @@ static void ppc_spapr_init(MachineState *machine)
     }
 
     filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, "spapr-rtas.bin");
-    spapr->rtas_size = load_image_targphys(filename, spapr->rtas_addr,
-                                           rtas_limit - spapr->rtas_addr);
-    if (spapr->rtas_size < 0) {
+    spapr->rtas_size = get_image_size(filename);
+    spapr->rtas_blob = g_malloc(spapr->rtas_size);
+    if (load_image_size(filename, spapr->rtas_blob, spapr->rtas_size) < 0) {
         hw_error("qemu: could not load LPAR rtas '%s'\n", filename);
         exit(1);
     }
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
index 7fff979..36e8e51 100644
--- a/include/hw/ppc/spapr.h
+++ b/include/hw/ppc/spapr.h
@@ -24,7 +24,8 @@ typedef struct sPAPREnvironment {
     hwaddr rma_size;
     int vrma_adjust;
     hwaddr fdt_addr, rtas_addr;
-    long rtas_size;
+    ssize_t rtas_size;
+    void *rtas_blob;
     void *fdt_skel;
     target_ulong entry_point;
     uint64_t rtc_offset;
-- 
2.0.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH 0/2] spapr: Move rtas and device-tree higher
  2014-07-21  3:02 [Qemu-devel] [PATCH 0/2] spapr: Move rtas and device-tree higher Alexey Kardashevskiy
  2014-07-21  3:02 ` [Qemu-devel] [PATCH 1/2] loader: Add load_image_size() to replace load_image() Alexey Kardashevskiy
  2014-07-21  3:02 ` [Qemu-devel] [PATCH 2/2] spapr: Locate RTAS and device-tree based on real RMA Alexey Kardashevskiy
@ 2014-07-28 11:23 ` Alexander Graf
  2 siblings, 0 replies; 4+ messages in thread
From: Alexander Graf @ 2014-07-28 11:23 UTC (permalink / raw)
  To: Alexey Kardashevskiy, qemu-devel; +Cc: qemu-ppc


On 21.07.14 05:02, Alexey Kardashevskiy wrote:
> At the moment RTAS and device tree are located at 256MB max
> which leaves too little space for huge initramdisk images and kernels.
> This relaxes the limitation.
>
> This is checkpatch.pl'ed version of:
> [PATCH 1/2] loader: Add load_image_size() to replace load_image()
> [PATCH 2/2] ppc/spapr: Locate RTAS and device-tree based on real RMA
>
> Please comment. Thanks.

Thanks, applied all to ppc-next-2.2.


Alex

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-07-28 11:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-21  3:02 [Qemu-devel] [PATCH 0/2] spapr: Move rtas and device-tree higher Alexey Kardashevskiy
2014-07-21  3:02 ` [Qemu-devel] [PATCH 1/2] loader: Add load_image_size() to replace load_image() Alexey Kardashevskiy
2014-07-21  3:02 ` [Qemu-devel] [PATCH 2/2] spapr: Locate RTAS and device-tree based on real RMA Alexey Kardashevskiy
2014-07-28 11:23 ` [Qemu-devel] [PATCH 0/2] spapr: Move rtas and device-tree higher Alexander Graf

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).