Skip to contentSkip to conversation

cleanup for __start_xen()

PATCH In review Xiao Guangrong 4 participants 8 messages Nov 30, 2009 – Dec 1, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cleanup for __start_xen()

Remove repetitive judgment in __start_xen()

b/xen/arch/x86/setup.c renamed from a/xen/arch/x86/setup.c +2 -2
index d87d082..563e46a 100644
@@ -729,7 +729,7 @@ void __init __start_xen(unsigned long mbi_p)
 #endif
 
         /* Is the region suitable for relocating the multiboot modules? */
-        if ( !initial_images_start && (s < e) &&
+        if ( !initial_images_start &&
              ((e-s) >= (modules_length+modules_headroom)) )
         {
             initial_images_end = e;
@@ -747,7 +747,7 @@ void __init __start_xen(unsigned long mbi_p)
             }
         }
 
-        if ( !kexec_crash_area.start && (s < e) &&
+        if ( !kexec_crash_area.start &&
              ((e-s) >= kexec_crash_area.size) )
         {
             e = (e - kexec_crash_area.size) & PAGE_MASK;
#1 lore raw

Xiao Guangrong writes ("[Xen-devel] [PATCH] cleanup for __start_xen()"):

Quoted 9 lines

Remove repetitive judgment in __start_xen()

b/xen/arch/x86/setup.c renamed from a/xen/arch/x86/setup.c +0 -0
index d87d082..563e46a 100644

b/xen/arch/x86/setup.c void __init __start_xen(unsigned long mbi_p) · line 732

Quoted 5 lines
b/xen/arch/x86/setup.c renamed from a/xen/arch/x86/setup.c +1 -1
@@ -729,7 +729,7 @@ void __init __start_xen(unsigned long mbi_p)
 #endif
 
         /* Is the region suitable for relocating the multiboot modules? */
-        if ( !initial_images_start && (s < e) &&
+        if ( !initial_images_start &&

This is wrong. s and e are uint64_t so if !(s < e), (e-s) will be large and positive.

Ian.

#2 lore raw
Quoted 6 lines · I wrote:

Xiao Guangrong writes ("[Xen-devel] [PATCH] cleanup for __start_xen()"):

b/xen/arch/x86/setup.c void __init __start_xen(unsigned long mbi_p) · line 732

Quoted 2 lines
b/xen/arch/x86/setup.c renamed from a/xen/arch/x86/setup.c +1 -1
-        if ( !initial_images_start && (s < e) &&
+        if ( !initial_images_start &&

This is wrong. s and e are uint64_t so if !(s < e), (e-s) will be large and positive.

I see this has already been applied (20523). It should be reverted, I think.

Ian.

#3 lore raw
Quoted 10 lines · Ian Jackson
Quoted 6 lines · I wrote:

Xiao Guangrong writes ("[Xen-devel] [PATCH] cleanup for __start_xen()"):

b/xen/arch/x86/setup.c void __init __start_xen(unsigned long mbi_p) · line 732

Quoted 2 lines
b/xen/arch/x86/setup.c renamed from a/xen/arch/x86/setup.c +1 -1
-        if ( !initial_images_start && (s < e) &&
+        if ( !initial_images_start &&

This is wrong. s and e are uint64_t so if !(s < e), (e-s) will be large and positive.

I see this has already been applied (20523). It should be reverted, I think.

None of the if() blocks in the loop will make e<s, as that would imply that the block had allocated itself a chunk of memory that starts below s. So it is actually safe to remove the checks, as we know e>=s. But now I look at it I think I broke the module-relocation block some time ago -- it ends up with 'e' being too large by modules_headroom. :-( Will look into that more tomorrow...

-- Keir

#4 lore raw
Quoted 11 lines · Keir Fraser
Quoted 8 lines · Ian Jackson
Quoted 5 lines · I wrote:

Xiao Guangrong writes ("[Xen-devel] [PATCH] cleanup for __start_xen()"):

b/xen/arch/x86/setup.c void __init __start_xen(unsigned long mbi_p) · line 732

Quoted 2 lines
b/xen/arch/x86/setup.c renamed from a/xen/arch/x86/setup.c +1 -1
-        if ( !initial_images_start && (s < e) &&
+        if ( !initial_images_start &&

This is wrong. s and e are uint64_t so if !(s < e), (e-s) will be large and positive.

I see this has already been applied (20523). It should be reverted, I think.

Quoted 7 lines

None of the if() blocks in the loop will make e<s, as that would imply that the block had allocated itself a chunk of memory that starts below s. So it is actually safe to remove the checks, as we know e>=s. But now I look at it I think I broke the module-relocation block some time ago -- it ends up with 'e' being too large by modules_headroom. :-( Will look into that more tomorrow...

I thinks remove this judgment is very safe, because we have judge it at the begin of this loop:

for ( i = boot_e820.nr_map-1; i >= 0; i-- )

    {
        uint64_t s, e, mask = (1UL << L2_PAGETABLE_SHIFT) - 1;
	
	<snip>

	if ( (boot_e820.map[i].type != E820_RAM) || (s >= e) )	/* NOTICE HERE*/
            continue;
	
	/* it must s < e while run below code, not need check it again ... */
	......
}

Thanks,
Xiao

#5 lore raw
Quoted 24 lines · Xiao Guangrong
Quoted 8 lines · Keir Fraser
Quoted 6 lines · Ian Jackson
Quoted 5 lines · I wrote:

Xiao Guangrong writes ("[Xen-devel] [PATCH] cleanup for __start_xen()"):

b/xen/arch/x86/setup.c void __init __start_xen(unsigned long mbi_p) · line 732

Quoted 2 lines
b/xen/arch/x86/setup.c renamed from a/xen/arch/x86/setup.c +1 -1
-        if ( !initial_images_start && (s < e) &&
+        if ( !initial_images_start &&

This is wrong. s and e are uint64_t so if !(s < e), (e-s) will be large and positive.

Quoted 9 lines
Quoted 2 lines

I see this has already been applied (20523). It should be reverted, I think.

None of the if() blocks in the loop will make e<s, as that would imply that the block had allocated itself a chunk of memory that starts below s. So it is actually safe to remove the checks, as we know e>=s. But now I look at it I think I broke the module-relocation block some time ago -- it ends up with 'e' being too large by modules_headroom. :-( Will look into that more tomorrow...

I thinks remove this judgment is very safe, because we have judge it at the begin of this loop:

for ( i = boot_e820.nr_map-1; i >= 0; i-- )

Quoted 12 lines
    {
        uint64_t s, e, mask = (1UL << L2_PAGETABLE_SHIFT) - 1;
	
	<snip>

	if ( (boot_e820.map[i].type != E820_RAM) || (s >= e) )	/* NOTICE HERE*/
            continue;
	
	/* it must s < e while run below code, not need check it again ... */
	......
}

And after below if():
if ( !initial_images_start && (s < e) &&

             ((e-s) >= (modules_length+modules_headroom)) )
        {
            initial_images_end = e;
            e = (e - modules_length) & PAGE_MASK;
            initial_images_start = e;
            e -= modules_headroom;
            initial_images_base = e;
            e += modules_length + modules_headroom;
            for ( j = mbi->mods_count-1; j >= 0; j-- )
            {
                e -= mod[j].mod_end - mod[j].mod_start;
                move_memory(e, mod[j].mod_start, mod[j].mod_end);
                mod[j].mod_end += e - mod[j].mod_start;
                mod[j].mod_start = e;
            }
        }
}

e is moved in [e-(modules_length+modules_headroom), e] range, so, s is not overrun e too...

#6 lore raw
Quoted 2 lines · Xiao Guangrong

e is moved in [e-(modules_length+modules_headroom), e] range, so, s is not overrun e too...

OK, but:
- this is not obvious (hence this thread);
- even Keir makes mistakes here from time to time; and
- it's a single test on code that runs at start of day
so maybe we should just leave it as it was?

Cheers,

Tim.

Signature · 3 lines
Tim Deegan <[email protected]>
Principal Software Engineer, Citrix Systems (R&D) Ltd.
[Company #02300071, SL9 0DZ, UK.]
#7 lore raw
Quoted 9 lines · Tim Deegan
Quoted 2 lines · Xiao Guangrong

e is moved in [e-(modules_length+modules_headroom), e] range, so, s is not overrun e too...

OK, but:
- this is not obvious (hence this thread);
- even Keir makes mistakes here from time to time; and
- it's a single test on code that runs at start of day
so maybe we should just leave it as it was?

I'll put it back and fix my other pre-existing mistake also.

-- Keir