Re: Interrupt and spin_lock

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Monday 22 August 2005 07:13, Gaurav Dhiman wrote:
> Can you please paste your whole code if its not too big.
> Just guessing, as page fault handler is executed whenever page fault
> occures which is an exception and not an interrupt, so using irq
> enable spinlocks might not help. Well it wud be better if you can
> provide the whole code.

I make things simpler by cutting down useless lines.

First, data structures used:

struct mtpmc_wrprotected_pages{
    struct list_head list;
    unsigned long address;
};

struct mtpmc_vm_wrprotected{ 
    struct list_head list;
    struct list_head pages_list;
    unsigned long vm_start;
    unsigned long vm_end;
};

I think these are self-explained.

Then, the function that scans lists:

int mtpmc_protected_by_us(unsigned long addr, int rw)
{
    struct mtpmc_vm_wrprotected *wr_vma;
    struct list_head *vma_list, *page_list;
    struct mtpmc_wrprotected_pages *wr_page;
/* LOCK */
    spin_lock_irqsave(&write_protected_lock, flags_lock);

    list_for_each(vma_list, &vm_write_protected){
        wr_vma = list_entry(vma_list, struct mtpmc_vm_wrprotected, list);
        list_for_each_safe(page_list, &wr_vma->pages_list){
            wr_page = list_entry(page_list, struct mtpmc_wrprotected_pages, 
list);
            if (wr_page's address is one of the address we've write protected)
            {
                    spin_unlock_irqrestore(&write_protected_lock, flags_lock);
                    return 1;
            }
        }
/* UNLOCK */
        spin_unlock_irqrestore(&write_protected_lock, flags_lock);
        return 0;      
}

The function above is called from within the page fault handler function I 
create.

Now, the function that fills the lists:

void mtpmc_set_mm_not_writable(struct mm_struct *mm)
{
    struct mtpmc_vm_wrprotected *vma;
    struct mtpmc_wrprotected_pages *page;
    struct vm_area_struct *vm;
    unsigned long addr;
    pte_t *pte;

    down_write(&mm->mmap_sem);

    for(vm = mm->mmap; vm != NULL; vm = vm->vm_next)
            /* this instruction create the needed structure for vma list */                  
           vma = mtpmc_mk_vm_wrprotected(vm);
            spin_lock_irqsave(&write_protected_lock, flags_lock);
            list_add_tail(&vma->list, &vm_write_protected);
            spin_unlock_irqrestore(&write_protected_lock, flags_lock);
            INIT_LIST_HEAD(&vma->pages_list);
            for (addr = vm->vm_start; addr<vm->vm_end; addr+=PAGE_SIZE){
                 /*get the pte of the page with address "addr" */
                pte = mtpmc_get_pte_from_address(mm, addr); 
                if (pte != NULL)
                /* if the page isn't already write protected */
                    if (pte_write(*pte)){
                       /*write protect it*/
                        set_pte(pte, pte_wrprotect(*pte));
                         /* this instruction create the needed structure for 
                             page list */
                        page = mtpmc_mk_page_wrprotected(addr);
  /* LOCK --> */   spin_lock_irqsave(&write_protected_lock, flags_lock); 
                        list_add_tail(&page->list, &vma->pages_list);
/*UNLOCK --> */spin_unlock_irqrestore(&write_protected_lock, flags_lock);
                    }
            }

    up_write(&mm->mmap_sem);
    return;
} 

I' hoe the code I've posted is not too big.
I'll re-post the error type:


Unable to handle kernel NULL pointer dereference at virtual address 00000000.
              ...............
<0>kernel panic: Aiee, killing interrupt handler
In interrupt handler - not syncing

I hoe you've some suggests for me. 
I really ignore where is the problem and how I can resolve it. 
I go in panic any times the kernel goes in panic (Vincenzo panic).
Thanks.
Vincenzo Mallozzi.



	

	
		
___________________________________ 
Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB 
http://mail.yahoo.it


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux