Skip to contentSkip to conversation

migration: check length directly to make sure the range is aligned

PATCH Applied Wei Yang 4 participants 11 messages Jul 12, 2019 – Nov 11, 2019

lore
Share & tools
lore

Wei Yang

author
#0 lore raw

PATCH 1/1 migration: check length directly to make sure the range is aligned

Since the start addr is already checked, to make sure the range is aligned, checking the length is enough.

---
 exec.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
exec.c +3 -4
index 50ea9c5aaa..8fa980baae 100644
@@ -4067,10 +4067,9 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length)
 
     if ((start + length) <= rb->used_length) {
         bool need_madvise, need_fallocate;
-        uint8_t *host_endaddr = host_startaddr + length;
-        if ((uintptr_t)host_endaddr & (rb->page_size - 1)) {
-            error_report("ram_block_discard_range: Unaligned end address: %p",
-                         host_endaddr);
+        if (length & (rb->page_size - 1)) {
+            error_report("ram_block_discard_range: Unaligned length: %lx",
+                         length);
             goto err;
         }
 
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · * Wei Yang ([email protected]) wrote:

Since the start addr is already checked, to make sure the range is aligned, checking the length is enough.

---
 exec.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
exec.c +0 -0
index 50ea9c5aaa..8fa980baae 100644

exec.c int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length) · line 4072

Quoted 10 lines
exec.c +3 -4
@@ -4067,10 +4067,9 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length)
 
     if ((start + length) <= rb->used_length) {
         bool need_madvise, need_fallocate;
-        uint8_t *host_endaddr = host_startaddr + length;
-        if ((uintptr_t)host_endaddr & (rb->page_size - 1)) {
-            error_report("ram_block_discard_range: Unaligned end address: %p",
-                         host_endaddr);
+        if (length & (rb->page_size - 1)) {
+            error_report("ram_block_discard_range: Unaligned length: %lx",
+                         length);

Yes, I *think* this is safe, we'll need to watch out for any warnings; David Gibson's balloon fix from February means that the balloon code should now warn in it's case.

rth: Want to pick this up?

Quoted 6 lines
exec.c +0 -0
             goto err;
         }
 
Signature · 1 line
2.17.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#2 lore raw
Quoted 7 lines · Dr. David Alan Gilbert

exec.c int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length) · line 4072

Quoted 6 lines
exec.c +3 -3
-        if ((uintptr_t)host_endaddr & (rb->page_size - 1)) {
-            error_report("ram_block_discard_range: Unaligned end address: %p",
-                         host_endaddr);
+        if (length & (rb->page_size - 1)) {
+            error_report("ram_block_discard_range: Unaligned length: %lx",
+                         length);

Yes, I *think* this is safe, we'll need to watch out for any warnings;

Do you mean compiler or QEMU warning? The patch is safe since there's an

    if ((uintptr_t)host_startaddr & (rb->page_size - 1)) {
        error_report("ram_block_discard_range: Unaligned start address: %p",
                     host_startaddr);
        goto err;
    }

just before this context.

Paolo

#3 lore raw
Quoted 10 lines · * Paolo Bonzini ([email protected]) wrote:
Quoted 7 lines · Dr. David Alan Gilbert

exec.c int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length) · line 4072

Quoted 6 lines
exec.c +3 -3
-        if ((uintptr_t)host_endaddr & (rb->page_size - 1)) {
-            error_report("ram_block_discard_range: Unaligned end address: %p",
-                         host_endaddr);
+        if (length & (rb->page_size - 1)) {
+            error_report("ram_block_discard_range: Unaligned length: %lx",
+                         length);

Yes, I *think* this is safe, we'll need to watch out for any warnings;

Do you mean compiler or QEMU warning?

No, I mean lots of these error reports being printed out in some common case.

Dave

The patch is safe since there's an

Quoted 10 lines
    if ((uintptr_t)host_startaddr & (rb->page_size - 1)) {
        error_report("ram_block_discard_range: Unaligned start address: %p",
                     host_startaddr);
        goto err;
    }

just before this context.

Paolo

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

author
#4 lore raw
Quoted 10 lines · Dr. David Alan Gilbert
Quoted 9 lines · * Paolo Bonzini ([email protected]) wrote:
Quoted 7 lines · Dr. David Alan Gilbert

exec.c int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length) · line 4072

Quoted 6 lines
exec.c +3 -3
-        if ((uintptr_t)host_endaddr & (rb->page_size - 1)) {
-            error_report("ram_block_discard_range: Unaligned end address: %p",
-                         host_endaddr);
+        if (length & (rb->page_size - 1)) {
+            error_report("ram_block_discard_range: Unaligned length: %lx",
+                         length);

Yes, I *think* this is safe, we'll need to watch out for any warnings;

Quoted 8 lines
Quoted 1 line

Do you mean compiler or QEMU warning?

No, I mean lots of these error reports being printed out in some common case.

Dave

The patch is safe since there's an

Dave,

Any further comment for this patch? or What should I do next?

Quoted 12 lines
Quoted 10 lines
    if ((uintptr_t)host_startaddr & (rb->page_size - 1)) {
        error_report("ram_block_discard_range: Unaligned start address: %p",
                     host_startaddr);
        goto err;
    }

just before this context.

Paolo

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

Signature · 2 lines
Wei Yang
Help you, Help me
author
#5 lore raw
In reply to Dr. David Alan Gilbert
Quoted 8 lines · Dr. David Alan Gilbert
Quoted 7 lines · * Paolo Bonzini ([email protected]) wrote:
Quoted 6 lines · Dr. David Alan Gilbert
Quoted 6 lines
exec.c +3 -3
-        if ((uintptr_t)host_endaddr & (rb->page_size - 1)) {
-            error_report("ram_block_discard_range: Unaligned end address: %p",
-                         host_endaddr);
+        if (length & (rb->page_size - 1)) {
+            error_report("ram_block_discard_range: Unaligned length: %lx",
+                         length);
Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Yes, I *think* this is safe, we'll need to watch out for any warnings;

Do you mean compiler or QEMU warning?

No, I mean lots of these error reports being printed out in some common case.

Hi, Dave

Haven't see you for a period of time :-)

Quoted 15 lines

Dave

The patch is safe since there's an

Quoted 10 lines
    if ((uintptr_t)host_startaddr & (rb->page_size - 1)) {
        error_report("ram_block_discard_range: Unaligned start address: %p",
                     host_startaddr);
        goto err;
    }

just before this context.

Paolo

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

Signature · 2 lines
Wei Yang
Help you, Help me
#6 lore raw
Quoted 13 lines · * Wei Yang ([email protected]) wrote:
Quoted 12 lines · Dr. David Alan Gilbert
Quoted 10 lines · * Paolo Bonzini ([email protected]) wrote:
Quoted 7 lines · Dr. David Alan Gilbert

exec.c int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length) · line 4072

Quoted 6 lines
exec.c +3 -3
-        if ((uintptr_t)host_endaddr & (rb->page_size - 1)) {
-            error_report("ram_block_discard_range: Unaligned end address: %p",
-                         host_endaddr);
+        if (length & (rb->page_size - 1)) {
+            error_report("ram_block_discard_range: Unaligned length: %lx",
+                         length);

Yes, I *think* this is safe, we'll need to watch out for any warnings;

Do you mean compiler or QEMU warning?

Quoted 7 lines
Quoted 3 lines

No, I mean lots of these error reports being printed out in some common case.

Hi, Dave

Haven't see you for a period of time :-)

I'm here (although been busy with virtiofs) - but this patch is exec.c so I think it needs to be picked by Paolo or rth.

Dave

Quoted 10 lines
Quoted 10 lines

Dave

The patch is safe since there's an

Quoted 7 lines
    if ((uintptr_t)host_startaddr & (rb->page_size - 1)) {
        error_report("ram_block_discard_range: Unaligned start address: %p",
                     host_startaddr);
        goto err;
    }
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

just before this context.

Paolo

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

Signature · 2 lines
Wei Yang
Help you, Help me

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

author
#7 lore raw
Quoted 18 lines · Dr. David Alan Gilbert
Quoted 17 lines · * Wei Yang ([email protected]) wrote:
Quoted 15 lines · Dr. David Alan Gilbert
Quoted 10 lines · * Paolo Bonzini ([email protected]) wrote:
Quoted 7 lines · Dr. David Alan Gilbert

exec.c int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length) · line 4072

Quoted 6 lines
exec.c +3 -3
-        if ((uintptr_t)host_endaddr & (rb->page_size - 1)) {
-            error_report("ram_block_discard_range: Unaligned end address: %p",
-                         host_endaddr);
+        if (length & (rb->page_size - 1)) {
+            error_report("ram_block_discard_range: Unaligned length: %lx",
+                         length);

Yes, I *think* this is safe, we'll need to watch out for any warnings;

Do you mean compiler or QEMU warning?

No, I mean lots of these error reports being printed out in some common case.

Quoted 7 lines
Quoted 3 lines

Hi, Dave

Haven't see you for a period of time :-)

I'm here (although been busy with virtiofs) - but this patch is exec.c so I think it needs to be picked by Paolo or rth.

Thanks Dave

Paolo

Do you feel comfortable with this?

Quoted 23 lines

Dave

Quoted 10 lines
Quoted 10 lines

Dave

The patch is safe since there's an

Quoted 7 lines
    if ((uintptr_t)host_startaddr & (rb->page_size - 1)) {
        error_report("ram_block_discard_range: Unaligned start address: %p",
                     host_startaddr);
        goto err;
    }
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

just before this context.

Paolo

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

Signature · 2 lines
Wei Yang
Help you, Help me

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

Signature · 2 lines
Wei Yang
Help you, Help me
#8 lore raw
Quoted 6 lines · Wei Yang

Thanks Dave

Paolo

Do you feel comfortable with this?

Queued now, thanks.

Paolo

author
#9 lore raw
In reply to Dr. David Alan Gilbert
Quoted 29 lines · Dr. David Alan Gilbert
Quoted 13 lines · * Wei Yang ([email protected]) wrote:

Since the start addr is already checked, to make sure the range is aligned, checking the length is enough.

---
 exec.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
exec.c +0 -0
index 50ea9c5aaa..8fa980baae 100644

exec.c int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length) · line 4072

Quoted 10 lines
exec.c +3 -4
@@ -4067,10 +4067,9 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length)
 
     if ((start + length) <= rb->used_length) {
         bool need_madvise, need_fallocate;
-        uint8_t *host_endaddr = host_startaddr + length;
-        if ((uintptr_t)host_endaddr & (rb->page_size - 1)) {
-            error_report("ram_block_discard_range: Unaligned end address: %p",
-                         host_endaddr);
+        if (length & (rb->page_size - 1)) {
+            error_report("ram_block_discard_range: Unaligned length: %lx",
+                         length);

Yes, I *think* this is safe, we'll need to watch out for any warnings; David Gibson's balloon fix from February means that the balloon code should now warn in it's case.

Quoted 4 lines

rth: Want to pick this up?

Hi, David

Do you like this one?

Quoted 8 lines
Quoted 6 lines
exec.c +0 -0
             goto err;
         }
 
Signature · 1 line
2.17.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

Signature · 2 lines
Wei Yang
Help you, Help me
#10 lore raw
In reply to Dr. David Alan Gilbert
Quoted 29 lines · Dr. David Alan Gilbert
Quoted 13 lines · * Wei Yang ([email protected]) wrote:

Since the start addr is already checked, to make sure the range is aligned, checking the length is enough.

---
 exec.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
exec.c +0 -0
index 50ea9c5aaa..8fa980baae 100644

exec.c int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length) · line 4072

Quoted 10 lines
exec.c +3 -4
@@ -4067,10 +4067,9 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length)
 
     if ((start + length) <= rb->used_length) {
         bool need_madvise, need_fallocate;
-        uint8_t *host_endaddr = host_startaddr + length;
-        if ((uintptr_t)host_endaddr & (rb->page_size - 1)) {
-            error_report("ram_block_discard_range: Unaligned end address: %p",
-                         host_endaddr);
+        if (length & (rb->page_size - 1)) {
+            error_report("ram_block_discard_range: Unaligned length: %lx",
+                         length);

Yes, I *think* this is safe, we'll need to watch out for any warnings; David Gibson's balloon fix from February means that the balloon code should now warn in it's case.

Quoted 4 lines

rth: Want to pick this up?

Any other task I should do for progress?

Quoted 8 lines
Quoted 6 lines
exec.c +0 -0
             goto err;
         }
 
Signature · 1 line
2.17.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

Signature · 2 lines
Wei Yang
Help you, Help me