qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 2.1 v7 0/3] Add max-ram-below-4g (was Add pci_hole_min_size machine option)
@ 2014-06-20  1:40 Don Slutz
  2014-06-20  1:40 ` [Qemu-devel] [PATCH 2.1 v7 1/3] xen-hvm: Fix xen_hvm_init() to adjust pc memory layout Don Slutz
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Don Slutz @ 2014-06-20  1:40 UTC (permalink / raw)
  To: xen-devel, qemu-devel, Stefano Stabellini
  Cc: Marcel Apfelbaum, Michael S. Tsirkin, Don Slutz, Anthony Liguori,
	Igor Mammedov, Andreas Färber

Changes v6 to v7:
  Drop most of v5 to v6 changes.

  Michael S. Tsirkin:
    #2 "pc & q35: Add new machine opt max-ram-below-4g":
       default: max-ram-below-4g=4g
       pc & q35:
          calculate lowmem
          lowmem = MIN(lowmem, max-ram-below-4g)
          calculate above_4g_mem_size and below_4g_mem_size

  #3 "xen-hvm: Handle machine opt max-ram-below-4g":
     Rename from "xen-hvm: Pass is_default to xen_hvm_init"
     Drop is_default.
     Use object_property_get_int() to get max-ram-below-4g.
     Do min(xen limit, user limit).


Changes v5 to v6:
  rebased on git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git pci

  Changed default handling.  Most pc machines are now set to 3.5G
  (0xe0000000) and q35 are set to 2.75G (0xb0000000).  The special
  value of 0 is used to flag the complex gigabyte_align memory
  layout selection.

  I did change the default for pc-i440fx-2.1 to 3G and pc-q35-2.1 to
  2G instead of the complex gigabyte_align.  This looks ok to me
  because the statement by Gerd Hoffmann is about more ram for 32
  bit (+non-PAE) guests can now have more then the defualt by
  specifing the new option like "max-ram-below-4g=3.75G" or
  "max-ram-below-4g=3.9375G".  Or if that is too complex to
  understand just select pc-i440fx-2.0 or pc-q35-2.0 to get what
  they use to get.

  Michael S. Tsirkin, Igor Mammedov, Marcel Apfelbaum:
    #2 "pc & q35: Add new machine opt max-ram-below-4g":
       Added setting of .default_machine_opts to include max-ram-below-4g
         for all pc types.
       Removed gigabyte_align.
       Added warning on small value.
       "less then" to "less than"

  #3 "xen-hvm: Pass is_default to xen_hvm_init":
    Changed to work with the changes in #2:
      Added max_ram_below_4g_changed in order to know if it is a default value
      or a user specified one.
    Added "assert(pc_machine->max_ram_below_4g_changed > 0)" so that
      "make check" will abort on default not set for any of the pc or
      q35 machine types.
    Dropped "Acked-by: Stefano Stabellin" do to bigger change.


Changes v4 to v5:
  Re-work based on:

  https://github.com/imammedo/qemu/commits/memory-hotplug-v11

  And so it now depends on this patch set.

  Stefano Stabellini:
    #3 "xen-hvm: Pass is_default to xen_hvm_init"
      Acked-by 
      Minor change of pmc to pcms.

Changes v3 to v4:
  Split out #2 "GlobalProperty: Display warning about unused -global"
  rebase on e00fcfe (origin/master)
  rename xen-all to xen-hvm

  Adjust #1 "xen-hvm: Fix xen_hvm_init() to adjust pc memory layout"
    Switch Acked-by & Signed-off-by
    rebase on master

  Rework #3 "xen-hvm: Pass is_default to xen_hvm_init":
    To pass is_default instead of max_ram_below_4g.
    Also did not add "Acked-by: Stefano Stabellini" since code changed a lot.

  Andreas Färber:
    all: Remove dot at end of subject
    #3 "xen-hvm: Pass is_default to xen_hvm_init"
      Adjust comment formatting.

  Andreas Färber, Paolo Bonzini, Marcel Apfelbaum:
    rework to use "opts per machine"
    Drop old #3, new #2.
  

Changes v2 to v3:
  Stefano Stabellini:
    Acked-by #1 "xen-all: Fix xen_hvm_init() to adjust pc memory"
    Adjust for code readability #4 "xen-all: Pass max_ram_below_4g to xen_hvm_init."
       Set max_ram_below_4g always and use it to calculate above_4g_mem_size,
       below_4g_mem_size.

Changes v1 to v2:
  Michael S. Tsirkin:
    Rename option.
    Only add it to machine types that support it.
  Split into 4 parts.

1/4 -- xen-all: Fix xen_hvm_init() to adjust pc memory layout

  This looks to be a possible bug that has yet to be found.
  below_4g_mem_size and above_4g_mem_size are stored in PcGuestInfo
  (pc_guest_info_init) which are currently not "correct".  This and
  4/4 change the same lines.

2/4 -- GlobalProperty: Display warning about unused -global

    My testing showed that setting a global property on an object
    that is not used is not reported at all.  This is added to help
    when the new global is set but not used.  The negative not_used
    was picked so that all static objects are assumed to be used
    even when they are not.

3/4 -- pc & q35: Add new object pc-memory-layout

  The objects that it might make sense to add this property to all
  get created too late.  So add a new object just to hold this
  property.  Name it so that it is expected that only pc (and q35)
  machine types support it.

4/4 -- xen-all: Pass max_ram_below_4g to xen_hvm_init

  Seprate the xen only part of the change.  Currectly based on patch 1/4

Don Slutz (3):
  xen-hvm: Fix xen_hvm_init() to adjust pc memory layout
  pc & q35: Add new machine opt max-ram-below-4g
  xen-hvm: Handle machine opt max-ram-below-4g

 hw/i386/pc.c         | 47 ++++++++++++++++++++++++++++++++++++++++++++++
 hw/i386/pc_piix.c    | 53 ++++++++++++++++++++++++++++++++++++----------------
 hw/i386/pc_q35.c     | 51 +++++++++++++++++++++++++++++++++++---------------
 include/hw/i386/pc.h |  3 +++
 include/hw/xen/xen.h |  3 ++-
 vl.c                 |  4 ++++
 xen-hvm-stub.c       |  3 ++-
 xen-hvm.c            | 53 +++++++++++++++++++++++++++++++++-------------------
 8 files changed, 165 insertions(+), 52 deletions(-)

-- 
1.8.4

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

* [Qemu-devel] [PATCH 2.1 v7 1/3] xen-hvm: Fix xen_hvm_init() to adjust pc memory layout
  2014-06-20  1:40 [Qemu-devel] [PATCH 2.1 v7 0/3] Add max-ram-below-4g (was Add pci_hole_min_size machine option) Don Slutz
@ 2014-06-20  1:40 ` Don Slutz
  2014-06-20  1:40 ` [Qemu-devel] [PATCH 2.1 v7 2/3] pc & q35: Add new machine opt max-ram-below-4g Don Slutz
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Don Slutz @ 2014-06-20  1:40 UTC (permalink / raw)
  To: xen-devel, qemu-devel, Stefano Stabellini
  Cc: Marcel Apfelbaum, Michael S. Tsirkin, Don Slutz, Anthony Liguori,
	Igor Mammedov, Andreas Färber

This is just below_4g_mem_size and above_4g_mem_size which is used later in QEMU.

Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Signed-off-by: Don Slutz <dslutz@verizon.com>
---
v7:
    No change
v6:
    No change
v5:
    No change
v4:
    Switch Acked-by & Signed-off-by
    rebase on master
v3:
    Add Acked-by: Stefano Stabellini
v2:
    No change

 hw/i386/pc_piix.c    | 31 ++++++++++++++++---------------
 hw/i386/pc_q35.c     | 29 +++++++++++++++--------------
 include/hw/xen/xen.h |  3 ++-
 xen-hvm-stub.c       |  3 ++-
 xen-hvm.c            | 24 ++++++++++++++----------
 5 files changed, 49 insertions(+), 41 deletions(-)

diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 3e7524b..60057f9 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -99,21 +99,6 @@ static void pc_init1(MachineState *machine,
     FWCfgState *fw_cfg = NULL;
     PcGuestInfo *guest_info;
 
-    if (xen_enabled() && xen_hvm_init(&ram_memory) != 0) {
-        fprintf(stderr, "xen hardware virtual machine initialisation failed\n");
-        exit(1);
-    }
-
-    icc_bridge = qdev_create(NULL, TYPE_ICC_BRIDGE);
-    object_property_add_child(qdev_get_machine(), "icc-bridge",
-                              OBJECT(icc_bridge), NULL);
-
-    pc_cpus_init(machine->cpu_model, icc_bridge);
-
-    if (kvm_enabled() && kvmclock_enabled) {
-        kvmclock_create();
-    }
-
     /* Check whether RAM fits below 4G (leaving 1/2 GByte for IO memory).
      * If it doesn't, we need to split it in chunks below and above 4G.
      * In any case, try to make sure that guest addresses aligned at
@@ -130,6 +115,22 @@ static void pc_init1(MachineState *machine,
         below_4g_mem_size = machine->ram_size;
     }
 
+    if (xen_enabled() && xen_hvm_init(&below_4g_mem_size, &above_4g_mem_size,
+                                      &ram_memory) != 0) {
+        fprintf(stderr, "xen hardware virtual machine initialisation failed\n");
+        exit(1);
+    }
+
+    icc_bridge = qdev_create(NULL, TYPE_ICC_BRIDGE);
+    object_property_add_child(qdev_get_machine(), "icc-bridge",
+                              OBJECT(icc_bridge), NULL);
+
+    pc_cpus_init(machine->cpu_model, icc_bridge);
+
+    if (kvm_enabled() && kvmclock_enabled) {
+        kvmclock_create();
+    }
+
     if (pci_enabled) {
         pci_memory = g_new(MemoryRegion, 1);
         memory_region_init(pci_memory, NULL, "pci", UINT64_MAX);
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index aa71332..2cb743c 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -86,20 +86,6 @@ static void pc_q35_init(MachineState *machine)
     DeviceState *icc_bridge;
     PcGuestInfo *guest_info;
 
-    if (xen_enabled() && xen_hvm_init(&ram_memory) != 0) {
-        fprintf(stderr, "xen hardware virtual machine initialisation failed\n");
-        exit(1);
-    }
-
-    icc_bridge = qdev_create(NULL, TYPE_ICC_BRIDGE);
-    object_property_add_child(qdev_get_machine(), "icc-bridge",
-                              OBJECT(icc_bridge), NULL);
-
-    pc_cpus_init(machine->cpu_model, icc_bridge);
-    pc_acpi_init("q35-acpi-dsdt.aml");
-
-    kvmclock_create();
-
     /* Check whether RAM fits below 4G (leaving 1/2 GByte for IO memory
      * and 256 Mbytes for PCI Express Enhanced Configuration Access Mapping
      * also known as MMCFG).
@@ -118,6 +104,21 @@ static void pc_q35_init(MachineState *machine)
         below_4g_mem_size = machine->ram_size;
     }
 
+    if (xen_enabled() && xen_hvm_init(&below_4g_mem_size, &above_4g_mem_size,
+                                      &ram_memory) != 0) {
+        fprintf(stderr, "xen hardware virtual machine initialisation failed\n");
+        exit(1);
+    }
+
+    icc_bridge = qdev_create(NULL, TYPE_ICC_BRIDGE);
+    object_property_add_child(qdev_get_machine(), "icc-bridge",
+                              OBJECT(icc_bridge), NULL);
+
+    pc_cpus_init(machine->cpu_model, icc_bridge);
+    pc_acpi_init("q35-acpi-dsdt.aml");
+
+    kvmclock_create();
+
     /* pci enabled */
     if (pci_enabled) {
         pci_memory = g_new(MemoryRegion, 1);
diff --git a/include/hw/xen/xen.h b/include/hw/xen/xen.h
index 85fda3d..f71f2d8 100644
--- a/include/hw/xen/xen.h
+++ b/include/hw/xen/xen.h
@@ -37,10 +37,11 @@ void xen_cmos_set_s3_resume(void *opaque, int irq, int level);
 qemu_irq *xen_interrupt_controller_init(void);
 
 int xen_init(MachineClass *mc);
-int xen_hvm_init(MemoryRegion **ram_memory);
 void xenstore_store_pv_console_info(int i, struct CharDriverState *chr);
 
 #if defined(NEED_CPU_H) && !defined(CONFIG_USER_ONLY)
+int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,
+                 MemoryRegion **ram_memory);
 void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size,
                    struct MemoryRegion *mr);
 void xen_modified_memory(ram_addr_t start, ram_addr_t length);
diff --git a/xen-hvm-stub.c b/xen-hvm-stub.c
index 4eb27b5..2d98696 100644
--- a/xen-hvm-stub.c
+++ b/xen-hvm-stub.c
@@ -51,7 +51,8 @@ void xen_modified_memory(ram_addr_t start, ram_addr_t length)
 {
 }
 
-int xen_hvm_init(MemoryRegion **ram_memory)
+int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,
+                 MemoryRegion **ram_memory)
 {
     return 0;
 }
diff --git a/xen-hvm.c b/xen-hvm.c
index a64486c..a0b6b5d 100644
--- a/xen-hvm.c
+++ b/xen-hvm.c
@@ -155,10 +155,11 @@ qemu_irq *xen_interrupt_controller_init(void)
 
 /* Memory Ops */
 
-static void xen_ram_init(ram_addr_t ram_size, MemoryRegion **ram_memory_p)
+static void xen_ram_init(ram_addr_t *below_4g_mem_size,
+                         ram_addr_t *above_4g_mem_size,
+                         ram_addr_t ram_size, MemoryRegion **ram_memory_p)
 {
     MemoryRegion *sysmem = get_system_memory();
-    ram_addr_t below_4g_mem_size, above_4g_mem_size = 0;
     ram_addr_t block_len;
 
     block_len = ram_size;
@@ -173,10 +174,11 @@ static void xen_ram_init(ram_addr_t ram_size, MemoryRegion **ram_memory_p)
     vmstate_register_ram_global(&ram_memory);
 
     if (ram_size >= HVM_BELOW_4G_RAM_END) {
-        above_4g_mem_size = ram_size - HVM_BELOW_4G_RAM_END;
-        below_4g_mem_size = HVM_BELOW_4G_RAM_END;
+        *above_4g_mem_size = ram_size - HVM_BELOW_4G_RAM_END;
+        *below_4g_mem_size = HVM_BELOW_4G_RAM_END;
     } else {
-        below_4g_mem_size = ram_size;
+        *above_4g_mem_size = 0;
+        *below_4g_mem_size = ram_size;
     }
 
     memory_region_init_alias(&ram_640k, NULL, "xen.ram.640k",
@@ -189,12 +191,13 @@ static void xen_ram_init(ram_addr_t ram_size, MemoryRegion **ram_memory_p)
      * the Options ROM, so it is registered here as RAM.
      */
     memory_region_init_alias(&ram_lo, NULL, "xen.ram.lo",
-                             &ram_memory, 0xc0000, below_4g_mem_size - 0xc0000);
+                             &ram_memory, 0xc0000,
+                             *below_4g_mem_size - 0xc0000);
     memory_region_add_subregion(sysmem, 0xc0000, &ram_lo);
-    if (above_4g_mem_size > 0) {
+    if (*above_4g_mem_size > 0) {
         memory_region_init_alias(&ram_hi, NULL, "xen.ram.hi",
                                  &ram_memory, 0x100000000ULL,
-                                 above_4g_mem_size);
+                                 *above_4g_mem_size);
         memory_region_add_subregion(sysmem, 0x100000000ULL, &ram_hi);
     }
 }
@@ -958,7 +961,8 @@ static void xen_wakeup_notifier(Notifier *notifier, void *data)
     xc_set_hvm_param(xen_xc, xen_domid, HVM_PARAM_ACPI_S_STATE, 0);
 }
 
-int xen_hvm_init(MemoryRegion **ram_memory)
+int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,
+                 MemoryRegion **ram_memory)
 {
     int i, rc;
     unsigned long ioreq_pfn;
@@ -1036,7 +1040,7 @@ int xen_hvm_init(MemoryRegion **ram_memory)
 
     /* Init RAM management */
     xen_map_cache_init(xen_phys_offset_to_gaddr, state);
-    xen_ram_init(ram_size, ram_memory);
+    xen_ram_init(below_4g_mem_size, above_4g_mem_size, ram_size, ram_memory);
 
     qemu_add_vm_change_state_handler(xen_hvm_change_state_handler, state);
 
-- 
1.8.4

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

* [Qemu-devel] [PATCH 2.1 v7 2/3] pc & q35: Add new machine opt max-ram-below-4g
  2014-06-20  1:40 [Qemu-devel] [PATCH 2.1 v7 0/3] Add max-ram-below-4g (was Add pci_hole_min_size machine option) Don Slutz
  2014-06-20  1:40 ` [Qemu-devel] [PATCH 2.1 v7 1/3] xen-hvm: Fix xen_hvm_init() to adjust pc memory layout Don Slutz
