qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hw/arm/virt: use pflash image real size when mapping
@ 2020-09-18 12:26 haibinzhang(张海斌)
  2020-09-18 13:41 ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 6+ messages in thread
From: haibinzhang(张海斌) @ 2020-09-18 12:26 UTC (permalink / raw)
  To: Peter Maydell, qemu-arm@nongnu.org; +Cc: qemu-devel@nongnu.org

Default size of arm-virt pflash image is 64MB which
will cost extra 128MB(64MBx2) memory per qemu process
and 12.5GB for 100 qemu processes. Host memory is
precious and it is valuable to reduce pflash image size.
For compatibility arm-virt uses real size when mapping.

Signed-off-by: Haibin Zhang <haibinzhang@tencent.com>
---
 hw/arm/virt.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index acf9bfbece..3545e12865 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -50,6 +50,7 @@
 #include "sysemu/sysemu.h"
 #include "sysemu/tpm.h"
 #include "sysemu/kvm.h"
+#include "sysemu/block-backend.h"
 #include "hw/loader.h"
 #include "exec/address-spaces.h"
 #include "qemu/bitops.h"
@@ -1001,10 +1002,27 @@ static void virt_flash_map(VirtMachineState *vms,
      */
     hwaddr flashsize = vms->memmap[VIRT_FLASH].size / 2;
     hwaddr flashbase = vms->memmap[VIRT_FLASH].base;
+    int64_t realsize;
+    BlockBackend *blk;

-    virt_flash_map1(vms->flash[0], flashbase, flashsize,
+    realsize = flashsize;
+    blk = pflash_cfi01_get_blk(vms->flash[0]);
+    if (blk) {
+        realsize = blk_getlength(blk);
+        realsize = realsize < flashsize ? realsize : flashsize;
+    }
+
+    virt_flash_map1(vms->flash[0], flashbase, realsize,
                     secure_sysmem);
-    virt_flash_map1(vms->flash[1], flashbase + flashsize, flashsize,
+
+    realsize = flashsize;
+    blk = pflash_cfi01_get_blk(vms->flash[1]);
+    if (blk) {
+        realsize = blk_getlength(blk);
+        realsize = realsize < flashsize ? realsize : flashsize;
+    }
+
+    virt_flash_map1(vms->flash[1], flashbase + flashsize, realsize,
                     sysmem);
 }

--
2.23.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread
* [PATCH] hw/arm/virt: use pflash image real size when mapping
@ 2020-09-18 12:21 haibinzhang(张海斌)
  0 siblings, 0 replies; 6+ messages in thread
From: haibinzhang(张海斌) @ 2020-09-18 12:21 UTC (permalink / raw)
  To: peter.maydell@linaro.org, qemu-arm@nongnu.or; +Cc: qemu-devel@nongnu.org

Default size of arm-virt pflash image is 64MB which
will cost extra 128MB(64MBx2) memory per qemu process
and 12.5GB for 100 qemu processes. Host memory is
precious and it is valuable to reduce pflash image size.
For compatibility arm-virt uses real size when mapping.

Signed-off-by: Haibin Zhang <haibinzhang@tencent.com>
---
 hw/arm/virt.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index acf9bfbece..3545e12865 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -50,6 +50,7 @@
 #include "sysemu/sysemu.h"
 #include "sysemu/tpm.h"
 #include "sysemu/kvm.h"
+#include "sysemu/block-backend.h"
 #include "hw/loader.h"
 #include "exec/address-spaces.h"
 #include "qemu/bitops.h"
@@ -1001,10 +1002,27 @@ static void virt_flash_map(VirtMachineState *vms,
      */
     hwaddr flashsize = vms->memmap[VIRT_FLASH].size / 2;
     hwaddr flashbase = vms->memmap[VIRT_FLASH].base;
+    int64_t realsize;
+    BlockBackend *blk;

-    virt_flash_map1(vms->flash[0], flashbase, flashsize,
+    realsize = flashsize;
+    blk = pflash_cfi01_get_blk(vms->flash[0]);
+    if (blk) {
+        realsize = blk_getlength(blk);
+        realsize = realsize < flashsize ? realsize : flashsize;
+    }
+
+    virt_flash_map1(vms->flash[0], flashbase, realsize,
                     secure_sysmem);
-    virt_flash_map1(vms->flash[1], flashbase + flashsize, flashsize,
+
+    realsize = flashsize;
+    blk = pflash_cfi01_get_blk(vms->flash[1]);
+    if (blk) {
+        realsize = blk_getlength(blk);
+        realsize = realsize < flashsize ? realsize : flashsize;
+    }
+
+    virt_flash_map1(vms->flash[1], flashbase + flashsize, realsize,
                     sysmem);
 }

--
2.23.0


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

end of thread, other threads:[~2020-09-22  7:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-18 12:26 [PATCH] hw/arm/virt: use pflash image real size when mapping haibinzhang(张海斌)
2020-09-18 13:41 ` Philippe Mathieu-Daudé
2020-09-19 10:03   ` haibinzhang(张海斌)
2020-09-21  5:34   ` haibinzhang(张海斌)
2020-09-22  6:57   ` Laszlo Ersek
  -- strict thread matches above, loose matches on Subject: below --
2020-09-18 12:21 haibinzhang(张海斌)

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