All of lore.kernel.org
 help / color / mirror / Atom feed
From: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
To: Keir Fraser <keir.fraser@eu.citrix.com>
Cc: xen-devel <xen-devel@lists.xensource.com>,
	Xiao Guangrong <ericxiao.gr@gmail.com>
Subject: Re: [PATCH] e820: fix clip_to_limit()
Date: Tue, 10 Nov 2009 10:13:01 +0800	[thread overview]
Message-ID: <4AF8CC2D.6050701@cn.fujitsu.com> (raw)
In-Reply-To: <C71E3015.19A67%keir.fraser@eu.citrix.com>

Hi Keir,

Keir Fraser wrote:
> I think the 'break' is in the wrong place. Actually also I think the case of

Why we can't break the loop if we meet the "large" end address? what am i missed?

> successful change_range_type() is also wrong, as i=0 will be skipped on the
> next iteration of the loop.
> 
> Overall I decided that modifying the e820 map inside the iterator loop was
> just bad and confusing, so I've rewritten it in response to your bug
> discovery. Please take a look at xen-unstable:20419 and let me know if you
> see any issues.

Your patch work well, IMHO, double loop is inefficient, we can decrease the
loop counter if we need "memmove" it, like this:

    if ( e820.map[i].addr < limit )
    {
       e820.map[i].size = limit - e820.map[i].addr;
    }
    else
    {
       memmove(&e820.map[i], &e820.map[i+1],
      (e820.nr_map - i - 1) * sizeof(struct e820entry));
       e820.nr_map--;
 +      i--;	
    }

Also in the original code:

   if ( e820_change_range_type(&e820, max(e820.map[i].addr, limit),
                               old_limit, E820_RAM, E820_UNUSABLE) )
   {
        /* Start again now e820 map must have changed. */
       i = 0;
   }

I think we don't need reload loop hear, because e820_change_range_type() not
touch front object(it may merge with e820.map[i+1], but it not hurt us).

Thanks,
Xiao

> 
> On 09/11/2009 20:04, "Xiao Guangrong" <ericxiao.gr@gmail.com> wrote:
> 
>> In clip_to_limit(), after memmove(&e820.map[i], &e820.map[i+1], ...), the
>> original
>> e820.map[i+1] become current e820.map[i] but the next loop count is i+1, so
>> the original
>> e820.map[i+1] will be skipped
>>
>> Actually, e820 is sorted form low to high by sanitize_e820_map(), so we can
>> simply break
>> the loop if we meet the item which overrun "limit"
>>
>> Signed-off-by: Xiao Guangrong <ericxiao.gr@gmail.com>
>>
>> diff -r 93bc06dd1161 -r 5e06f2790d93 xen/arch/x86/e820.c
>> --- a/xen/arch/x86/e820.c Tue Nov 10 02:41:59 2009 +0800
>> +++ b/xen/arch/x86/e820.c Tue Nov 10 03:51:08 2009 +0800
>> @@ -389,6 +389,7 @@
>>                       (e820.nr_map - i - 1) * sizeof(struct e820entry));
>>               e820.nr_map--;
>>           }
>> + break;
>>       }
>>
>>       if ( old_limit )
> 
> 
> 
> 

  reply	other threads:[~2009-11-10  2:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-09 20:04 [PATCH] e820: fix clip_to_limit() Xiao Guangrong
2009-11-09 20:46 ` Keir Fraser
2009-11-10  2:13   ` Xiao Guangrong [this message]
2009-11-10  7:45     ` Keir Fraser
2009-11-10  8:19       ` Xiao Guangrong
2009-11-10  8:39         ` Keir Fraser
2009-11-10  9:18           ` Xiao Guangrong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4AF8CC2D.6050701@cn.fujitsu.com \
    --to=xiaoguangrong@cn.fujitsu.com \
    --cc=ericxiao.gr@gmail.com \
    --cc=keir.fraser@eu.citrix.com \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.