QEMU-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [Qemu-devel] [PATCH] migration: check length directly to make sure the range is aligned
@ 2019-07-12  3:27 Wei Yang
  2019-07-19 17:54 ` Dr. David Alan Gilbert
  0 siblings, 1 reply; 7+ messages in thread
From: Wei Yang @ 2019-07-12  3:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, Wei Yang, rth, dgilbert, quintela

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

Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
---
 exec.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/exec.c b/exec.c
index 50ea9c5aaa..8fa980baae 100644
--- a/exec.c
+++ b/exec.c
@@ -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;
         }
 
-- 
2.17.1



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

* Re: [Qemu-devel] [PATCH] migration: check length directly to make sure the range is aligned
  2019-07-12  3:27 [Qemu-devel] [PATCH] migration: check length directly to make sure the range is aligned Wei Yang
@ 2019-07-19 17:54 ` Dr. David Alan Gilbert
  2019-07-19 18:03   ` Paolo Bonzini
                     ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Dr. David Alan Gilbert @ 2019-07-19 17:54 UTC (permalink / raw)
  To: Wei Yang, rth; +Cc: pbonzini, qemu-devel, quintela

* Wei Yang (richardw.yang@linux.intel.com) wrote:
> Since the start addr is already checked, to make sure the range is
> aligned, checking the length is enough.
> 
> Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
> ---
>  exec.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/exec.c b/exec.c
> index 50ea9c5aaa..8fa980baae 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -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?

Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>

>              goto err;
>          }
>  
> -- 
> 2.17.1
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK


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

* Re: [Qemu-devel] [PATCH] migration: check length directly to make sure the range is aligned
  2019-07-19 17:54 ` Dr. David Alan Gilbert
@ 2019-07-19 18:03   ` Paolo Bonzini
  2019-07-19 18:06     ` Dr. David Alan Gilbert
  2019-08-19  2:26   ` Wei Yang
  2019-09-13 23:58   ` Wei Yang
  2 siblings, 1 reply; 7+ messages in thread
From: Paolo Bonzini @ 2019-07-19 18:03 UTC (permalink / raw)
  To: Dr. David Alan Gilbert, Wei Yang, rth; +Cc: qemu-devel, quintela

On 19/07/19 19:54, Dr. David Alan Gilbert wrote:
>> -        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


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

* Re: [Qemu-devel] [PATCH] migration: check length directly to make sure the range is aligned
  2019-07-19 18:03   ` Paolo Bonzini
@ 2019-07-19 18:06     ` Dr. David Alan Gilbert
  2019-10-01  7:54       ` Wei Yang
  0 siblings, 1 reply; 7+ messages in thread
From: Dr. David Alan Gilbert @ 2019-07-19 18:06 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel, quintela, Wei Yang, rth

* Paolo Bonzini (pbonzini@redhat.com) wrote:
> On 19/07/19 19:54, Dr. David Alan Gilbert wrote:
> >> -        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
> 
>     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 / dgilbert@redhat.com / Manchester, UK


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

* Re: [Qemu-devel] [PATCH] migration: check length directly to make sure the range is aligned
  2019-07-19 17:54 ` Dr. David Alan Gilbert
  2019-07-19 18:03   ` Paolo Bonzini
@ 2019-08-19  2:26   ` Wei Yang
  2019-09-13 23:58   ` Wei Yang
  2 siblings, 0 replies; 7+ messages in thread
From: Wei Yang @ 2019-08-19  2:26 UTC (permalink / raw)
  To: Dr. David Alan Gilbert; +Cc: qemu-devel, pbonzini, quintela, Wei Yang, rth

On Fri, Jul 19, 2019 at 06:54:00PM +0100, Dr. David Alan Gilbert wrote:
>* Wei Yang (richardw.yang@linux.intel.com) wrote:
>> Since the start addr is already checked, to make sure the range is
>> aligned, checking the length is enough.
>> 
>> Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
>> ---
>>  exec.c | 7 +++----
>>  1 file changed, 3 insertions(+), 4 deletions(-)
>> 
>> diff --git a/exec.c b/exec.c
>> index 50ea9c5aaa..8fa980baae 100644
>> --- a/exec.c
>> +++ b/exec.c
>> @@ -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?
>
>Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
>

Hi, David

Do you like this one?

>>              goto err;
>>          }
>>  
>> -- 
>> 2.17.1
>> 
>--
>Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK

-- 
Wei Yang
Help you, Help me


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

* Re: [Qemu-devel] [PATCH] migration: check length directly to make sure the range is aligned
  2019-07-19 17:54 ` Dr. David Alan Gilbert
  2019-07-19 18:03   ` Paolo Bonzini
  2019-08-19  2:26   ` Wei Yang
@ 2019-09-13 23:58   ` Wei Yang
  2 siblings, 0 replies; 7+ messages in thread
From: Wei Yang @ 2019-09-13 23:58 UTC (permalink / raw)
  To: Dr. David Alan Gilbert; +Cc: qemu-devel, pbonzini, quintela, Wei Yang, rth

On Fri, Jul 19, 2019 at 06:54:00PM +0100, Dr. David Alan Gilbert wrote:
>* Wei Yang (richardw.yang@linux.intel.com) wrote:
>> Since the start addr is already checked, to make sure the range is
>> aligned, checking the length is enough.
>> 
>> Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
>> ---
>>  exec.c | 7 +++----
>>  1 file changed, 3 insertions(+), 4 deletions(-)
>> 
>> diff --git a/exec.c b/exec.c
>> index 50ea9c5aaa..8fa980baae 100644
>> --- a/exec.c
>> +++ b/exec.c
>> @@ -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?
>
>Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
>

Any other task I should do for progress?

>>              goto err;
>>          }
>>  
>> -- 
>> 2.17.1
>> 
>--
>Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK

-- 
Wei Yang
Help you, Help me


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

* Re: [Qemu-devel] [PATCH] migration: check length directly to make sure the range is aligned
  2019-07-19 18:06     ` Dr. David Alan Gilbert
@ 2019-10-01  7:54       ` Wei Yang
  0 siblings, 0 replies; 7+ messages in thread
From: Wei Yang @ 2019-10-01  7:54 UTC (permalink / raw)
  To: Dr. David Alan Gilbert; +Cc: Paolo Bonzini, rth, Wei Yang, qemu-devel, quintela

On Fri, Jul 19, 2019 at 07:06:51PM +0100, Dr. David Alan Gilbert wrote:
>* Paolo Bonzini (pbonzini@redhat.com) wrote:
>> On 19/07/19 19:54, Dr. David Alan Gilbert wrote:
>> >> -        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

Dave,

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

>> 
>>     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 / dgilbert@redhat.com / Manchester, UK

-- 
Wei Yang
Help you, Help me


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

end of thread, back to index

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-12  3:27 [Qemu-devel] [PATCH] migration: check length directly to make sure the range is aligned Wei Yang
2019-07-19 17:54 ` Dr. David Alan Gilbert
2019-07-19 18:03   ` Paolo Bonzini
2019-07-19 18:06     ` Dr. David Alan Gilbert
2019-10-01  7:54       ` Wei Yang
2019-08-19  2:26   ` Wei Yang
2019-09-13 23:58   ` Wei Yang

QEMU-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/qemu-devel/0 qemu-devel/git/0.git
	git clone --mirror https://lore.kernel.org/qemu-devel/1 qemu-devel/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 qemu-devel qemu-devel/ https://lore.kernel.org/qemu-devel \
		qemu-devel@nongnu.org qemu-devel@archiver.kernel.org
	public-inbox-index qemu-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.nongnu.qemu-devel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox