DEBUG_PAGEALLOC on PPC not working (kernels 2.6-25, 3.0-34)

Scott Wood scottwood at freescale.com
Thu Jun 20 07:00:46 EST 2013


On 06/19/2013 08:09:44 AM, saikia.partha wrote:
> Hi,
> 
> We have two Freescale PowerPC boards on which we're trying to enable
> DEBUG_PAGEALLOC with the hope that we'll see an exception whenever  
> some
> code tries to modify a page that's been already freed. To test it, we  
> wrote
> this sample code -
> 
> ===
> #define BUF_SIZE    4096
> void
> pagealloc_test(void)
> {
>     char *buf = kmalloc(BUF_SIZE, GFP_KERNEL);
> 
>     if (!buf) {
>         printk("%s[%d] - alloc failed!\n", __func__, __LINE__);
>         return;
>     }
>     printk("%s[%d] - alloc'd\n", __func__, __LINE__);
>     memset(&buf[0], 0, BUF_SIZE);
>     printk("%s[%d] - memset'd\n", __func__, __LINE__);
>     kfree(buf);
>     printk("%s[%d] - free'd\n", __func__, __LINE__);
>     memset(&buf[0], 1, BUF_SIZE);
>     printk("%s[%d] - memset'd after free!\n", __func__, __LINE__);
> }
> ===
> 
> Here, the last memset() should generate an exception if PAGEALLOC code
> correctly unmapped the page during kfree(). However, kernel is happily
> running after the memset post-free. Any clue?
> Also, the 2nd board has Book-E which has a different MMU architecture.
> Here, I saw that the function __change_page_attr() always returns as  
> the
> condition v_mapped_by_tlbcam() is true. How do we remove the pte  
> entry from
> the TLB in this case?  Has anyone tried DEBUG_PAGEALLOC on Book-E?

This is not supported on booke -- the tlbcam mapping is required for  
all lowmem.

> Please find the board details below -
> Board 1: CPU - e300c4, kernel 2.6-25

For e300, I think I had it working at one point a few years ago (see  
commit bde6c6e16aa489ea76c762fb7ffb0abb48660dd8).

The reason we can do it on e300 and not on booke is because e300 takes  
exceptions in real mode.  On e500 the MMU is always enabled, so we need  
bolted TLB1 entries that cover at least all exception code (up to the  
point where a TLB miss could safely be taken) and all page tables (in  
practice, we just bolt all lowmem) and other data that can be  
referenced from said exception code.  There are not enough TLB1 entries  
to do this on a fine-grained basis.

-Scott


More information about the Linuxppc-dev mailing list