Do I need spin_lock before pgd/pmd/pte_offset?

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

 



I can't seem to find a definitive answer to this question. I have this code which takes a user-space virtual address and converts it to a physical address:

        pgd_t *pgd = pgd_offset(current->mm, address);
        pmd_t *pmd = pmd_offset(pgd, address);
        pte_t *pte = pte_offset_map(pmd, address);
        pte_t _pte = *pte;
        pte_unmap(pte);

        return pte_val(_pte) & PTE_MASK;

Nothing unusual here. The question is, do I need to protect this code with a spinlock? That is, should I change the above to:

	spin_lock(&current->mm->page_table_lock);
        pgd_t *pgd = pgd_offset(current->mm, address);
        pmd_t *pmd = pmd_offset(pgd, address);
        pte_t *pte = pte_offset_map(pmd, address);
        pte_t _pte = *pte;
        pte_unmap(pte);
	spin_unlock(&current->mm->page_table_lock);

I'm guessing I only need to call a spinlock if the page isn't locked in memory. Is that correct?

--
Timur Tabi
Staff Software Engineer
timur.tabi@ammasso.com

--
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