Patchwork [PatchV2] s390x: fix memory detection for guests > 64GB

login
register
mail settings
Submitter Christian Borntraeger
Date May 12, 2011, 7:50 a.m.
Message ID <4DCB9137.70008@de.ibm.com>
Download mbox | patch
Permalink /patch/95267/
State New
Headers show

Comments

Christian Borntraeger - May 12, 2011, 7:50 a.m.
the s390 memory detection has a 16bit field that specifies the amount of
increments. This patch adopts the memory size to always fit into that
scheme. This also fixes virtio detection for these guests, since the 
descriptor page is located after the main memory.

Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>

---
 target-s390x/op_helper.c |    8 ++++++--
 vl.c                     |   11 +++++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)
Alexander Graf - May 12, 2011, 7:55 a.m.
On 12.05.2011, at 09:50, Christian Borntraeger wrote:

> the s390 memory detection has a 16bit field that specifies the amount of
> increments. This patch adopts the memory size to always fit into that
> scheme. This also fixes virtio detection for these guests, since the 
> descriptor page is located after the main memory.
> 
> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
> 
> ---
> target-s390x/op_helper.c |    8 ++++++--
> vl.c                     |   11 +++++++++++
> 2 files changed, 17 insertions(+), 2 deletions(-)
> 
> Index: b/target-s390x/op_helper.c
> ===================================================================
> --- a/target-s390x/op_helper.c
> +++ b/target-s390x/op_helper.c
> @@ -2361,6 +2361,7 @@ static void ext_interrupt(CPUState *env,
> int sclp_service_call(CPUState *env, uint32_t sccb, uint64_t code)
> {
>     int r = 0;
> +    int shift = 0;
> 
> #ifdef DEBUG_HELPER
>     printf("sclp(0x%x, 0x%" PRIx64 ")\n", sccb, code);
> @@ -2375,8 +2376,11 @@ int sclp_service_call(CPUState *env, uin
>     switch(code) {
>         case SCLP_CMDW_READ_SCP_INFO:
>         case SCLP_CMDW_READ_SCP_INFO_FORCED:
> -            stw_phys(sccb + SCP_MEM_CODE, ram_size >> 20);
> -            stb_phys(sccb + SCP_INCREMENT, 1);
> +            while ((ram_size >> (20 + shift)) > 65535) {
> +                shift++;
> +            }
> +            stw_phys(sccb + SCP_MEM_CODE, ram_size >> (20 + shift));
> +            stb_phys(sccb + SCP_INCREMENT, 1 << shift);
>             stw_phys(sccb + SCP_RESPONSE_CODE, 0x10);
> 
>             if (kvm_enabled()) {
> Index: b/vl.c
> ===================================================================
> --- a/vl.c
> +++ b/vl.c
> @@ -2962,6 +2962,17 @@ int main(int argc, char **argv, char **e
>     if (ram_size == 0)
>         ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
> 
> +    /* s390x ram size detection needs a 16bit multiplier + an increment. So
> +       guests > 64GB can be specified in 2MB steps etc */
> +    if (strstr(machine->name, "s390")) {
> +        int shift = 0;
> +
> +        while ((ram_size >> (20 + shift)) > 65535) {
> +            shift++;
> +        }
> +        ram_size = ram_size >> (20 + shift) << (20 + shift);

This one really belongs to hw/s390-virtio.c. Just move the same code to s390_init there and it should work out. The less hacks we can have in generic code, the better :).


Alex
Christian Borntraeger - May 12, 2011, 7:59 a.m.
On 12/05/11 09:55, Alexander Graf wrote:
>> +    /* s390x ram size detection needs a 16bit multiplier + an increment. So
>> +       guests > 64GB can be specified in 2MB steps etc */
>> +    if (strstr(machine->name, "s390")) {
>> +        int shift = 0;
>> +
>> +        while ((ram_size >> (20 + shift)) > 65535) {
>> +            shift++;
>> +        }
>> +        ram_size = ram_size >> (20 + shift) << (20 + shift);
> 
> This one really belongs to hw/s390-virtio.c. Just move the same code to s390_init there and it should work out. The less hacks we can have in generic code, the better :).

Unfortunately this does not work. The slcp op helper uses the global variable
ram_size fro vl.c. I could change the global ram_size in s390_init, but this
is also pretty ugly.

Christian
Alexander Graf - May 12, 2011, 8:01 a.m.
On 12.05.2011, at 09:59, Christian Borntraeger wrote:

> On 12/05/11 09:55, Alexander Graf wrote:
>>> +    /* s390x ram size detection needs a 16bit multiplier + an increment. So
>>> +       guests > 64GB can be specified in 2MB steps etc */
>>> +    if (strstr(machine->name, "s390")) {
>>> +        int shift = 0;
>>> +
>>> +        while ((ram_size >> (20 + shift)) > 65535) {
>>> +            shift++;
>>> +        }
>>> +        ram_size = ram_size >> (20 + shift) << (20 + shift);
>> 
>> This one really belongs to hw/s390-virtio.c. Just move the same code to s390_init there and it should work out. The less hacks we can have in generic code, the better :).
> 
> Unfortunately this does not work. The slcp op helper uses the global variable
> ram_size fro vl.c. I could change the global ram_size in s390_init, but this
> is also pretty ugly.

I'd definitely prefer that over the change on vl.c :)


Alex

Patch

Index: b/target-s390x/op_helper.c
===================================================================
--- a/target-s390x/op_helper.c
+++ b/target-s390x/op_helper.c
@@ -2361,6 +2361,7 @@  static void ext_interrupt(CPUState *env,
 int sclp_service_call(CPUState *env, uint32_t sccb, uint64_t code)
 {
     int r = 0;
+    int shift = 0;
 
 #ifdef DEBUG_HELPER
     printf("sclp(0x%x, 0x%" PRIx64 ")\n", sccb, code);
@@ -2375,8 +2376,11 @@  int sclp_service_call(CPUState *env, uin
     switch(code) {
         case SCLP_CMDW_READ_SCP_INFO:
         case SCLP_CMDW_READ_SCP_INFO_FORCED:
-            stw_phys(sccb + SCP_MEM_CODE, ram_size >> 20);
-            stb_phys(sccb + SCP_INCREMENT, 1);
+            while ((ram_size >> (20 + shift)) > 65535) {
+                shift++;
+            }
+            stw_phys(sccb + SCP_MEM_CODE, ram_size >> (20 + shift));
+            stb_phys(sccb + SCP_INCREMENT, 1 << shift);
             stw_phys(sccb + SCP_RESPONSE_CODE, 0x10);
 
             if (kvm_enabled()) {
Index: b/vl.c
===================================================================
--- a/vl.c
+++ b/vl.c
@@ -2962,6 +2962,17 @@  int main(int argc, char **argv, char **e
     if (ram_size == 0)
         ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
 
+    /* s390x ram size detection needs a 16bit multiplier + an increment. So
+       guests > 64GB can be specified in 2MB steps etc */
+    if (strstr(machine->name, "s390")) {
+        int shift = 0;
+
+        while ((ram_size >> (20 + shift)) > 65535) {
+            shift++;
+        }
+        ram_size = ram_size >> (20 + shift) << (20 + shift);
+    }
+
     /* init the dynamic translator */
     cpu_exec_init_all(tb_size * 1024 * 1024);