Re: [PATCH] [1/9] Handle kernel near memory hole inclear_kernel_mapping

From: Andi Kleen
Date: Thu Jan 31 2008 - 11:22:33 EST


> > +#define overlaps(as, ae, bs, be) ((ae) >= (bs) && (as) <= (be))
>
> inline function please and a bit more intuituive arrangement of
> arguments.

Which one do you prefer? (to be honest the current one is "intuitive"
to me)


>
> > +void __init clear_kernel_mapping(unsigned long address, unsigned long size)
> > +{
> > + int sh = PMD_SHIFT;
> > + unsigned long kernel = __pa(__START_KERNEL_map);
> > +
> > + /*
> > + * Note that we cannot unmap the kernel itself because the unmapped
> > + * holes here are always at least 2MB aligned.
>
> That's not enforced. The unmap code just does not split pages.

It is -- there are BUG_ONs for this in __clear_kernel_mapping

>
> > + * This just applies to the trailing areas of the 40MB kernel mapping.
>
> How is this ensured, that it only affects the end of the 40MB mapping ?

It is enforced in the callers (actually there is only a single caller --
the GART code ) by not calling it overlapping for the kernel itself.
Given that could be checked too, but that would be probably overkill
for an internal function.

>
> > + */
> > + if (overlaps(kernel >> sh, (kernel + KERNEL_TEXT_SIZE) >> sh,
> > + __pa(address) >> sh, __pa(address + size) >> sh)) {
>
> This checks:
>
> (kernel_end + 1) >= gart_start && kernel_start <= gart_end
>
> One off error: kernel + KERNEL_TEXT_SIZE
> needs to be: kernel + KERNEL_TEXT_SIZE - 1

Ok.

>
> Also there is no sanity check, whether the area is inside real kernel text.

Hmm I can add one, but if that happens the caller is likely seriously
confused and will likely cause other problems anyways.

I don't think it can happen for the GART code which is currently
the only caller.

>
> > + printk(KERN_WARNING
> > + "Kernel mapping at %lx within 2MB of memory hole\n",
> > + kernel);
>
>
> > + __clear_kernel_mapping(__START_KERNEL_map+__pa(address), size);
>
> Doh! This is unmapping the wrong place. According to __phys_addr():
>
> paddr = vaddr - __START_KERNEL_map + phys_base;

Hmm true -- that will only affect relocatable kernels, but for those
it's wrong. Given that the patch was supposed to fix a case
that only happens relocatable kernels that's quite ironic :)

Actually thinking about it again you can just drop it for now.
It is orthogonal to gbpages. I think I added it to the series
when I was planning to do kernel mapping as GB pages, but that
turned out to be a bad idea anyways.

Thanks for the review,

-Andi
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/