public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Need help about how linux to handle translation fault
@ 2011-08-12  7:37 Pecker Hu
  2011-08-12 11:27 ` Clemens Ladisch
  0 siblings, 1 reply; 2+ messages in thread
From: Pecker Hu @ 2011-08-12  7:37 UTC (permalink / raw)
  To: linux-kernel

Dear all:

I am a newer,I hope someone can help me about how linux to handle
translation fault(ARM architecture)

I define a string arrary in user space code:
unsignd char str[20] = "abcdefg";

And I send the address of str to kernel space using IOCTL interface.
ioctl(fd, VM_TEST_GET_VADDR, str);

When I try to use pgd to find the physical address, I don't find it
.But after calling copy_from_user,I can find physical address through
pgd.I don' know why?
/* user space address convert to physical address , if pte is NULL ,
it will return zero */
static unsigned long uva_to_pa(struct mm_struct *mm, unsigned long addr)
{
	unsigned long ret = 0UL;
	pgd_t *pgd;
	pud_t *pud;
	pmd_t *pmd;
	pte_t *pte;

	pgd = pgd_offset(mm, addr);
	if (!pgd_none(*pgd)) {
		pud = pud_offset(pgd, addr);
		if (!pud_none(*pud)) {
			pmd = pmd_offset(pud, addr);
			if (!pmd_none(*pmd)) {
				pte = pte_offset_map(pmd, addr);
				if (!pte_none(*pte) && pte_present(*pte)) {
					/* Use hard PTE */
					pte = (pte_t *)((u32)pte - 2048);
					if(pte)
						ret = (*pte & 0xfffff000) | (addr & 0xfff);
				} else {
					printk("pet is not present:0x%08x\n", (*pte & 0xfffff000) | (addr
& 0xfff));
				}
			}
		}
	}
	return ret;
}

So I think string array is located in data cache not in physical
memory, after I call copy_from_user, kernel will allocate page for it,
then we can access it, is it right?


Thanks
Best regards.

Pecker Hu

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-08-12 11:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-12  7:37 Need help about how linux to handle translation fault Pecker Hu
2011-08-12 11:27 ` Clemens Ladisch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox