Skip to contentSkip to conversation

s390x/sclp: fix maxram calculation

PATCH In review Christian Borntraeger 4 participants 15 messages Jul 30, 2018 – Jul 31, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 s390x/sclp: fix maxram calculation

We clamp down ram_size to match the sclp increment size. We do not do the same for maxram_size, which means for large guests with some sizes (e.g. -m 50000) maxram_size differs from ram_size. This can break other code (e.g. CMMA migration) which uses maxram_size to calculate the number of pages and then throws some errors.

Fixes 82fab5c5b90e468f3e9d54c ("s390x/sclp: remove memory hotplug support")
CC David Hildenbrand <[email protected]>
---
 hw/s390x/sclp.c | 1 +
 1 file changed, 1 insertion(+)
hw/s390x/sclp.c +1 -0
index bd2a024..4510a80 100644
@@ -320,6 +320,7 @@ static void sclp_memory_init(SCLPDevice *sclp)
     initial_mem = initial_mem >> increment_size << increment_size;
 
     machine->ram_size = initial_mem;
+    machine->maxram_size = initial_mem;
     /* let's propagate the changed ram size into the global variable. */
     ram_size = initial_mem;
 }
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 5 lines · Christian Borntraeger

We clamp down ram_size to match the sclp increment size. We do not do the same for maxram_size, which means for large guests with some sizes (e.g. -m 50000) maxram_size differs from ram_size. This can break other code (e.g. CMMA migration) which uses maxram_size to calculate the number of pages and then throws some errors.

So the only problem is that the buffer size between source and target differ?

Quoted 15 lines
Fixes 82fab5c5b90e468f3e9d54c ("s390x/sclp: remove memory hotplug support")
CC David Hildenbrand <[email protected]>
---
 hw/s390x/sclp.c | 1 +
 1 file changed, 1 insertion(+)
hw/s390x/sclp.c +0 -0
index bd2a024..4510a80 100644

hw/s390x/sclp.c static void sclp_memory_init(SCLPDevice *sclp) · line 326

Quoted 7 lines
hw/s390x/sclp.c +1 -0
@@ -320,6 +320,7 @@ static void sclp_memory_init(SCLPDevice *sclp)
     initial_mem = initial_mem >> increment_size << increment_size;
 
     machine->ram_size = initial_mem;
+    machine->maxram_size = initial_mem;
     /* let's propagate the changed ram size into the global variable. */
     ram_size = initial_mem;
 }

I even have a private patch for that already :)

Signature · 3 lines
Thanks,

David / dhildenb
#2 lore raw
Quoted 9 lines · David Hildenbrand
Quoted 5 lines · Christian Borntraeger

We clamp down ram_size to match the sclp increment size. We do not do the same for maxram_size, which means for large guests with some sizes (e.g. -m 50000) maxram_size differs from ram_size. This can break other code (e.g. CMMA migration) which uses maxram_size to calculate the number of pages and then throws some errors.

So the only problem is that the buffer size between source and target differ?

The problem is that the target tries to access a non-existing buffer when committing all cmma value, so the kernel returns with EFAULT.

Quoted 25 lines
Quoted 16 lines
Fixes 82fab5c5b90e468f3e9d54c ("s390x/sclp: remove memory hotplug support")
CC David Hildenbrand <[email protected]>
---
 hw/s390x/sclp.c | 1 +
 1 file changed, 1 insertion(+)
hw/s390x/sclp.c +0 -0
index bd2a024..4510a80 100644

hw/s390x/sclp.c static void sclp_memory_init(SCLPDevice *sclp) · line 326

Quoted 7 lines
hw/s390x/sclp.c +1 -0
@@ -320,6 +320,7 @@ static void sclp_memory_init(SCLPDevice *sclp)
     initial_mem = initial_mem >> increment_size << increment_size;
 
     machine->ram_size = initial_mem;
+    machine->maxram_size = initial_mem;
     /* let's propagate the changed ram size into the global variable. */
     ram_size = initial_mem;
 }

I even have a private patch for that already :)

#3 lore raw
Quoted 10 lines · Christian Borntraeger
Quoted 7 lines · David Hildenbrand
Quoted 5 lines · Christian Borntraeger

We clamp down ram_size to match the sclp increment size. We do not do the same for maxram_size, which means for large guests with some sizes (e.g. -m 50000) maxram_size differs from ram_size. This can break other code (e.g. CMMA migration) which uses maxram_size to calculate the number of pages and then throws some errors.

Quoted 6 lines
Quoted 2 lines

So the only problem is that the buffer size between source and target differ?

The problem is that the target tries to access a non-existing buffer when committing all cmma value, so the kernel returns with EFAULT.

Quoted 1 line

Am I wrong or does CMMA migration code really not care about which parts of maxram are actually used (== which memory regions are actually defined)?

If so, this looks broken to me and the right fix is to use ramsize for now, because it simply does not support maxram.

(I assume using some -m X,maxmem=X+Y would make it fail in the same way)

(this patch still makes sense and should be done)

Signature · 3 lines
Thanks,

David / dhildenb
#4 lore raw
Quoted 21 lines · David Hildenbrand
Quoted 10 lines · Christian Borntraeger
Quoted 7 lines · David Hildenbrand
Quoted 5 lines · Christian Borntraeger

We clamp down ram_size to match the sclp increment size. We do not do the same for maxram_size, which means for large guests with some sizes (e.g. -m 50000) maxram_size differs from ram_size. This can break other code (e.g. CMMA migration) which uses maxram_size to calculate the number of pages and then throws some errors.

Quoted 6 lines
Quoted 2 lines

So the only problem is that the buffer size between source and target differ?

The problem is that the target tries to access a non-existing buffer when committing all cmma value, so the kernel returns with EFAULT.

Quoted 1 line

Am I wrong or does CMMA migration code really not care about which parts of maxram are actually used (== which memory regions are actually defined)?

Quoted 6 lines

If so, this looks broken to me and the right fix is to use ramsize for now, because it simply does not support maxram.

(I assume using some -m X,maxmem=X+Y would make it fail in the same way)

(this patch still makes sense and should be done)

I am looking for the minimal fix for 2.13 and ideally even for 2.12.1.

Can we agree on this fix and do the remaining thing later?

Reviewed-by
#5 lore raw
Quoted 27 lines · Christian Borntraeger
Quoted 24 lines · David Hildenbrand
Quoted 10 lines · Christian Borntraeger
Quoted 7 lines · David Hildenbrand
Quoted 5 lines · Christian Borntraeger

We clamp down ram_size to match the sclp increment size. We do not do the same for maxram_size, which means for large guests with some sizes (e.g. -m 50000) maxram_size differs from ram_size. This can break other code (e.g. CMMA migration) which uses maxram_size to calculate the number of pages and then throws some errors.

Quoted 6 lines
Quoted 2 lines

So the only problem is that the buffer size between source and target differ?

The problem is that the target tries to access a non-existing buffer when committing all cmma value, so the kernel returns with EFAULT.

Quoted 1 line

Am I wrong or does CMMA migration code really not care about which parts of maxram are actually used (== which memory regions are actually defined)?

If so, this looks broken to me and the right fix is to use ramsize for now, because it simply does not support maxram.

Quoted 8 lines
Quoted 3 lines

(I assume using some -m X,maxmem=X+Y would make it fail in the same way)

(this patch still makes sense and should be done)

I am looking for the minimal fix for 2.13 and ideally even for 2.12.1.

Can we agree on this fix and do the remaining thing later?

Yes. The clean fix should then really only consider mapped memory regions (so the sending side should somehow iterate over them and also only access that memory).

Signature · 3 lines
Thanks,

David / dhildenb
#6 lore raw
In reply to Christian Borntraeger
Quoted 22 lines · On Mon, 30 Jul 2018 17:20:25 +0200 Christian Borntraeger…
Quoted 21 lines · David Hildenbrand
Quoted 10 lines · Christian Borntraeger
Quoted 7 lines · David Hildenbrand
Quoted 5 lines · Christian Borntraeger

We clamp down ram_size to match the sclp increment size. We do not do the same for maxram_size, which means for large guests with some sizes (e.g. -m 50000) maxram_size differs from ram_size. This can break other code (e.g. CMMA migration) which uses maxram_size to calculate the number of pages and then throws some errors.

Quoted 6 lines
Quoted 2 lines

So the only problem is that the buffer size between source and target differ?

The problem is that the target tries to access a non-existing buffer when committing all cmma value, so the kernel returns with EFAULT.

Quoted 1 line

Am I wrong or does CMMA migration code really not care about which parts of maxram are actually used (== which memory regions are actually defined)?

Quoted 8 lines
Quoted 6 lines

If so, this looks broken to me and the right fix is to use ramsize for now, because it simply does not support maxram.

(I assume using some -m X,maxmem=X+Y would make it fail in the same way)

(this patch still makes sense and should be done)

I am looking for the minimal fix for 2.13 and ideally even for 2.12.1.

2.13 is not the QEMU version you are looking for :)

Quoted 1 line

Can we agree on this fix and do the remaining thing later?

If you guys agree, I'm happy to queue it to s390-fixes for 3.0-rc3. Just be quick, as I'd need to send it tomorrow morning the latest :)

(FWIW, patch looks sane and small enough to me.)

#7 lore raw
In reply to Christian Borntraeger

Are we still able to get things into 2.12.1 or are we too late?

Quoted 27 lines · Christian Borntraeger

We clamp down ram_size to match the sclp increment size. We do not do the same for maxram_size, which means for large guests with some sizes (e.g. -m 50000) maxram_size differs from ram_size. This can break other code (e.g. CMMA migration) which uses maxram_size to calculate the number of pages and then throws some errors.

Fixes 82fab5c5b90e468f3e9d54c ("s390x/sclp: remove memory hotplug support")
CC David Hildenbrand <[email protected]>
---
 hw/s390x/sclp.c | 1 +
 1 file changed, 1 insertion(+)
hw/s390x/sclp.c +1 -0
index bd2a024..4510a80 100644
@@ -320,6 +320,7 @@ static void sclp_memory_init(SCLPDevice *sclp)
     initial_mem = initial_mem >> increment_size << increment_size;
 
     machine->ram_size = initial_mem;
+    machine->maxram_size = initial_mem;
     /* let's propagate the changed ram size into the global variable. */
     ram_size = initial_mem;
 }
#8 lore raw

Quoting Christian Borntraeger (2018-07-30 10:31:12)

Quoted 1 line

Are we still able to get things into 2.12.1 or are we too late?

Freeze is EOD today, but I can grab them if they hit master/rc3 tomorrow.

Quoted 31 lines · Christian Borntraeger
Quoted 27 lines

We clamp down ram_size to match the sclp increment size. We do not do the same for maxram_size, which means for large guests with some sizes (e.g. -m 50000) maxram_size differs from ram_size. This can break other code (e.g. CMMA migration) which uses maxram_size to calculate the number of pages and then throws some errors.

Fixes 82fab5c5b90e468f3e9d54c ("s390x/sclp: remove memory hotplug support")
CC David Hildenbrand <[email protected]>
---
 hw/s390x/sclp.c | 1 +
 1 file changed, 1 insertion(+)
hw/s390x/sclp.c +1 -0
index bd2a024..4510a80 100644
@@ -320,6 +320,7 @@ static void sclp_memory_init(SCLPDevice *sclp)
     initial_mem = initial_mem >> increment_size << increment_size;
 
     machine->ram_size = initial_mem;
+    machine->maxram_size = initial_mem;
     /* let's propagate the changed ram size into the global variable. */
     ram_size = initial_mem;
 }
#9 lore raw
Quoted 4 lines · On Mon, 30 Jul 2018 11:58:13 -0500 Michael Roth <[email protected]>…

Quoting Christian Borntraeger (2018-07-30 10:31:12)

Quoted 1 line

Are we still able to get things into 2.12.1 or are we too late?

Freeze is EOD today, but I can grab them if they hit master/rc3 tomorrow.

OK, I just sent a pull request with this patch.

#10 lore raw
Quoted 9 lines · On Tue, 31 Jul 2018 08:52:05 +0200 Cornelia Huck <[email protected]> wrote:
Quoted 4 lines · On Mon, 30 Jul 2018 11:58:13 -0500 Michael Roth <[email protected]>…

Quoting Christian Borntraeger (2018-07-30 10:31:12)

Quoted 1 line

Are we still able to get things into 2.12.1 or are we too late?

Freeze is EOD today, but I can grab them if they hit master/rc3 tomorrow.

OK, I just sent a pull request with this patch.

...and it is in master now.

#11 lore raw
In reply to Christian Borntraeger
Quoted 20 lines · Christian Borntraeger

We clamp down ram_size to match the sclp increment size. We do not do the same for maxram_size, which means for large guests with some sizes (e.g. -m 50000) maxram_size differs from ram_size. This can break other code (e.g. CMMA migration) which uses maxram_size to calculate the number of pages and then throws some errors.

Fixes 82fab5c5b90e468f3e9d54c ("s390x/sclp: remove memory hotplug support")
CC David Hildenbrand <[email protected]>
---
 hw/s390x/sclp.c | 1 +
 1 file changed, 1 insertion(+)
hw/s390x/sclp.c +0 -0
index bd2a024..4510a80 100644

hw/s390x/sclp.c static void sclp_memory_init(SCLPDevice *sclp) · line 326

Quoted 7 lines
hw/s390x/sclp.c +1 -0
@@ -320,6 +320,7 @@ static void sclp_memory_init(SCLPDevice *sclp)
     initial_mem = initial_mem >> increment_size << increment_size;
 
     machine->ram_size = initial_mem;
+    machine->maxram_size = initial_mem;
     /* let's propagate the changed ram size into the global variable. */
     ram_size = initial_mem;
 }

BTW, I handle it in may private patch like this

static inline SCLPDevice *get_sclp_device(void)
{
@@ -319,9 +321,12 @@ static void sclp_memory_init(SCLPDevice *sclp)
* down to align with the nearest increment boundary. */
initial_mem = initial_mem >> increment_size << increment_size;

-    machine->ram_size = initial_mem;
-    /* let's propagate the changed ram size into the global variable. */
-    ram_size = initial_mem;
+    /* propagate the changed ram size into the different places */
+    if (initial_mem != machine->ram_size) {
+        machine->maxram_size -= machine->ram_size - initial_mem;
+        machine->ram_size = initial_mem;
+        ram_size = initial_mem;

+ }
}

You would right now overwrite any maxmem setting (which might be ok as we don't support it yet).

Signature · 3 lines
Thanks,

David / dhildenb
#12 lore raw
Quoted 48 lines · On Mon, 30 Jul 2018 17:43:42 +0200 David Hildenbrand <[email protected]> wrote:
Quoted 20 lines · Christian Borntraeger

We clamp down ram_size to match the sclp increment size. We do not do the same for maxram_size, which means for large guests with some sizes (e.g. -m 50000) maxram_size differs from ram_size. This can break other code (e.g. CMMA migration) which uses maxram_size to calculate the number of pages and then throws some errors.

Fixes 82fab5c5b90e468f3e9d54c ("s390x/sclp: remove memory hotplug support")
CC David Hildenbrand <[email protected]>
---
 hw/s390x/sclp.c | 1 +
 1 file changed, 1 insertion(+)
hw/s390x/sclp.c +0 -0
index bd2a024..4510a80 100644

hw/s390x/sclp.c static void sclp_memory_init(SCLPDevice *sclp) · line 326

Quoted 7 lines
hw/s390x/sclp.c +1 -0
@@ -320,6 +320,7 @@ static void sclp_memory_init(SCLPDevice *sclp)
     initial_mem = initial_mem >> increment_size << increment_size;
 
     machine->ram_size = initial_mem;
+    machine->maxram_size = initial_mem;
     /* let's propagate the changed ram size into the global variable. */
     ram_size = initial_mem;
 }

BTW, I handle it in may private patch like this

static inline SCLPDevice *get_sclp_device(void)
{

(quoted diff) +6 -3
@@ -319,9 +321,12 @@ static void sclp_memory_init(SCLPDevice *sclp)
      * down to align with the nearest increment boundary. */
     initial_mem = initial_mem >> increment_size << increment_size;
 
-    machine->ram_size = initial_mem;
-    /* let's propagate the changed ram size into the global variable. */
-    ram_size = initial_mem;
+    /* propagate the changed ram size into the different places */
+    if (initial_mem != machine->ram_size) {
+        machine->maxram_size -= machine->ram_size - initial_mem;
+        machine->ram_size = initial_mem;
+        ram_size = initial_mem;
+    }
 }
 
