Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 30 Mar 2010 11:28:31 -0700 (PDT)
From:      "Dr. Baud" <drbaud@yahoo.com>
To:        freebsd-current@freebsd.org
Subject:   Re: pmap_extract question
Message-ID:  <925011.22864.qm@web65606.mail.ac4.yahoo.com>

next in thread | raw e-mail | index | archive | help
=0A   It was pointed out that you need to pass physical address to mmap. A =
step was missed in posted recipe. Consider that the return from vtophys(mem=
ory_chunk) was passed at the offset parameter. Sorry for the confusion.=0A=
=0A--- On Tue, 3/30/10, Dr. Baud <drbaud@yahoo.com> wrote:=0A=0A> From: Dr.=
 Baud <drbaud@yahoo.com>=0A> Subject: pmap_extract question=0A> To: freebsd=
-current@freebsd.org=0A> Date: Tuesday, March 30, 2010, 12:35 PM=0A> =0A> =
=A0 =A0 Say I have a kernel module that allocates a=0A> contiguous chunk of=
 kernel physical memory (note that a call=0A> to vtophys() reports a non-ze=
ro value):=0A> =0A> memory_chunk =3D contigmalloc(=A0 =A0=0A> memory_chunk_=
length,=0A> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=0A> =A0 =A0 =A0 =A0 =A0 =A0 =A0=
 =A0=0A> NULL,=0A> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=0A> =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0=0A> M_NOWAIT,=0A> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=0A> =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0=0A> 0UL,=0A> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=0A> =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=0A> ~0UL,=0A> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0=0A> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=0A> PAGE_SIZE,=0A> =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0=0A> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 0);=0A> =0A> =A0 =A0 Th=
e kernel virtual address returned from=0A> contigmalloc is passed to a user=
 application which maps the=0A> chunk to the virtual address space of the a=
pplication:=0A> =0A> fd =3D open("/dev/mem", O_RDWR);=0A> mapped_memory_chu=
nk =3D mmap( NULL,=0A> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=0A> =A0 =A0 =A0 =A0 =
=A0 =A0=0A> memory_chunk_length,=0A> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=0A> =
=A0 =A0 =A0 =A0 =A0 =A0 PROT_READ |=0A> PROT_WRITE,=0A> =A0 =A0 =A0 =A0 =A0=
 =A0 =A0 =A0=0A> =A0 =A0 =A0 =A0 =A0 =A0 MAP_SHARED,=0A> =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0=0A> =A0 =A0 =A0 =A0 =A0 =A0 fd,=0A> =A0 =A0 =A0 =A0 =A0 =A0=
 =A0 =A0=0A> =A0 =A0 =A0 =A0 =A0 =A0 (off_t)=0A> memory_chunk);=0A> =0A> =
=A0 =A0 Now consider that the mapped memory chunk=0A> address is then passe=
d back to the kernel module. My=0A> question is; shouldn't pmap_extract(9) =
be able to determine=0A> the physical address?=0A> =0A> struct thread *td =
=3D curthread;=0A> pmap_t pmap =3D=0A> &td->td_proc->p_vmspace->vm_pmap;=0A=
> physical_address =3D pmap_extract(pmap,=0A> mapped_memory_chunk);=0A> =0A=
> =A0 =A0 In this example pmap_extract returns 0. Note=0A> also that /proc/=
<pid>/map indicates the page(s)=0A> associated with the virtual addresses a=
re not resident,=0A> e.g.:=0A> =0A> 0x801731000 0x801732000 0 0 0xffffff01d=
1ecd360 rw- 10 0=0A> 0x1000 NCOW NNC device -=0A> =0A> =A0 =A0 The first tw=
o values shown are the start=0A> (address returned from mmap above) and end=
 addresses. The=0A> third, in this case zero, is intended to represent whet=
her=0A> the pages are in resident. This value is simply the result=0A> of a=
 call to pmap_extract.=0A> =0A> =A0 =A0 Is this to be expected? Should mmap=
(2) serve=0A> up a virtual address which pmap_extract cannot determine the=
=0A> physical address? Or is there a flaw in this logic?=0A> =0A> =A0 =A0 T=
hanks in advance......=0A> =0A> =A0 =A0 Dr=0A> =0A> =0A> =0A> =0A> =0A> =A0=
 =A0 =A0 =0A> =0A=0A=0A      



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?925011.22864.qm>