@ 2014-06-20  1:40 ` Don Slutz
  2014-06-23 14:59   ` Michael S. Tsirkin
  2014-06-20  1:40 ` [Qemu-devel] [PATCH 2.1 v7 3/3] xen-hvm: Handle " Don Slutz
  2014-06-23 14:41 ` [Qemu-devel] [PATCH 2.1 v7 0/3] Add max-ram-below-4g (was Add pci_hole_min_size machine option) Michael S. Tsirkin
  3 siblings, 1 reply; 9+ messages in thread
From: Don Slutz @ 2014-06-20  1:40 UTC (permalink / raw)
  To: xen-devel, qemu-devel, Stefano Stabellini
  Cc: Marcel Apfelbaum, Michael S. Tsirkin, Don Slutz, Anthony Liguori,
	Igor Mammedov, Andreas Färber

This is a pc & q35 only machine opt.

If you add enough PCI devices then all mmio for them will not fit
below 4G which may not be the layout the user wanted. This allows
you to increase the below 4G address space that PCI devices can use
(aka decrease ram below 4G) and therefore in more cases not have any
mmio that is above 4G.

For example using "-machine pc,max-ram-below-4g=2G" on the command
line will limit the amount of ram that is below 4G to 2G.

Note: this machine option cannot be used to increase the amount
of ram below 4G.

Signed-off-by: Don Slutz <dslutz@verizon.com>
---
v7:
    Drop most of v5 to v6 changes.
    default: max-ram-below-4g=4g
    pc & q35:
       calculate lowmem
       lowmem = MIN(lowmem, max-ram-below-4g)
       calculate above_4g_mem_size and below_4g_mem_size
v6:
    Added setting of .default_machine_opts to include max-ram-below-4g
      for all pc types.
    Removed gigabyte_align
    Added warning on small value.
    "less then" to "less than"

v5:
    Re-work based on:

    https://github.com/imammedo/qemu/commits/memory-hotplug-v11


 hw/i386/pc.c         | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 hw/i386/pc_piix.c    | 22 +++++++++++++++++++++-
 hw/i386/pc_q35.c     | 22 +++++++++++++++++++++-
 include/hw/i386/pc.h |  3 +++
 vl.c                 |  4 ++++
 5 files changed, 96 insertions(+), 2 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index e993b0f..bc15761 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1647,11 +1647,58 @@ pc_machine_get_hotplug_memory_region_size(Object *obj, Visitor *v, void *opaque,
     visit_type_int(v, &value, name, errp);
 }
 
+static void pc_machine_get_max_ram_below_4g(Object *obj, Visitor *v,
+                                         void *opaque, const char *name,
+                                         Error **errp)
+{
+    PCMachineState *pcms = PC_MACHINE(obj);
+    uint64_t value = pcms->max_ram_below_4g;
+
+    visit_type_size(v, &value, name, errp);
+}
+
+static void pc_machine_set_max_ram_below_4g(Object *obj, Visitor *v,
+                                         void *opaque, const char *name,
+                                         Error **errp)
+{
+    PCMachineState *pcms = PC_MACHINE(obj);
+    Error *error = NULL;
+    uint64_t value;
+
+    visit_type_size(v, &value, name, &error);
+    if (error) {
+        error_propagate(errp, error);
+        return;
+    }
+    if (value > (1ULL << 32)) {
+        error_set(&error, ERROR_CLASS_GENERIC_ERROR,
+                  "Machine option 'max-ram-below-4g=%"PRIu64
+                  "' expects size less than or equal to 4G", value);
+        error_propagate(errp, error);
+        return;
+    }
+
+    if (value < (1ULL << 20)) {
+        error_report("Warning: small max_ram_below_4g(%"PRIu64
+                     ") less than 1M.  BIOS may not work..",
+                     value);
+    }
+
+    pcms->max_ram_below_4g = value;
+}
+
 static void pc_machine_initfn(Object *obj)
 {
+    PCMachineState *pcms = PC_MACHINE(obj);
+
     object_property_add(obj, PC_MACHINE_MEMHP_REGION_SIZE, "int",
                         pc_machine_get_hotplug_memory_region_size,
                         NULL, NULL, NULL, NULL);
+    pcms->max_ram_below_4g = 1UL << 32; /* 4G */
+    object_property_add(obj, PC_MACHINE_MAX_RAM_BELOW_4G, "size",
+                        pc_machine_get_max_ram_below_4g,
+                        pc_machine_set_max_ram_below_4g,
+                        NULL, NULL, NULL);
 }
 
 static void pc_machine_class_init(ObjectClass *oc, void *data)
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 60057f9..b4ce10e 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -48,6 +48,7 @@
 #include "exec/address-spaces.h"
 #include "hw/acpi/acpi.h"
 #include "cpu.h"
+#include "qemu/error-report.h"
 #ifdef CONFIG_XEN
 #  include <xen/hvm/hvm_info_table.h>
 #endif
@@ -98,6 +99,7 @@ static void pc_init1(MachineState *machine,
     DeviceState *icc_bridge;
     FWCfgState *fw_cfg = NULL;
     PcGuestInfo *guest_info;
+    ram_addr_t lowmem;
 
     /* Check whether RAM fits below 4G (leaving 1/2 GByte for IO memory).
      * If it doesn't, we need to split it in chunks below and above 4G.
@@ -107,7 +109,25 @@ static void pc_init1(MachineState *machine,
      * breaking migration.
      */
     if (machine->ram_size >= 0xe0000000) {
-        ram_addr_t lowmem = gigabyte_align ? 0xc0000000 : 0xe0000000;
+        lowmem = gigabyte_align ? 0xc0000000 : 0xe0000000;
+    } else {
+        lowmem = 0xe0000000;
+    }
+
+    /* Handle the machine opt max-ram-below-4g.  It is basicly doing
+     * min(qemu limit, user limit).
+     */
+    if (lowmem > pc_machine->max_ram_below_4g) {
+        lowmem = pc_machine->max_ram_below_4g;
+        if (machine->ram_size - lowmem > lowmem &&
+            lowmem & ((1ULL << 30) - 1)) {
+            error_report("Warning: Large machine and max_ram_below_4g(%"PRIu64
+                         ") not a multiple of 1G; possible bad performance.",
+                         pc_machine->max_ram_below_4g);
+        }
+    }
+
+    if (machine->ram_size >= lowmem) {
         above_4g_mem_size = machine->ram_size - lowmem;
         below_4g_mem_size = lowmem;
     } else {
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 2cb743c..c6d97ce 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -44,6 +44,7 @@
 #include "hw/ide/ahci.h"
 #include "hw/usb.h"
 #include "hw/cpu/icc_bus.h"
+#include "qemu/error-report.h"
 
 /* ICH9 AHCI has 6 ports */
 #define MAX_SATA_PORTS     6
@@ -85,6 +86,7 @@ static void pc_q35_init(MachineState *machine)
     PCIDevice *ahci;
     DeviceState *icc_bridge;
     PcGuestInfo *guest_info;
+    ram_addr_t lowmem;
 
     /* Check whether RAM fits below 4G (leaving 1/2 GByte for IO memory
      * and 256 Mbytes for PCI Express Enhanced Configuration Access Mapping
@@ -96,7 +98,25 @@ static void pc_q35_init(MachineState *machine)
      * breaking migration.
      */
     if (machine->ram_size >= 0xb0000000) {
-        ram_addr_t lowmem = gigabyte_align ? 0x80000000 : 0xb0000000;
+        lowmem = gigabyte_align ? 0x80000000 : 0xb0000000;
+    } else {
+        lowmem = 0xb0000000;
+    }
+
+    /* Handle the machine opt max-ram-below-4g.  It is basicly doing
+     * min(qemu limit, user limit).
+     */
+    if (lowmem > pc_machine->max_ram_below_4g) {
+        lowmem = pc_machine->max_ram_below_4g;
+        if (machine->ram_size - lowmem > lowmem &&
+            lowmem & ((1ULL << 30) - 1)) {
+            error_report("Warning: Large machine and max_ram_below_4g(%"PRIu64
+                         ") not a multiple of 1G; possible bad performance.",
+                         pc_machine->max_ram_below_4g);
+        }
+    }
+
+    if (machine->ram_size >= lowmem) {
         above_4g_mem_size = machine->ram_size - lowmem;
         below_4g_mem_size = lowmem;
     } else {
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 76d4c6e..f5672ee 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -33,10 +33,13 @@ struct PCMachineState {
     MemoryRegion hotplug_memory;
 
     HotplugHandler *acpi_dev;
+
+    uint64_t max_ram_below_4g;
 };
 
 #define PC_MACHINE_ACPI_DEVICE_PROP "acpi-device"
 #define PC_MACHINE_MEMHP_REGION_SIZE "hotplug-memory-region-size"
+#define PC_MACHINE_MAX_RAM_BELOW_4G "max-ram-below-4g"
 
 /**
  * PCMachineClass:
diff --git a/vl.c b/vl.c
index 1617013..27c60eb 100644
--- a/vl.c
+++ b/vl.c
@@ -381,6 +381,10 @@ static QemuOptsList qemu_machine_opts = {
             .name = "kvm-type",
             .type = QEMU_OPT_STRING,
             .help = "Specifies the KVM virtualization mode (HV, PR)",
+        },{
+            .name = PC_MACHINE_MAX_RAM_BELOW_4G,
+            .type = QEMU_OPT_SIZE,
+            .help = "maximum ram below the 4G boundary (32bit boundary)",
         },
         { /* End of list */ }
     },
-- 
1.8.4

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

* [Qemu-devel] [PATCH 2.1 v7 3/3] xen-hvm: Handle machine opt max-ram-below-4g
  2014-06-20  1:40 [Qemu-devel] [PATCH 2.1 v7 0/3] Add max-ram-below-4g (was Add pci_hole_min_size machine option) Don Slutz
  2014-06-20  1:40 ` [Qemu-devel] [PATCH 2.1 v7 1/3] xen-hvm: Fix xen_hvm_init() to adjust pc memory layout Don Slutz
  2014-06-20  1:40 ` [Qemu-devel] [PATCH 2.1 v7 2/3] pc & q35: Add new machine opt max-ram-below-4g Don Slutz
@ 2014-06-20  1:40 ` Don Slutz
  2014-06-20 12:21   ` Stefano Stabellini
  2014-06-23 14:41 ` [Qemu-devel] [PATCH 2.1 v7 0/3] Add max-ram-below-4g (was Add pci_hole_min_size machine option) Michael S. Tsirkin
  3 siblings, 1 reply; 9+ messages in thread
From: Don Slutz @ 2014-06-20  1:40 UTC (permalink / raw)
  To: xen-devel, qemu-devel, Stefano Stabellini
  Cc: Marcel Apfelbaum, Michael S. Tsirkin, Don Slutz, Anthony Liguori,
	Igor Mammedov, Andreas Färber

This is the xen part of "pc & q35: Add new machine opt max-ram-below-4g"

Note: this machine option cannot be used to increase the amount
of ram below 4G.

Signed-off-by: Don Slutz <dslutz@verizon.com>
---
v7:
     Rename from "xen-hvm: Pass is_default to xen_hvm_init"
     Drop is_default.
     Use object_property_get_int() to get max-ram-below-4g.
     Do min(xen limit, user limit).
v6:
    Changed to work with the changes in #2:
      Added max_ram_below_4g_changed in order to know if it is a default value
      or a user specified one.
    Added "assert(pc_machine->max_ram_below_4g_changed > 0)" so that
      "make check" will abort on default not set for any of the pc or
      q35 machine types.
    Dropped "Acked-by: Stefano Stabellin" do to bigger change.

 xen-hvm.c | 35 +++++++++++++++++++++++------------
 1 file changed, 23 insertions(+), 12 deletions(-)

diff --git a/xen-hvm.c b/xen-hvm.c
index a0b6b5d..2745a7a 100644
--- a/xen-hvm.c
+++ b/xen-hvm.c
@@ -161,25 +161,36 @@ static void xen_ram_init(ram_addr_t *below_4g_mem_size,
 {
     MemoryRegion *sysmem = get_system_memory();
     ram_addr_t block_len;
+    uint64_t user_lowmem = object_property_get_int(qdev_get_machine(),
+                                                   PC_MACHINE_MAX_RAM_BELOW_4G,
+                                                   &error_abort);
 
-    block_len = ram_size;
-    if (ram_size >= HVM_BELOW_4G_RAM_END) {
-        /* Xen does not allocate the memory continuously, and keep a hole at
-         * HVM_BELOW_4G_MMIO_START of HVM_BELOW_4G_MMIO_LENGTH
-         */
-        block_len += HVM_BELOW_4G_MMIO_LENGTH;
+    /* Handle the machine opt max-ram-below-4g.  It is basicly doing
+     * min(xen limit, user limit).
+     */
+    if (HVM_BELOW_4G_RAM_END <= user_lowmem) {
+        user_lowmem = HVM_BELOW_4G_RAM_END;
     }
-    memory_region_init_ram(&ram_memory, NULL, "xen.ram", block_len);
-    *ram_memory_p = &ram_memory;
-    vmstate_register_ram_global(&ram_memory);
 
-    if (ram_size >= HVM_BELOW_4G_RAM_END) {
-        *above_4g_mem_size = ram_size - HVM_BELOW_4G_RAM_END;
-        *below_4g_mem_size = HVM_BELOW_4G_RAM_END;
+    if (ram_size >= user_lowmem) {
+        *above_4g_mem_size = ram_size - user_lowmem;
+        *below_4g_mem_size = user_lowmem;
     } else {
         *above_4g_mem_size = 0;
         *below_4g_mem_size = ram_size;
     }
+    if (!*above_4g_mem_size) {
+        block_len = ram_size;
+    } else {
+        /*
+         * Xen does not allocate the memory continuously, it keeps a
+         * hole of the size computed above or passed in.
+         */
+        block_len = (1ULL << 32) + *above_4g_mem_size;
+    }
+    memory_region_init_ram(&ram_memory, NULL, "xen.ram", block_len);
+    *ram_memory_p = &ram_memory;
+    vmstate_register_ram_global(&ram_memory);
 
     memory_region_init_alias(&ram_640k, NULL, "xen.ram.640k",
                              &ram_memory, 0, 0xa0000);
-- 
1.8.4

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

* Re: [Qemu-devel] [PATCH 2.1 v7 3/3] xen-hvm: Handle machine opt max-ram-below-4g
  2014-06-20  1:40 ` [Qemu-devel] [PATCH 2.1 v7 3/3] xen-hvm: Handle " Don Slutz
@ 2014-06-20 12:21   ` Stefano Stabellini
  0 siblings, 0 replies; 9+ messages in thread
From: Stefano Stabellini @ 2014-06-20 12:21 UTC (permalink / raw)
  To: Don Slutz
  Cc: xen-devel, Michael S. Tsirkin, Stefano Stabellini, qemu-devel,
	Anthony Liguori, Igor Mammedov, Marcel Apfelbaum,
	Andreas Färber

On Thu, 19 Jun 2014, Don Slutz wrote:
> This is the xen part of "pc & q35: Add new machine opt max-ram-below-4g"
> 
> Note: this machine option cannot be used to increase the amount
> of ram below 4G.
> 
> Signed-off-by: Don Slutz <dslutz@verizon.com>

It is still good for me.

> v7:
>      Rename from "xen-hvm: Pass is_default to xen_hvm_init"
>      Drop is_default.
>      Use object_property_get_int() to get max-ram-below-4g.
>      Do min(xen limit, user limit).
> v6:
>     Changed to work with the changes in #2:
>       Added max_ram_below_4g_changed in order to know if it is a default value
>       or a user specified one.
>     Added "assert(pc_machine->max_ram_below_4g_changed > 0)" so that
>       "make check" will abort on default not set for any of the pc or
>       q35 machine types.
>     Dropped "Acked-by: Stefano Stabellin" do to bigger change.
> 
>  xen-hvm.c | 35 +++++++++++++++++++++++------------
>  1 file changed, 23 insertions(+), 12 deletions(-)
> 
> diff --git a/xen-hvm.c b/xen-hvm.c
> index a0b6b5d..2745a7a 100644
> --- a/xen-hvm.c
> +++ b/xen-hvm.c
> @@ -161,25 +161,36 @@ static void xen_ram_init(ram_addr_t *below_4g_mem_size,
>  {
>      MemoryRegion *sysmem = get_system_memory();
>      ram_addr_t block_len;
> +    uint64_t user_lowmem = object_property_get_int(qdev_get_machine(),
> +                                                   PC_MACHINE_MAX_RAM_BELOW_4G,
> +                                                   &error_abort);
>  
> -    block_len = ram_size;
> -    if (ram_size >= HVM_BELOW_4G_RAM_END) {
> -        /* Xen does not allocate the memory continuously, and keep a hole at
> -         * HVM_BELOW_4G_MMIO_START of HVM_BELOW_4G_MMIO_LENGTH
> -         */
> -        block_len += HVM_BELOW_4G_MMIO_LENGTH;
> +    /* Handle the machine opt max-ram-below-4g.  It is basicly doing
> +     * min(xen limit, user limit).
> +     */
> +    if (HVM_BELOW_4G_RAM_END <= user_lowmem) {
> +        user_lowmem = HVM_BELOW_4G_RAM_END;
>      }
> -    memory_region_init_ram(&ram_memory, NULL, "xen.ram", block_len);
> -    *ram_memory_p = &ram_memory;
> -    vmstate_register_ram_global(&ram_memory);
>  
> -    if (ram_size >= HVM_BELOW_4G_RAM_END) {
> -        *above_4g_mem_size = ram_size - HVM_BELOW_4G_RAM_END;
> -        *below_4g_mem_size = HVM_BELOW_4G_RAM_END;
> +    if (ram_size >= user_lowmem) {
> +        *above_4g_mem_size = ram_size - user_lowmem;
> +        *below_4g_mem_size = user_lowmem;
>      } else {
>          *above_4g_mem_size = 0;
>          *below_4g_mem_size = ram_size;
>      }
> +    if (!*above_4g_mem_size) {
> +        block_len = ram_size;
> +    } else {
> +        /*
> +         * Xen does not allocate the memory continuously, it keeps a
> +         * hole of the size computed above or passed in.
> +         */
> +        block_len = (1ULL << 32) + *above_4g_mem_size;
> +    }
> +    memory_region_init_ram(&ram_memory, NULL, "xen.ram", block_len);
> +    *ram_memory_p = &ram_memory;
> +    vmstate_register_ram_global(&ram_memory);
>  
>      memory_region_init_alias(&ram_640k, NULL, "xen.ram.640k",
>                               &ram_memory, 0, 0xa0000);
> -- 
> 1.8.4
> 

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

* Re: [Qemu-devel] [PATCH 2.1 v7 0/3] Add max-ram-below-4g (was Add pci_hole_min_size machine option)
  2014-06-20  1:40 [Qemu-devel] [PATCH 2.1 v7 0/3] Add max-ram-below-4g (was Add pci_hole_min_size machine option) Don Slutz
                   ` (2 preceding siblings ...)
  2014-06-20  1:40 ` [Qemu-devel] [PATCH 2.1 v7 3/3] xen-hvm: Handle " Don Slutz
@ 2014-06-23 14:41 ` Michael S. Tsirkin
  2014-06-23 14:53   ` Stefano Stabellini
  3 siblings, 1 reply; 9+ messages in thread
From: Michael S. Tsirkin @ 2014-06-23 14:41 UTC (permalink / raw)
  To: Don Slutz
  Cc: xen-devel, Stefano Stabellini, Marcel Apfelbaum, qemu-devel,
	Anthony Liguori, Igor Mammedov, Andreas Färber

On Thu, Jun 19, 2014 at 09:40:23PM -0400, Don Slutz wrote:
> Changes v6 to v7:
>   Drop most of v5 to v6 changes.
> 
>   Michael S. Tsirkin:
>     #2 "pc & q35: Add new machine opt max-ram-below-4g":
>        default: max-ram-below-4g=4g
>        pc & q35:
>           calculate lowmem
>           lowmem = MIN(lowmem, max-ram-below-4g)
>           calculate above_4g_mem_size and below_4g_mem_size
> 
>   #3 "xen-hvm: Handle machine opt max-ram-below-4g":
>      Rename from "xen-hvm: Pass is_default to xen_hvm_init"
>      Drop is_default.
>      Use object_property_get_int() to get max-ram-below-4g.
>      Do min(xen limit, user limit).
> 


Applied, thanks!

> Changes v5 to v6:
>   rebased on git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git pci
> 
>   Changed default handling.  Most pc machines are now set to 3.5G
>   (0xe0000000) and q35 are set to 2.75G (0xb0000000).  The special
>   value of 0 is used to flag the complex gigabyte_align memory
>   layout selection.
> 
>   I did change the default for pc-i440fx-2.1 to 3G and pc-q35-2.1 to
>   2G instead of the complex gigabyte_align.  This looks ok to me
>   because the statement by Gerd Hoffmann is about more ram for 32
>   bit (+non-PAE) guests can now have more then the defualt by
>   specifing the new option like "max-ram-below-4g=3.75G" or
>   "max-ram-below-4g=3.9375G".  Or if that is too complex to
>   understand just select pc-i440fx-2.0 or pc-q35-2.0 to get what
>   they use to get.
> 
>   Michael S. Tsirkin, Igor Mammedov, Marcel Apfelbaum:
>     #2 "pc & q35: Add new machine opt max-ram-below-4g":
>        Added setting of .default_machine_opts to include max-ram-below-4g
>          for all pc types.
>        Removed gigabyte_align.
>        Added warning on small value.
>        "less then" to "less than"
> 
>   #3 "xen-hvm: Pass is_default to xen_hvm_init":
>     Changed to work with the changes in #2:
>       Added max_ram_below_4g_changed in order to know if it is a default value
>       or a user specified one.
>     Added "assert(pc_machine->max_ram_below_4g_changed > 0)" so that
>       "make check" will abort on default not set for any of the pc or
>       q35 machine types.
>     Dropped "Acked-by: Stefano Stabellin" do to bigger change.
> 
> 
> Changes v4 to v5:
>   Re-work based on:
> 
>   https://github.com/imammedo/qemu/commits/memory-hotplug-v11
> 
>   And so it now depends on this patch set.
> 
>   Stefano Stabellini:
>     #3 "xen-hvm: Pass is_default to xen_hvm_init"
>       Acked-by 
>       Minor change of pmc to pcms.
> 
> Changes v3 to v4:
>   Split out #2 "GlobalProperty: Display warning about unused -global"
>   rebase on e00fcfe (origin/master)
>   rename xen-all to xen-hvm
> 
>   Adjust #1 "xen-hvm: Fix xen_hvm_init() to adjust pc memory layout"
>     Switch Acked-by & Signed-off-by
>     rebase on master
> 
>   Rework #3 "xen-hvm: Pass is_default to xen_hvm_init":
>     To pass is_default instead of max_ram_below_4g.
>     Also did not add "Acked-by: Stefano Stabellini" since code changed a lot.
> 
>   Andreas Färber:
>     all: Remove dot at end of subject
>     #3 "xen-hvm: Pass is_default to xen_hvm_init"
>       Adjust comment formatting.
> 
>   Andreas Färber, Paolo Bonzini, Marcel Apfelbaum:
>     rework to use "opts per machine"
>     Drop old #3, new #2.
>   
> 
> Changes v2 to v3:
>   Stefano Stabellini:
>     Acked-by #1 "xen-all: Fix xen_hvm_init() to adjust pc memory"
>     Adjust for code readability #4 "xen-all: Pass max_ram_below_4g to xen_hvm_init."
>        Set max_ram_below_4g always and use it to calculate above_4g_mem_size,
>        below_4g_mem_size.
> 
> Changes v1 to v2:
>   Michael S. Tsirkin:
>     Rename option.
>     Only add it to machine types that support it.
>   Split into 4 parts.
> 
> 1/4 -- xen-all: Fix xen_hvm_init() to adjust pc memory layout
> 
>   This looks to be a possible bug that has yet to be found.
>   below_4g_mem_size and above_4g_mem_size are stored in PcGuestInfo
>   (pc_guest_info_init) which are currently not "correct".  This and
>   4/4 change the same lines.
> 
> 2/4 -- GlobalProperty: Display warning about unused -global
> 
>     My testing showed that setting a global property on an object
>     that is not used is not reported at all.  This is added to help
>     when the new global is set but not used.  The negative not_used
>     was picked so that all static objects are assumed to be used
>     even when they are not.
> 
> 3/4 -- pc & q35: Add new object pc-memory-layout
> 
>   The objects that it might make sense to add this property to all
>   get created too late.  So add a new object just to hold this
>   property.  Name it so that it is expected that only pc (and q35)
>   machine types support it.
> 
> 4/4 -- xen-all: Pass max_ram_below_4g to xen_hvm_init
> 
>   Seprate the xen only part of the change.  Currectly based on patch 1/4
> 
> Don Slutz (3):
>   xen-hvm: Fix xen_hvm_init() to adjust pc memory layout
>   pc & q35: Add new machine opt max-ram-below-4g
>   xen-hvm: Handle machine opt max-ram-below-4g
> 
>  hw/i386/pc.c         | 47 ++++++++++++++++++++++++++++++++++++++++++++++
>  hw/i386/pc_piix.c    | 53 ++++++++++++++++++++++++++++++++++++----------------
>  hw/i386/pc_q35.c     | 51 +++++++++++++++++++++++++++++++++++---------------
>  include/hw/i386/pc.h |  3 +++
>  include/hw/xen/xen.h |  3 ++-
>  vl.c                 |  4 ++++
>  xen-hvm-stub.c       |  3 ++-
>  xen-hvm.c            | 53 +++++++++++++++++++++++++++++++++-------------------
>  8 files changed, 165 insertions(+), 52 deletions(-)
> 
> -- 
> 1.8.4

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

* Re: [Qemu-devel] [PATCH 2.1 v7 0/3] Add max-ram-below-4g (was Add pci_hole_min_size machine option)
  2014-06-23 14:41 ` [Qemu-devel] [PATCH 2.1 v7 0/3] Add max-ram-below-4g (was Add pci_hole_min_size machine option) Michael S. Tsirkin
@ 2014-06-23 14:53   ` Stefano Stabellini
  0 siblings, 0 replies; 9+ messages in thread
From: Stefano Stabellini @ 2014-06-23 14:53 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: xen-devel, Stefano Stabellini, Marcel Apfelbaum, qemu-devel,
	Don Slutz, Anthony Liguori, Igor Mammedov, Andreas Färber

[-- Attachment #1: Type: text/plain, Size: 6096 bytes --]

On Mon, 23 Jun 2014, Michael S. Tsirkin wrote:
> On Thu, Jun 19, 2014 at 09:40:23PM -0400, Don Slutz wrote:
> > Changes v6 to v7:
> >   Drop most of v5 to v6 changes.
> > 
> >   Michael S. Tsirkin:
> >     #2 "pc & q35: Add new machine opt max-ram-below-4g":
> >        default: max-ram-below-4g=4g
> >        pc & q35:
> >           calculate lowmem
> >           lowmem = MIN(lowmem, max-ram-below-4g)
> >           calculate above_4g_mem_size and below_4g_mem_size
> > 
> >   #3 "xen-hvm: Handle machine opt max-ram-below-4g":
> >      Rename from "xen-hvm: Pass is_default to xen_hvm_init"
> >      Drop is_default.
> >      Use object_property_get_int() to get max-ram-below-4g.
> >      Do min(xen limit, user limit).
> > 
> 
> 
> Applied, thanks!

Thanks, Michael.


> > Changes v5 to v6:
> >   rebased on git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git pci
> > 
> >   Changed default handling.  Most pc machines are now set to 3.5G
> >   (0xe0000000) and q35 are set to 2.75G (0xb0000000).  The special
> >   value of 0 is used to flag the complex gigabyte_align memory
> >   layout selection.
> > 
> >   I did change the default for pc-i440fx-2.1 to 3G and pc-q35-2.1 to
> >   2G instead of the complex gigabyte_align.  This looks ok to me
> >   because the statement by Gerd Hoffmann is about more ram for 32
> >   bit (+non-PAE) guests can now have more then the defualt by
> >   specifing the new option like "max-ram-below-4g=3.75G" or
> >   "max-ram-below-4g=3.9375G".  Or if that is too complex to
> >   understand just select pc-i440fx-2.0 or pc-q35-2.0 to get what
> >   they use to get.
> > 
> >   Michael S. Tsirkin, Igor Mammedov, Marcel Apfelbaum:
> >     #2 "pc & q35: Add new machine opt max-ram-below-4g":
> >        Added setting of .default_machine_opts to include max-ram-below-4g
> >          for all pc types.
> >        Removed gigabyte_align.
> >        Added warning on small value.
> >        "less then" to "less than"
> > 
> >   #3 "xen-hvm: Pass is_default to xen_hvm_init":
> >     Changed to work with the changes in #2:
> >       Added max_ram_below_4g_changed in order to know if it is a default value
> >       or a user specified one.
> >     Added "assert(pc_machine->max_ram_below_4g_changed > 0)" so that
> >       "make check" will abort on default not set for any of the pc or
> >       q35 machine types.
> >     Dropped "Acked-by: Stefano Stabellin" do to bigger change.
> > 
> > 
> > Changes v4 to v5:
> >   Re-work based on:
> > 
> >   https://github.com/imammedo/qemu/commits/memory-hotplug-v11
> > 
> >   And so it now depends on this patch set.
> > 
> >   Stefano Stabellini:
> >     #3 "xen-hvm: Pass is_default to xen_hvm_init"
> >       Acked-by 
> >       Minor change of pmc to pcms.
> > 
> > Changes v3 to v4:
> >   Split out #2 "GlobalProperty: Display warning about unused -global"
> >   rebase on e00fcfe (origin/master)
> >   rename xen-all to xen-hvm
> > 
> >   Adjust #1 "xen-hvm: Fix xen_hvm_init() to adjust pc memory layout"
> >     Switch Acked-by & Signed-off-by
> >     rebase on master
> > 
> >   Rework #3 "xen-hvm: Pass is_default to xen_hvm_init":
> >     To pass is_default instead of max_ram_below_4g.
> >     Also did not add "Acked-by: Stefano Stabellini" since code changed a lot.
> > 
> >   Andreas Färber:
> >     all: Remove dot at end of subject
> >     #3 "xen-hvm: Pass is_default to xen_hvm_init"
> >       Adjust comment formatting.
> > 
> >   Andreas Färber, Paolo Bonzini, Marcel Apfelbaum:
> >     rework to use "opts per machine"
> >     Drop old #3, new #2.
> >   
> > 
> > Changes v2 to v3:
> >   Stefano Stabellini:
> >     Acked-by #1 "xen-all: Fix xen_hvm_init() to adjust pc memory"
> >     Adjust for code readability #4 "xen-all: Pass max_ram_below_4g to xen_hvm_init."
> >        Set max_ram_below_4g always and use it to calculate above_4g_mem_size,
> >        below_4g_mem_size.
> > 
> > Changes v1 to v2:
> >   Michael S. Tsirkin:
> >     Rename option.
> >     Only add it to machine types that support it.
> >   Split into 4 parts.
> > 
> > 1/4 -- xen-all: Fix xen_hvm_init() to adjust pc memory layout
> > 
> >   This looks to be a possible bug that has yet to be found.
> >   below_4g_mem_size and above_4g_mem_size are stored in PcGuestInfo
> >   (pc_guest_info_init) which are currently not "correct".  This and
> >   4/4 change the same lines.
> > 
> > 2/4 -- GlobalProperty: Display warning about unused -global
> > 
> >     My testing showed that setting a global property on an object
> >     that is not used is not reported at all.  This is added to help
> >     when the new global is set but not used.  The negative not_used
> >     was picked so that all static objects are assumed to be used
> >     even when they are not.
> > 
> > 3/4 -- pc & q35: Add new object pc-memory-layout
> > 
> >   The objects that it might make sense to add this property to all
> >   get created too late.  So add a new object just to hold this
> >   property.  Name it so that it is expected that only pc (and q35)
> >   machine types support it.
> > 
> > 4/4 -- xen-all: Pass max_ram_below_4g to xen_hvm_init
> > 
> >   Seprate the xen only part of the change.  Currectly based on patch 1/4
> > 
> > Don Slutz (3):
> >   xen-hvm: Fix xen_hvm_init() to adjust pc memory layout
> >   pc & q35: Add new machine opt max-ram-below-4g
> >   xen-hvm: Handle machine opt max-ram-below-4g
> > 
> >  hw/i386/pc.c         | 47 ++++++++++++++++++++++++++++++++++++++++++++++
> >  hw/i386/pc_piix.c    | 53 ++++++++++++++++++++++++++++++++++++----------------
> >  hw/i386/pc_q35.c     | 51 +++++++++++++++++++++++++++++++++++---------------
> >  include/hw/i386/pc.h |  3 +++
> >  include/hw/xen/xen.h |  3 ++-
> >  vl.c                 |  4 ++++
> >  xen-hvm-stub.c       |  3 ++-
> >  xen-hvm.c            | 53 +++++++++++++++++++++++++++++++++-------------------
> >  8 files changed, 165 insertions(+), 52 deletions(-)
> > 
> > -- 
> > 1.8.4
> 

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

* Re: [Qemu-devel] [PATCH 2.1 v7 2/3] pc & q35: Add new machine opt max-ram-below-4g
  2014-06-20  1:40 ` [Qemu-devel] [PATCH 2.1 v7 2/3] pc & q35: Add new machine opt max-ram-below-4g Don Slutz
@ 2014-06-23 14:59   ` Michael S. Tsirkin
  2014-06-23 17:49     ` Don Slutz
  0 siblings, 1 reply; 9+ messages in thread
From: Michael S. Tsirkin @ 2014-06-23 14:59 UTC (permalink / raw)
  To: Don Slutz
  Cc: xen-devel, Stefano Stabellini, Marcel Apfelbaum, qemu-devel,
	Anthony Liguori, Igor Mammedov, Andreas Färber

On Thu, Jun 19, 2014 at 09:40:25PM -0400, Don Slutz wrote:
> This is a pc & q35 only machine opt.
> 
> If you add enough PCI devices then all mmio for them will not fit
> below 4G which may not be the layout the user wanted. This allows
> you to increase the below 4G address space that PCI devices can use
> (aka decrease ram below 4G) and therefore in more cases not have any
> mmio that is above 4G.
> 
> For example using "-machine pc,max-ram-below-4g=2G" on the command
> line will limit the amount of ram that is below 4G to 2G.
> 
> Note: this machine option cannot be used to increase the amount
> of ram below 4G.
> 
> Signed-off-by: Don Slutz <dslutz@verizon.com>
> ---
> v7:
>     Drop most of v5 to v6 changes.
>     default: max-ram-below-4g=4g
>     pc & q35:
>        calculate lowmem
>        lowmem = MIN(lowmem, max-ram-below-4g)
>        calculate above_4g_mem_size and below_4g_mem_size
> v6:
>     Added setting of .default_machine_opts to include max-ram-below-4g
>       for all pc types.
>     Removed gigabyte_align
>     Added warning on small value.
>     "less then" to "less than"
> 
> v5:
>     Re-work based on:
> 
>     https://github.com/imammedo/qemu/commits/memory-hotplug-v11
> 
> 
>  hw/i386/pc.c         | 47 +++++++++++++++++++++++++++++++++++++++++++++++
>  hw/i386/pc_piix.c    | 22 +++++++++++++++++++++-
>  hw/i386/pc_q35.c     | 22 +++++++++++++++++++++-
>  include/hw/i386/pc.h |  3 +++
>  vl.c                 |  4 ++++
>  5 files changed, 96 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/i386/pc.c b/hw/i386/pc.c
> index e993b0f..bc15761 100644
> --- a/hw/i386/pc.c
> +++ b/hw/i386/pc.c
> @@ -1647,11 +1647,58 @@ pc_machine_get_hotplug_memory_region_size(Object *obj, Visitor *v, void *opaque,
>      visit_type_int(v, &value, name, errp);
>  }
>  
> +static void pc_machine_get_max_ram_below_4g(Object *obj, Visitor *v,
> +                                         void *opaque, const char *name,
> +                                         Error **errp)
> +{
> +    PCMachineState *pcms = PC_MACHINE(obj);
> +    uint64_t value = pcms->max_ram_below_4g;
> +
> +    visit_type_size(v, &value, name, errp);
> +}
> +
> +static void pc_machine_set_max_ram_below_4g(Object *obj, Visitor *v,
> +                                         void *opaque, const char *name,
> +                                         Error **errp)
> +{
> +    PCMachineState *pcms = PC_MACHINE(obj);
> +    Error *error = NULL;
> +    uint64_t value;
> +
> +    visit_type_size(v, &value, name, &error);
> +    if (error) {
> +        error_propagate(errp, error);
> +        return;
> +    }
> +    if (value > (1ULL << 32)) {
> +        error_set(&error, ERROR_CLASS_GENERIC_ERROR,
> +                  "Machine option 'max-ram-below-4g=%"PRIu64
> +                  "' expects size less than or equal to 4G", value);
> +        error_propagate(errp, error);
> +        return;
> +    }
> +
> +    if (value < (1ULL << 20)) {
> +        error_report("Warning: small max_ram_below_4g(%"PRIu64
> +                     ") less than 1M.  BIOS may not work..",
> +                     value);
> +    }
> +
> +    pcms->max_ram_below_4g = value;
> +}
> +
>  static void pc_machine_initfn(Object *obj)
>  {
> +    PCMachineState *pcms = PC_MACHINE(obj);
> +
>      object_property_add(obj, PC_MACHINE_MEMHP_REGION_SIZE, "int",
>                          pc_machine_get_hotplug_memory_region_size,
>                          NULL, NULL, NULL, NULL);
> +    pcms->max_ram_below_4g = 1UL << 32; /* 4G */

This is a bug: should be 1ULL. Fixed it up locally.

> +    object_property_add(obj, PC_MACHINE_MAX_RAM_BELOW_4G, "size",
> +                        pc_machine_get_max_ram_below_4g,
> +                        pc_machine_set_max_ram_below_4g,
> +                        NULL, NULL, NULL);
>  }
>  
>  static void pc_machine_class_init(ObjectClass *oc, void *data)
> diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
> index 60057f9..b4ce10e 100644
> --- a/hw/i386/pc_piix.c
> +++ b/hw/i386/pc_piix.c
> @@ -48,6 +48,7 @@
>  #include "exec/address-spaces.h"
>  #include "hw/acpi/acpi.h"
>  #include "cpu.h"
> +#include "qemu/error-report.h"
>  #ifdef CONFIG_XEN
>  #  include <xen/hvm/hvm_info_table.h>
>  #endif
> @@ -98,6 +99,7 @@ static void pc_init1(MachineState *machine,
>      DeviceState *icc_bridge;
>      FWCfgState *fw_cfg = NULL;
>      PcGuestInfo *guest_info;
> +    ram_addr_t lowmem;
>  
>      /* Check whether RAM fits below 4G (leaving 1/2 GByte for IO memory).
>       * If it doesn't, we need to split it in chunks below and above 4G.
> @@ -107,7 +109,25 @@ static void pc_init1(MachineState *machine,
>       * breaking migration.
>       */
>      if (machine->ram_size >= 0xe0000000) {
> -        ram_addr_t lowmem = gigabyte_align ? 0xc0000000 : 0xe0000000;
> +        lowmem = gigabyte_align ? 0xc0000000 : 0xe0000000;
> +    } else {
> +        lowmem = 0xe0000000;
> +    }
> +
> +    /* Handle the machine opt max-ram-below-4g.  It is basicly doing
> +     * min(qemu limit, user limit).
> +     */
> +    if (lowmem > pc_machine->max_ram_below_4g) {
> +        lowmem = pc_machine->max_ram_below_4g;
> +        if (machine->ram_size - lowmem > lowmem &&
> +            lowmem & ((1ULL << 30) - 1)) {
> +            error_report("Warning: Large machine and max_ram_below_4g(%"PRIu64
> +                         ") not a multiple of 1G; possible bad performance.",
> +                         pc_machine->max_ram_below_4g);
> +        }
> +    }
> +
> +    if (machine->ram_size >= lowmem) {
>          above_4g_mem_size = machine->ram_size - lowmem;
>          below_4g_mem_size = lowmem;
>      } else {
> diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
> index 2cb743c..c6d97ce 100644
> --- a/hw/i386/pc_q35.c
> +++ b/hw/i386/pc_q35.c
> @@ -44,6 +44,7 @@
>  #include "hw/ide/ahci.h"
>  #include "hw/usb.h"
>  #include "hw/cpu/icc_bus.h"
> +#include "qemu/error-report.h"
>  
>  /* ICH9 AHCI has 6 ports */
>  #define MAX_SATA_PORTS     6
> @@ -85,6 +86,7 @@ static void pc_q35_init(MachineState *machine)
>      PCIDevice *ahci;
>      DeviceState *icc_bridge;
>      PcGuestInfo *guest_info;
> +    ram_addr_t lowmem;
>  
>      /* Check whether RAM fits below 4G (leaving 1/2 GByte for IO memory
>       * and 256 Mbytes for PCI Express Enhanced Configuration Access Mapping
> @@ -96,7 +98,25 @@ static void pc_q35_init(MachineState *machine)
>       * breaking migration.
>       */
>      if (machine->ram_size >= 0xb0000000) {
> -        ram_addr_t lowmem = gigabyte_align ? 0x80000000 : 0xb0000000;
> +        lowmem = gigabyte_align ? 0x80000000 : 0xb0000000;
> +    } else {
> +        lowmem = 0xb0000000;
> +    }
> +
> +    /* Handle the machine opt max-ram-below-4g.  It is basicly doing
> +     * min(qemu limit, user limit).
> +     */
> +    if (lowmem > pc_machine->max_ram_below_4g) {
> +        lowmem = pc_machine->max_ram_below_4g;
> +        if (machine->ram_size - lowmem > lowmem &&
> +            lowmem & ((1ULL << 30) - 1)) {
> +            error_report("Warning: Large machine and max_ram_below_4g(%"PRIu64
> +                         ") not a multiple of 1G; possible bad performance.",
> +                         pc_machine->max_ram_below_4g);
> +        }
> +    }
> +
> +    if (machine->ram_size >= lowmem) {
>          above_4g_mem_size = machine->ram_size - lowmem;
>          below_4g_mem_size = lowmem;
>      } else {
> diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
> index 76d4c6e..f5672ee 100644
> --- a/include/hw/i386/pc.h
> +++ b/include/hw/i386/pc.h
> @@ -33,10 +33,13 @@ struct PCMachineState {
>      MemoryRegion hotplug_memory;
>  
>      HotplugHandler *acpi_dev;
> +
> +    uint64_t max_ram_below_4g;
>  };
>  
>  #define PC_MACHINE_ACPI_DEVICE_PROP "acpi-device"
>  #define PC_MACHINE_MEMHP_REGION_SIZE "hotplug-memory-region-size"
> +#define PC_MACHINE_MAX_RAM_BELOW_4G "max-ram-below-4g"
>  
>  /**
>   * PCMachineClass:
> diff --git a/vl.c b/vl.c
> index 1617013..27c60eb 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -381,6 +381,10 @@ static QemuOptsList qemu_machine_opts = {
>              .name = "kvm-type",
>              .type = QEMU_OPT_STRING,
>              .help = "Specifies the KVM virtualization mode (HV, PR)",
> +        },{
> +            .name = PC_MACHINE_MAX_RAM_BELOW_4G,
> +            .type = QEMU_OPT_SIZE,
> +            .help = "maximum ram below the 4G boundary (32bit boundary)",
>          },
>          { /* End of list */ }
>      },
> -- 
> 1.8.4

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

* Re: [Qemu-devel] [PATCH 2.1 v7 2/3] pc & q35: Add new machine opt max-ram-below-4g
  2014-06-23 14:59   ` Michael S. Tsirkin
@ 2014-06-23 17:49     ` Don Slutz
  0 siblings, 0 replies; 9+ messages in thread
From: Don Slutz @ 2014-06-23 17:49 UTC (permalink / raw)
  To: Michael S. Tsirkin, Don Slutz
  Cc: xen-devel, Stefano Stabellini, Marcel Apfelbaum, qemu-devel,
	Anthony Liguori, Igor Mammedov, Andreas Färber

On 06/23/14 10:59, Michael S. Tsirkin wrote:
> On Thu, Jun 19, 2014 at 09:40:25PM -0400, Don Slutz wrote:
>> This is a pc & q35 only machine opt.
>>
...
>>
>>   static void pc_machine_initfn(Object *obj)
>>   {
>> +    PCMachineState *pcms = PC_MACHINE(obj);
>> +
>>       object_property_add(obj, PC_MACHINE_MEMHP_REGION_SIZE, "int",
>>                           pc_machine_get_hotplug_memory_region_size,
>>                           NULL, NULL, NULL, NULL);
>> +    pcms->max_ram_below_4g = 1UL << 32; /* 4G */
> This is a bug: should be 1ULL. Fixed it up locally.

Yes.  Thanks for fixing it.  My 64bit system's gcc:

dcs-xen-54:~/qemu>gcc --version
gcc (GCC) 4.7.2 20120921 (Red Hat 4.7.2-2)
Copyright (C) 2012 Free Software Foundation, Inc.

Gets this wrong generating 32bit code :(

     -Don Slutz

>> +    object_property_add(obj, PC_MACHINE_MAX_RAM_BELOW_4G, "size",
>> +                        pc_machine_get_max_ram_below_4g,
>> +                        pc_machine_set_max_ram_below_4g,
>> +                        NULL, NULL, NULL);
>>   }

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

end of thread, other threads:[~2014-06-23 17:50 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-20  1:40 [Qemu-devel] [PATCH 2.1 v7 0/3] Add max-ram-below-4g (was Add pci_hole_min_size machine option) Don Slutz
2014-06-20  1:40 ` [Qemu-devel] [PATCH 2.1 v7 1/3] xen-hvm: Fix xen_hvm_init() to adjust pc memory layout Don Slutz
2014-06-20  1:40 ` [Qemu-devel] [PATCH 2.1 v7 2/3] pc & q35: Add new machine opt max-ram-below-4g Don Slutz
2014-06-23 14:59   ` Michael S. Tsirkin
2014-06-23 17:49     ` Don Slutz
2014-06-20  1:40 ` [Qemu-devel] [PATCH 2.1 v7 3/3] xen-hvm: Handle " Don Slutz
2014-06-20 12:21   ` Stefano Stabellini
2014-06-23 14:41 ` [Qemu-devel] [PATCH 2.1 v7 0/3] Add max-ram-below-4g (was Add pci_hole_min_size machine option) Michael S. Tsirkin
2014-06-23 14:53   ` Stefano Stabellini

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