Quoted 3 lines

You would right now overwrite any maxmem setting (which might be ok as we don't support it yet).

So, will you (for whatever value of 'you') submit more patches for 3.1?

#13 lore raw
Quoted 51 lines · Cornelia Huck
Quoted 48 lines · On Mon, 30 Jul 2018 17:43:42 +0200 David Hildenbrand <[email protected]> wrote:
Quoted 20 lines · Christian Borntraeger

We clamp down ram_size to match the sclp increment size. We do not do the same for maxram_size, which means for large guests with some sizes (e.g. -m 50000) maxram_size differs from ram_size. This can break other code (e.g. CMMA migration) which uses maxram_size to calculate the number of pages and then throws some errors.

Fixes 82fab5c5b90e468f3e9d54c ("s390x/sclp: remove memory hotplug support")
CC David Hildenbrand <[email protected]>
---
 hw/s390x/sclp.c | 1 +
 1 file changed, 1 insertion(+)
hw/s390x/sclp.c +0 -0
index bd2a024..4510a80 100644

hw/s390x/sclp.c static void sclp_memory_init(SCLPDevice *sclp) · line 326

Quoted 7 lines
hw/s390x/sclp.c +1 -0
@@ -320,6 +320,7 @@ static void sclp_memory_init(SCLPDevice *sclp)
     initial_mem = initial_mem >> increment_size << increment_size;
 
     machine->ram_size = initial_mem;
+    machine->maxram_size = initial_mem;
     /* let's propagate the changed ram size into the global variable. */
     ram_size = initial_mem;
 }

BTW, I handle it in may private patch like this

static inline SCLPDevice *get_sclp_device(void)
{

(quoted diff) +6 -3
@@ -319,9 +321,12 @@ static void sclp_memory_init(SCLPDevice *sclp)
      * down to align with the nearest increment boundary. */
     initial_mem = initial_mem >> increment_size << increment_size;
 
-    machine->ram_size = initial_mem;
-    /* let's propagate the changed ram size into the global variable. */
-    ram_size = initial_mem;
+    /* propagate the changed ram size into the different places */
+    if (initial_mem != machine->ram_size) {
+        machine->maxram_size -= machine->ram_size - initial_mem;
+        machine->ram_size = initial_mem;
+        ram_size = initial_mem;
+    }
 }
 
Quoted 6 lines
Quoted 3 lines

You would right now overwrite any maxmem setting (which might be ok as we don't support it yet).

So, will you (for whatever value of 'you') submit more patches for 3.1?

Once we have memory device support for s390x that will be needed. But the person that implemented cmma migration should fix the handling and only try to migrate memory that is actually there. This was broken before my patch, just never happened as Linux always onlines all memory it sees via SCLP (thereby creating the memory regions).

Signature · 3 lines
Thanks,

David / dhildenb
#14 lore raw
In reply to Christian Borntraeger
Quoted 19 lines · On Mon, 30 Jul 2018 16:09:26 +0200 Christian Borntraeger…

We clamp down ram_size to match the sclp increment size. We do not do the same for maxram_size, which means for large guests with some sizes (e.g. -m 50000) maxram_size differs from ram_size. This can break other code (e.g. CMMA migration) which uses maxram_size to calculate the number of pages and then throws some errors.

Fixes 82fab5c5b90e468f3e9d54c ("s390x/sclp: remove memory hotplug support")
CC David Hildenbrand <[email protected]>
---
 hw/s390x/sclp.c | 1 +
 1 file changed, 1 insertion(+)
hw/s390x/sclp.c +0 -0
index bd2a024..4510a80 100644

hw/s390x/sclp.c static void sclp_memory_init(SCLPDevice *sclp) · line 326

Quoted 7 lines
hw/s390x/sclp.c +1 -0
@@ -320,6 +320,7 @@ static void sclp_memory_init(SCLPDevice *sclp)
     initial_mem = initial_mem >> increment_size << increment_size;
 
     machine->ram_size = initial_mem;
+    machine->maxram_size = initial_mem;
     /* let's propagate the changed ram size into the global variable. */
     ram_size = initial_mem;
 }

Thanks, queued to s390-fixes.