Subject: uvm_map ?
To: None <tech-kern@netbsd.org>
From: Nalin Gupta <nalingupta2000@gmail.com>
List: tech-kern
Date: 04/11/2007 11:42:32
hello

Is uvm_map enough to attach kernel memory to user process ?

regards,
- nalin

---------- Forwarded message ----------
From: Nalin Gupta <nalingupta2000@gmail.com>
Date: Apr 10, 2007 8:12 PM
Subject: map/attach wired kernel memory to user space process... ?
To: tech-kern@netbsd.org


Hello,

Could some one guide me how to attach wired kernel memory to user
space process(es) ?
Surely I'm doing many mistakes, any help shall be very appreciable.

In code Below, I assume to be allocating phy wired mem using
uvm_km_kmemalloc1 and later to user process, I am trying to attach
using uvm_map. Am I right ?

Further, within uvm_map, I assume "attach_va", gives me virtual address,
where wired mem gets attached. Again am I right ?

regards,
- nalin

CODE

I wrote a loadable char dev module, which allocate wired memory at load time:
-------- [snip] -----------
logPoolSize = (logPoolSize + PGOFSET) & ~PGOFSET;  /* multiple of Page size */
alfLogMgr.uvmObject   = uao_create( logPoolSize, 0 );
uao_reference(alfLogMgr.uvmObject);
allocFlags = UVM_KMF_NOWAIT ;
alfLogMgr.wiredMemory = uvm_km_kmemalloc1( kernel_map,
                                                  alfLogMgr.uvmObject,
                                                  logPoolSize,
                                                  1, /*align */
                                                  0, /*pref offset */
                                                  allocFlags /* flags */
                                                );
-------- [snip] -----------
later then a user space process access this module (open or ioctl),
so to allocate and attach its virtual space to memory allocated above,
as follows:
-------- [snip] -----------
      uao_reference(alfLogMgr.uvmObject);
//    attach_va = VM_DEFAULT_ADDRESS(p->p_vmspace->vm_daddr, logPoolSize);
      attach_va = 0;
      error = uvm_map( &p->p_vmspace->vm_map,
                        &attach_va,
                        logPoolSize,
                        alfLogMgr.uvmObject,
                        0,
                        0,
                        UVM_MAPFLAG(UVM_PROT_RW, UVM_PROT_RW,
                                     UVM_INH_SHARE, UVM_ADV_NORMAL, 0)
/* flags */
                      ) ;
-------- [snip] -----------