killing process from interrupt

2009-04-30 Thread Alexej Sokolov
Hello,
I have in my interrupt function the pointer to structure of some process.
What is the safe way to kill the process?

psignal (p, 9);  ?

Thanx
Alexej
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


Intel Pro 82546GB COPPER. Frames reception by disabled interrupts

2009-03-26 Thread Alexej Sokolov
Hello,

interrupts disable:  E1000_WRITE_REG(&adapter->hw, E1000_IMC, 0x);
this clears interrupt mask register.

Question: Will network adapter accept incoming frames and transfer them to
hast memory by disabled interrupts ?

Thenx,
Alexej
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


Re: rebuilding libpcap

2009-03-16 Thread Alexej Sokolov
Ohhh... thanks a lot ! I'am jaust about to do it...

2009/3/16 Dan Nelson 

> In the last episode (Mar 16), Alexej Sokolov said:
> > how to correctly rebuild only libpcap from /usr/src/contrib without
> > rebuilding the whole world ?  I try to do in libpcap some changes, then
> > make; make install in
> > /usr/src/contrib/libpcap,
> > but the changes are not visible by calling changed functions :(
> > What I do wrong ?
>
> /usr/src/contrib is a repository of 3rd-party source trees, and they're not
> meant to be built from.  Try running your "make ; make install" in
> /usr/src/lib/libpcap instead.
>
> --
>Dan Nelson
>dnel...@allantgroup.com
> ___
> freebsd-hackers@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"
>
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


rebuilding libpcap

2009-03-16 Thread Alexej Sokolov
Hello,
how to correctly rebuild only libpcap from /usr/src/contrib without
rebuilding the whole world ?
I try to do in libpcap some changes, then make; make install in
/usr/src/contrib/libpcap,
but the changes are not visible by calling changed functions :(
What I do wrong ?

Thanks,
Alexej

P.S: % uname -v
FreeBSD 7.0-RELEASE-p10 #1: Mon Mar 16 16:58:38 CET 2009
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


Re: Problems mapping an vm_object to a process memory space

2009-03-13 Thread Alexej Sokolov
hi ,
I had a problem with remapping too. Could I see your code?
here is my code, that some times on AMD64 runs wrong :
http://pastebin.com/m78da0b37

And now I solved the problem with remapping by using /dev/mem device. It has
mmap syscal. And it seems to be working without problem.

Alexej
<

2009/3/13 Pekka Nikander 

> As a part of a research project, I'm trying to build publish/subscribe
> shared memory semantics where the idea is to first map an vm_object as
> read/write to a publisher's memory space, and then a COW shadow of that
> later to the subscriber processes' memory space.
>
> I've got to the point where the code works most of the time, but at certain
> scenarios (which are hard to classify and seem slightly random) the mapping
> goes wrong, and either the subscriber process has no physical mapping at the
> supposed address or there appears some random page.   To me it appears as if
> the vm_object, vm_map etc data structures are OK, but somehow the pmaps
> don't get right.  I'm currently using 7.1 RELEASE on amd64, but I'm planning
> to try the same on -CURRENT as soon as I get it properly ported.  I even
> tried calling pmap_enter_object explicitly before returning to the user
> space, but it doesn't seem to help.
>
> Another thing is that there may be some bugs related OBJ_ONEMAPPING.  We
> need to explicitly clear it at places, and sometimes artificially bump up
> the vm_object reference count to avoid code related to ONEMAPPING from
> trashing the object's mappings.  Is this a known issue?
>
> Any advice?
>
> --Pekka Nikander
>
> ___
> freebsd-hackers@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"
>
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


Fwd: write protection by mmap of /dev/mem doesn't work

2009-03-10 Thread Alexej Sokolov
Sorry,
it was my mistake !
seg fault was by reading of data. To do this should PROT_READ|PROT_WRITE be
setted.
Now it works!

Alexej


-- Forwarded message --
From: Alexej Sokolov 
Date: 2009/3/10
Subject: write protection by mmap of /dev/mem doesn't work
To: freebsd-hackers@freebsd.org


hello,
How can I mmap some memory regions with PROT_WRITE protection flag ?
What i do:
 /* Open mem device */
if ((devmem_fd = open("/dev/mem", O_RDWR)) == -1){
perror("/dev/mem");
exit (1);
}

then if I try to mmap some memory region with PROT_READ it goes Ok. But by
PROT_WRITE it doesn't work:
sp =mmap (  0,
   MCLBYTES,   /* Size of remapped buffer = size of
mbuf cluster */
   PROT_WRITE,
   MAP_SHARED,
   devmem_fd,
   phys_addr   /* Physical addres of packet buffer
from descriptor */
 );
I get by PROT_WRITE " segmentation fault"
What is the problem here ?
And question again:
How can I do it possible to remapp the kernel memory region to user space
process through /dev/mem and give to this user process write permissions to
remmaped space ?

Thanx
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


write protection by mmap of /dev/mem doesn't work

2009-03-10 Thread Alexej Sokolov
hello,
How can I mmap some memory regions with PROT_WRITE protection flag ?
What i do:
 /* Open mem device */
if ((devmem_fd = open("/dev/mem", O_RDWR)) == -1){
perror("/dev/mem");
exit (1);
}

then if I try to mmap some memory region with PROT_READ it goes Ok. But by
PROT_WRITE it doesn't work:
sp =mmap (  0,
   MCLBYTES,   /* Size of remapped buffer = size of
mbuf cluster */
   PROT_WRITE,
   MAP_SHARED,
   devmem_fd,
   phys_addr   /* Physical addres of packet buffer
from descriptor */
 );
I get by PROT_WRITE " segmentation fault"
What is the problem here ?
And question again:
How can I do it possible to remapp the kernel memory region to user space
process through /dev/mem and give to this user process write permissions to
remmaped space ?

Thanx
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


Re: wrong data in remapped buffer

2009-03-10 Thread Alexej Sokolov
2009/3/9 John Baldwin 

> On Monday 09 March 2009 3:38:55 pm Alexej Sokolov wrote:
> > 2009/3/9 John Baldwin 
> >
> > > On Friday 06 March 2009 11:13:38 am Alexej Sokolov wrote:
> > > > Hello,
> > > > I try to MALLOC a buffer in kern, then remap it with vm_map_find(),
> to
> > > space
> > > > of user process.
> > > > Some times the remapped buffer in user space contain incorrect data.
> > >
> > > What architecture are you using?  On some archs like amd64, small
> mallocs
> > > (<=
> > > PAGE_SIZE) don't use the kmem_map or kmem_object.
> > >
> > > --
> > > John Baldwin
> > >
> > anyway , the error happens only some times... I think there is other
> reason.
> > My hardware is amd64
> > % uname -ms
> > FreeBSD i386
>
> i386 always uses kmem for malloc(9).
>
> --
> John Baldwin

ok,
and what should be a reason of  inconsistent data after remapping ?
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


Re: wrong data in remapped buffer

2009-03-09 Thread Alexej Sokolov
2009/3/9 John Baldwin 

> On Friday 06 March 2009 11:13:38 am Alexej Sokolov wrote:
> > Hello,
> > I try to MALLOC a buffer in kern, then remap it with vm_map_find(), to
> space
> > of user process.
> > Some times the remapped buffer in user space contain incorrect data.
>
> What architecture are you using?  On some archs like amd64, small mallocs
> (<=
> PAGE_SIZE) don't use the kmem_map or kmem_object.
>
> --
> John Baldwin
>
anyway , the error happens only some times... I think there is other reason.
My hardware is amd64
% uname -ms
FreeBSD i386
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


Re: uma_zone

2009-03-08 Thread Alexej Sokolov
2009/3/7 Robert Watson 

> On Wed, 4 Mar 2009, Alexej Sokolov wrote:
>
>  how can I get the size and pointer of some allocated uma zone ? For
>> example: zone_pack
>>
>
> Could you tell us a bit more about the context in which you want to do
> this?

Interrupt kontext.


> Normally kernel modules acquire pointers to globally visible zones via a
> symbol dependency resolved by the kernel linker (zone_pack is a globally
> visible symbol in the kernel).


But what about the size ? Do the UMA zones have fixed sizes? What I want to
do is to remap zone_pack into the user space in order to give user
applications access to mbuf clusters with frames.


> Our general userspace monitoring tools, such as vmstat -z, don't display
> the UMA zone pointers, and a pointer to the zone is not exported by the
> sysctls it depends on, currently, but if you run kgdb on kernel.symbols you
> should be able to print out the address of the global zone_pack directly.
>
> Robert N M Watson
> Computer Laboratory
> University of Cambridge


Thanx a lot!
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


wrong data in remapped buffer

2009-03-06 Thread Alexej Sokolov
Hello,
I try to MALLOC a buffer in kern, then remap it with vm_map_find(), to space
of user process.
Some times the remapped buffer in user space contain incorrect data.

What could be a reason of this problem and how to solve it ?
Thanx,
Alexej


P.S. Whole code of remapping function:  http://pastebin.com/m78da0b37
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


uma_zone

2009-03-04 Thread Alexej Sokolov
how can I get the size and pointer of some allocated uma zone ?
For example:  zone_pack

Thanx
Alexej
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


bus_setup_intr (9)

2009-02-12 Thread Alexej Sokolov
hello,

from man:
int
 bus_setup_intr(device_t dev, struct resource *r, int flags,
 driver_filter_t filter, driver_intr_t ithread, void *arg,
 void **cookiep);

The function filter returns value of type driver_filter_t (int).  This
function will run if interrupt happen.

Question: Which function will get this returned "int value" of filter
function. Or How/where can I catch it ?

Alexej
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


Re: strange output in /var/log/messages

2009-02-12 Thread Alexej Sokolov
2009/2/12 Stefan Lambrev 

> Hi,
> On Feb 12, 2009, at 6:57 PM, Alexej Sokolov wrote:
>
> Hello,
> I try now to debug a kernel module and I make some output with printf(9).
> But the text appears in /var/log/messages in very strange form:
>
> Feb 12 17:54:34 myhost kernel: b
> Feb 12 17:54:34 myhost kernel: eg
> Feb 12 17:54:34 myhost kernel: in
> Feb 12 17:54:34 myhost kernel: .
> Feb 12 17:54:34 myhost kernel: De
> Feb 12 17:54:34 myhost kernel: vice
> Feb 12 17:54:34 myhost kernel: U
> Feb 12 17:54:34 myhost kernel: ni
> Feb 12 17:54:34 myhost kernel: t:
>
> Could anyone explain the reason of this kind of output. And how can I
> correct it?
>
>
> But those kernel messages are displayed properly if you type dmesg?
> If yes I think you can blame syslogd.
>

Yes , dmesg makes correct output :(


>
>
>
> Alexej
> ___
> freebsd-hackers@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"
>
>
> --
> Best Wishes,
> Stefan Lambrev
> ICQ# 24134177
>
>
>
>
>
>
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


strange output in /var/log/messages

2009-02-12 Thread Alexej Sokolov
Hello,
I try now to debug a kernel module and I make some output with printf(9).
But the text appears in /var/log/messages in very strange form:

Feb 12 17:54:34 myhost kernel: b
Feb 12 17:54:34 myhost kernel: eg
Feb 12 17:54:34 myhost kernel: in
Feb 12 17:54:34 myhost kernel: .
Feb 12 17:54:34 myhost kernel: De
Feb 12 17:54:34 myhost kernel: vice
Feb 12 17:54:34 myhost kernel: U
Feb 12 17:54:34 myhost kernel: ni
Feb 12 17:54:34 myhost kernel: t:

Could anyone explain the reason of this kind of output. And how can I
correct it?

Alexej
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


taskqueue (9)

2009-02-10 Thread Alexej Sokolov
Hello,
the structure task(9) contain field ta_priority. Which role plays this
priority if the task will wake up for run.
Or it is used only for order of  task in waitqueue while pending ?

Thanks
Alexej
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


Re: bus_dma (9). What exactly means "Loading of memory allocation" ?

2009-02-02 Thread Alexej Sokolov
Hi,
thanx for your answer.  I checked the source code of the *dma() functions.
If I understand it correctly, "loading of memory allocation" means the
following:

1. At first memory allocation should be done: bufp = *alloc(sizeof )
2. then in ... _bus_dmamap_load_buffer() we get physical addres of allocated
buffer:
 if (pmap)
 curaddr = pmap_extract(pmap, vaddr);
 else
 curaddr = pmap_kextract(vaddr);

... then some "magic" with bouncing

3. then physical address will passed to dmat->segments
segs[seg].ds_addr = curaddr;
segs[seg].ds_len = sgsize;

Ok, it all means: getting of physical address of allocated buffer. If
physical space not accessble for device, allocating bounce buffers. Getting
of physical addresses of allocated buffers. And then put these physical
addresses and sizes of buffers in  dmat->segments array. <- loading of
memory allocation (-:

right ?

Thanx,
Alexej



2009/2/2 Garrett Cooper 

> On Mon, Feb 2, 2009 at 12:45 AM, Garrett Cooper 
> wrote:
> > On Sun, Feb 1, 2009 at 5:56 PM, Sergey Babkin 
> wrote:
> >>
> >>   If I remember correctly, loading means that the pages become mapped
> >>   and visible to the devices. Some buses can access only a limited
> >>   address space , like ISA has only a 24-bit address. When a map gets
> >>   loaded, for any pages outside of this range the temporary in-ramge
> >>   pages are allocated and the d ata gets moved through them. On some
> >>   machines, like I think DEC Alpha, the  physicall addresses seen by
> >>   the devices are not the same as seen by the CPU , these need to be
> >>   translated. And so on.
> >>   I think my real old articl e had some of these explanations but now
> >>   the Daemonnews site seems to be re al slow:
> >>   http://ezine.daemonnews.org/28/isa.html
> >>   -SB
> >>   (sorry a bout top quoting, it's the only kind the web interface of my
> >>   provider suppo rts)
> >>   Feb 1, 2009 03:38:27 PM, [1]bsd.qu...@googlemail.com  wrote:
> >>
> >>  Hi,
> >> at first the cut of text from man (9) bus_dma:
> >> bus_dmamap_t
> >>  A machine-dependent opaque type describing an individual
> >> mapp ing.
> >> One map is used for each memory allocation that will b e loaded.
> >> Maps can be reused once they have been unloaded.. .
> >> Question: What exactly means "Loading of memory allocation" in thi
>   s context
> >> ?
> >> Could anyone explain it or give me some little example wi th DMA
> >> functions
> >> for understanding it.
> >
> > Unfortunately it's bad English, so that might be where some of the
> > confusion is stemming from. I'll send a doc's PR request after this to
> > fix it.
> > -Garrett
>
> Ugh. Nevermind. The question was written improperly -- the manpage wasn't
> ><.
> -Garrett
>
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


bus_dma (9). What exactly means "Loading of memory allocation" ?

2009-02-01 Thread Alexej Sokolov
Hi,
at first the cut of text from man (9) bus_dma:
bus_dmamap_t
 A machine-dependent opaque type describing an individual
mapping.
 One map is used for each memory allocation that will be loaded.
 Maps can be reused once they have been unloaded...

Question: What exactly means "Loading of memory allocation" in this context
?
Could anyone explain it or give me some little example with DMA functions
for understanding it.

Thanks a lot,
Alexej
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


Re: KLD: program.ko: depends of kernel - no avaiable

2009-01-28 Thread Alexej Sokolov
Can you  paste please the dmesg after KLDloading ? Sometimes there are
in /var/log/messages more helpful information. And I would like to look
your  syscall code if it possible. 

Alexej

On Tue, Jan 20, 2009 at 05:21:02PM +0100, Jacky Oh wrote:
> Hi,
> 
> I'm writing a syscall module and he compiles well but at load time, kldload
> shows:
> 
> KLD: program.ko: depends of kernel - no avaiable
> 
> anyone know something about this?
> 
> Thanks!
> ___
> freebsd-hackers@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"

-- 
Alexej Sokolov 
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


Re: How to access kernel memory from user space

2009-01-16 Thread Alexej Sokolov
On Thu, Jan 15, 2009 at 01:22:18PM -0600, Gerry Weaver wrote:
> _  
> 
> From: Alexej Sokolov [mailto:bsd.qu...@googlemail.com]
> To: Gerry Weaver [mailto:ger...@compvia.com]
> Cc: freebsd-hackers@freebsd.org
> Sent: Thu, 15 Jan 2009 12:31:00 -0600
> Subject: Re: How to access kernel memory from user space
> 
> 
> 
> 
> 2008/12/23 Gerry Weaver 
>   Hello All,
>   
>   I am working on a driver that collects various network statistics via pfil. 
> I have a simple array of structures that I use to store the statistics. I 
> also have a user space process that needs to collect these statistics every 
> second or so. A copy operation from kernel to user space would be too 
> expensive. Is there a mechanism that would allow me to gain direct access to 
> my kernel array from user space? The user process would only need read 
> access. It seems like maybe this could be done with mmap, but since this is 
> not a character driver, there is no device file etc.. I'm a newbie, so I 
> apologize if this is something that should be obvious.
> 
>   
>   Thanks in advance,
>   Gerry
>   ___
>   freebsd-hackers@freebsd.org mailing list
>   http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
>   To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"
>   Hi, 
> some times ago I solve this task. That's my solution in a system call 
> (whithout cdev). 
> Thanx in advance for founded mistakes and possible bugs (-:
> 
> 
> #include 
>   #include 
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
>   #include 
>  
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
>
>  
> /* Arguments for syscall */
> struct args {
>  
> /* Pointer to allocated Buffer */
> unsigned int  *p;
> }; 
>  
> /* String to be located in maped buffer */
> const char *str = "BSD IS SEXY";
>
> /* Syscall func */
> static int 
> syscf(struct thread *td, void *sa)
> {
> int error;
> struct args *uap;   
> vm_offset_t addr;  /* Kernel space address */
> vm_offset_t user_addr;  /* User space address  */
>
> struct proc *procp = (struct proc *)td->td_proc;
>  
> struct vmspace *vms = procp->p_vmspace; 
>  
> uap = (struct args *)sa;  
> 
> PROC_LOCK(procp);
> user_addr = round_page((vm_offset_t)vms->vm_daddr + 
>   lim_max(procp, RLIMIT_DATA));
> PROC_UNLOCK(procp);
>  
> MALLOC(addr, vm_offset_t, PAGE_SIZE, M_DEVBUF, M_WAITOK | M_ZERO);
>  
> vm_map_entry_t  myentry;
> vm_object_t myobject;
>   vm_pindex_t mypindex;
> vm_prot_t   myprot;
> boolean_t   mywired;
> vm_ooffset_tobjoffset;
> 
> vm_map_lookup(&kmem_map, addr, VM_PROT_ALL,
> &myentry, &myobject, &mypindex, &myprot, &mywired); 
> /* OUT */
>   vm_map_lookup_done(kmem_map, myentry);
>  
> printf("---> Syscall: hint for allocating space = 0x%X\n", addr);
>   
> if (myobject == kmem_object){
> printf("---> Syscall: Yes, it is kmem_obj! \n");
>   }
>  
> /* Offset in vm_object */   
> objoffset = addr - myentry->start + myentry->offset;
>  
> printf("--> Syscall: Object offset = 0x%X \n", (unsigned 
> int)objoffset);
>
> /*
>  * Try to map kernel buffer to user space  
>  */
> vm_object_reference(myobject); /* NEEDED Increment vm_obj references 
> */
> error = vm_map_find(&vms->vm_map, myobject, objoffset, (vm_offset_t 
> *)&user_addr, 
>   PAGE_SIZE, TRUE, VM_PROT_RW, VM_PROT_RW, 
> MAP_ENTRY_NOFAULT);
>  
> if (error == KERN_SUCCESS) {
> /* copy string using kernel address */
> size_t len;
>   copystr(str, (void *)addr, 12, &len); 
>  
> /* 
>  * Tell to user process it's  user space address 
>  */
> *uap->p = user_addr;
>
> /* 
>  * Try to read the string using user space address
>  */ 
> printf("String: %s\n", (char *)*uap->p); 
>  
> printf("---> Syscall: user_addr for allocating space = 
> 0x%X\n"

Re: How to access kernel memory from user space

2009-01-15 Thread Alexej Sokolov
2008/12/23 Gerry Weaver 

> Hello All,
>
> I am working on a driver that collects various network statistics via pfil.
> I have a simple array of structures that I use to store the statistics. I
> also have a user space process that needs to collect these statistics every
> second or so. A copy operation from kernel to user space would be too
> expensive. Is there a mechanism that would allow me to gain direct access to
> my kernel array from user space? The user process would only need read
> access. It seems like maybe this could be done with mmap, but since this is
> not a character driver, there is no device file etc.. I'm a newbie, so I
> apologize if this is something that should be obvious.
>
>
> Thanks in advance,
> Gerry
> ___
> freebsd-hackers@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"
>
Hi,
some times ago I solve this task. That's my solution in a system call
(whithout cdev).
Thanx in advance for founded mistakes and possible bugs (-:


#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#include 
#include 
#include 
#include 
#include 
#include 


/* Arguments for syscall */
struct args {

/* Pointer to allocated Buffer */
unsigned int  *p;
};

/* String to be located in maped buffer */
const char *str = "BSD IS SEXY";

/* Syscall func */
static int
syscf(struct thread *td, void *sa)
{
int error;
struct args *uap;
vm_offset_t addr;  /* Kernel space address */
vm_offset_t user_addr;  /* User space address  */

struct proc *procp = (struct proc *)td->td_proc;

struct vmspace *vms = procp->p_vmspace;

uap = (struct args *)sa;

PROC_LOCK(procp);
user_addr = round_page((vm_offset_t)vms->vm_daddr +
lim_max(procp, RLIMIT_DATA));
PROC_UNLOCK(procp);

MALLOC(addr, vm_offset_t, PAGE_SIZE, M_DEVBUF, M_WAITOK | M_ZERO);

vm_map_entry_t  myentry;
vm_object_t myobject;
vm_pindex_t mypindex;
vm_prot_t   myprot;
boolean_t   mywired;
vm_ooffset_tobjoffset;

vm_map_lookup(&kmem_map, addr, VM_PROT_ALL,
&myentry, &myobject, &mypindex, &myprot, &mywired);
/* OUT */
vm_map_lookup_done(kmem_map, myentry);

printf("---> Syscall: hint for allocating space = 0x%X\n", addr);

if (myobject == kmem_object){
printf("---> Syscall: Yes, it is kmem_obj! \n");
}

/* Offset in vm_object */
objoffset = addr - myentry->start + myentry->offset;

printf("--> Syscall: Object offset = 0x%X \n", (unsigned
int)objoffset);

/*
 * Try to map kernel buffer to user space
 */
vm_object_reference(myobject); /* NEEDED Increment vm_obj references
*/
error = vm_map_find(&vms->vm_map, myobject, objoffset, (vm_offset_t
*)&user_addr,
PAGE_SIZE, TRUE, VM_PROT_RW, VM_PROT_RW,
MAP_ENTRY_NOFAULT);

if (error == KERN_SUCCESS) {
/* copy string using kernel address */
size_t len;
copystr(str, (void *)addr, 12, &len);

/*
 * Tell to user process it's  user space address
 */
*uap->p = user_addr;

/*
 * Try to read the string using user space address
 */
printf("String: %s\n", (char *)*uap->p);

printf("---> Syscall: user_addr for allocating space =
0x%X\n", user_addr);
}

return (0);
}

/* Sysent entity for syscall */
static struct sysent sc_sysent = {
1,  /* Number of
arguments */
syscf   /* Syscall function*/
};

/* Offset in sysent[] */
static int offset = NO_SYSCALL;

/* Loader */
static int
load (struct module *m, int cmd, void *something)
{
int error = 0;
switch(cmd){
case MOD_LOAD:
printf("Module with sysc loaded. Offset = %d \n",
offset);
break;

case MOD_UNLOAD:
printf("Module with sysc unloaded. Offset = %d \n",
offset);
break;

default:
error = EOPNOTSUPP;
break;
}
return (error);
}

/* Syscall macro*/
SYSCALL_MODULE(fiveg_sysc, &offset, &sc_sysent, load, NULL);

If needed, I can post user space program.
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


Re: panic by unlocking of mutex in KLD

2009-01-12 Thread Alexej Sokolov
2009/1/12 Mateusz Guzik 

> On Mon, Jan 12, 2009 at 07:16:51PM +0100, Alexej Sokolov wrote:
> > 2009/1/12 Mateusz Guzik 
> >
> > > On Mon, Jan 12, 2009 at 05:19:56PM +0100, Alexej Sokolov wrote:
> > > > 2009/1/12 Mateusz Guzik 
> > > > > Mutexes have owners. It panics on loading because processes cannot
> > > > > return to userland with locks held.
> > > >
> > > > i am not sure about it. Some time ago i implemented a charecter
> device
> > > with
> > > > two syscalls: write, read. "write" lock the mutex and  "read" unlock
> it.
> > > The
> > > > user space programm opens device, then mekes "write" (mutex will held
> in
> > > > kernel), goes back to user space, then makes "read" (mutex will
> unlocked
> > > in
> > > > kernel) and it all run without panic. If needed i can post the source
> > > code.
> > > >
> > >
> > > Do you have kernel compiled with WITNESS? At least on -CURRENT the
> > > kernel panicked like this (while loading your module):
> > >
> > > System call kldload returning with 1 locks held
> >
> > My kernel is compiled without WITNESS. And it allows to lock mutex in one
> > systcall (for example "write") and to unlock it in other ("read").
> > Do you mean it is "very bad idea" to do something like this ?
> > I could not find anywhere in the documentation that a it is not allowed
> to
> > return in the user space with a locked mutex.
> > Can you give me some reference on man page, source code or something
> other
> > from where can I understand it ?
> >
>
> Locks are used to synchronize access to data changeable by other
> threads. I don't know if I'm correct here, but let's consider the
> following situation: your process grabs a mutex and returns to userland,
> then it's killed due to segmentation violation. This mutex should (and
> can be) unlocked on exit, but the state of data protected by it is
> unknown. (For example your process was killed while inserting something
> into linked list.) So even if the kernel could be guided to unlock it on
> exit, the data could be in inconsistent state.
>
> Also your locking scheme doesn't make much sense. Consider this:
>proc1 calls write on your cdev
> but in the meantime
>proc2 calls read on your cdev
>
> So you get panic because proc1 was writing some data. (attempt to unlock
> mutex locked by proc1) Even if the kernel wouldn't panic, proc2 would
> read inconsistend data because proc1 was writing. Proper solution is to
> lock mutex before and after reading/writing data. For working example
> you can check how devctl was implemented (sys/kern/subr_bus.c).
>
> --
> Mateusz Guzik 
>

Ok , now I understaand it.
If a thread return to user space with locked mutex, kernel doesen't know if
the thread will come back to unlock it. It is really unsafe return to
userspace without unlocking of helding mutexes.

Thanks a lot for your help.
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


Re: panic by unlocking of mutex in KLD

2009-01-12 Thread Alexej Sokolov
2009/1/12 Mateusz Guzik 

> On Mon, Jan 12, 2009 at 07:16:51PM +0100, Alexej Sokolov wrote:
> > 2009/1/12 Mateusz Guzik 
> >
> > > On Mon, Jan 12, 2009 at 05:19:56PM +0100, Alexej Sokolov wrote:
> > > > 2009/1/12 Mateusz Guzik 
> > > > > Mutexes have owners. It panics on loading because processes cannot
> > > > > return to userland with locks held.
> > > >
> > > > i am not sure about it. Some time ago i implemented a charecter
> device
> > > with
> > > > two syscalls: write, read. "write" lock the mutex and  "read" unlock
> it.
> > > The
> > > > user space programm opens device, then mekes "write" (mutex will held
> in
> > > > kernel), goes back to user space, then makes "read" (mutex will
> unlocked
> > > in
> > > > kernel) and it all run without panic. If needed i can post the source
> > > code.
> > > >
> > >
> > > Do you have kernel compiled with WITNESS? At least on -CURRENT the
> > > kernel panicked like this (while loading your module):
> > >
> > > System call kldload returning with 1 locks held
> >
> > My kernel is compiled without WITNESS. And it allows to lock mutex in one
> > systcall (for example "write") and to unlock it in other ("read").
> > Do you mean it is "very bad idea" to do something like this ?
> > I could not find anywhere in the documentation that a it is not allowed
> to
> > return in the user space with a locked mutex.
> > Can you give me some reference on man page, source code or something
> other
> > from where can I understand it ?
> >
>
> Locks are used to synchronize access to data changeable by other
> threads. I don't know if I'm correct here, but let's consider the
> following situation: your process grabs a mutex and returns to userland,
> then it's killed due to segmentation violation. This mutex should (and
> can be) unlocked on exit, but the state of data protected by it is
> unknown. (For example your process was killed while inserting something
> into linked list.) So even if the kernel could be guided to unlock it on
> exit, the data could be in inconsistent state.
>
> Also your locking scheme doesn't make much sense. Consider this:
>proc1 calls write on your cdev
> but in the meantime
>proc2 calls read on your cdev
>
> So you get panic because proc1 was writing some data. (attempt to unlock
> mutex locked by proc1) Even if the kernel wouldn't panic, proc2 would
> read inconsistend data because proc1 was writing. Proper solution is to
> lock mutex before and after reading/writing data. For working example
> you can check how devctl was implemented (sys/kern/subr_bus.c).
>
> --
> Mateusz Guzik 
>

Ok , now I understaand it.
If a thread return to user space with locked mutex, kernel doesen't know if
the thread will come back to unlock it. It is really unsafe return to
userspace without unlocking of helding mutexes.

Thanks a lot for your help.
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


Re: panic by unlocking of mutex in KLD

2009-01-12 Thread Alexej Sokolov
2009/1/12 Mateusz Guzik 

> On Mon, Jan 12, 2009 at 05:19:56PM +0100, Alexej Sokolov wrote:
> > 2009/1/12 Mateusz Guzik 
> > > Mutexes have owners. It panics on loading because processes cannot
> > > return to userland with locks held.
> >
> > i am not sure about it. Some time ago i implemented a charecter device
> with
> > two syscalls: write, read. "write" lock the mutex and  "read" unlock it.
> The
> > user space programm opens device, then mekes "write" (mutex will held in
> > kernel), goes back to user space, then makes "read" (mutex will unlocked
> in
> > kernel) and it all run without panic. If needed i can post the source
> code.
> >
>
> Do you have kernel compiled with WITNESS? At least on -CURRENT the
> kernel panicked like this (while loading your module):
>
> System call kldload returning with 1 locks held

My kernel is compiled without WITNESS. And it allows to lock mutex in one
systcall (for example "write") and to unlock it in other ("read").
Do you mean it is "very bad idea" to do something like this ?
I could not find anywhere in the documentation that a it is not allowed to
return in the user space with a locked mutex.
Can you give me some reference on man page, source code or something other
from where can I understand it ?

Thanx a lot,
Alexej



>
>
> --
> Mateusz Guzik 
> ___
> freebsd-hackers@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"
>
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


Re: panic by unlocking of mutex in KLD

2009-01-12 Thread Alexej Sokolov
2009/1/12 Mateusz Guzik 

> On Mon, Jan 12, 2009 at 02:47:26PM +0100, Alexej Sokolov wrote:
> > Hello,
> >
> > by unloading of folowing module  I have kernel panic.
> >
> > I would like to get any explanation about my mistake.
> >
> > #include 
> > #include 
> > #include 
> > #include 
> > #include 
> > #include 
> > #include 
> > #include 
> > #include 
> > #include 
> > #include 
> >
> >
> > struct mtx my_mtx;
> >
> >
> > /* Load handler */
> > static int
> > load(struct module *mod, int cmd, void *arg)
> > {
> > int error = 0;
> > switch(cmd) {
> > case MOD_LOAD:
> > printf("Start! Addres of mutex = 0x%X \n",
> > &my_mtx);
> > mtx_init(&my_mtx, "My mutex name", "My mutex
> > type", MTX_DEF);
> >
> > mtx_lock(&my_mtx);
> > break;
> > case MOD_UNLOAD:
> > printf("Stop! Addres of mutex = 0x%X \n",
> > &my_mtx);
> > mtx_unlock(&my_mtx);
> > break;
> > default:
> > error = EOPNOTSUPP;
> > break;
> > }
> >
> > return (error);
> > }
> >
> > /* Module structure */
> > static moduledata_t mod_data = {
> > "mymod",
> > load,
> > NULL
> > };
> > MODULE_VERSION (kld, 1);
> > DECLARE_MODULE (kld, mod_data, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
> >
> >
>
> Acutally it panics even on loading. :)

Thanks, a lot. Yes, in this case the different processes try to lock and
unlock the same mutex. Stupid mistake!

But...

>
>
> Mutexes have owners. It panics on loading because processes cannot
> return to userland with locks held.

i am not sure about it. Some time ago i implemented a charecter device with
two syscalls: write, read. "write" lock the mutex and  "read" unlock it. The
user space programm opens device, then mekes "write" (mutex will held in
kernel), goes back to user space, then makes "read" (mutex will unlocked in
kernel) and it all run without panic. If needed i can post the source code.



> It panics on unloading (in your
> case) because curproc != my_mtx's owner.
>
> --
> Mateusz Guzik 
>

Thanks,
Alexej
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


panic by unlocking of mutex in KLD

2009-01-12 Thread Alexej Sokolov
Hello, 

by unloading of folowing module  I have kernel panic.

I would like to get any explanation about my mistake.

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 


struct mtx my_mtx; 


/* Load handler */
static int
load(struct module *mod, int cmd, void *arg)
{
int error = 0; 
switch(cmd) {
case MOD_LOAD:
printf("Start! Addres of mutex = 0x%X \n",
&my_mtx);
mtx_init(&my_mtx, "My mutex name", "My mutex
type", MTX_DEF);

mtx_lock(&my_mtx);
break;
case MOD_UNLOAD:
printf("Stop! Addres of mutex = 0x%X \n",
&my_mtx);
mtx_unlock(&my_mtx);
break;
default:
error = EOPNOTSUPP;
break;
}

return (error);
}

/* Module structure */
static moduledata_t mod_data = {
"mymod",
load,
NULL
};
MODULE_VERSION (kld, 1);
DECLARE_MODULE (kld, mod_data, SI_SUB_DRIVERS, SI_ORDER_MIDDLE); 


Thanx

-- 
Alexej Sokolov 
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


vm_map (9) + MAP_PREFAULT and MAP_PREFAULT_PARTIAL

2008-12-09 Thread Alexej Sokolov
Hello, 
could anyone explain what exactly do the cow-flags MAP_PREFAULT_PARTIAL,
MAP_PREFAULT. I couldn't understand it from man pages and from source
code. 
It's mean that the pages will be wired ? 

Thanks, 

-- 
Alexej Sokolov <[EMAIL PROTECTED]>
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: kernel vm_submap's

2008-12-04 Thread Alexej Sokolov
2008/12/4 pluknet <[EMAIL PROTECTED]>

> 2008/12/4 Alexej Sokolov <[EMAIL PROTECTED]>:
>  > Hello,
> > Where/How can I get information about vm_submap's in the actual stable
> > kernel:
> > % uname -v
> > FreeBSD 7.0-RELEASE-p5 #0: Tue Oct  7 19:05:20 CEST 2008
> > And what kind of data is present in these submaps (mallocs, mbufs,
> > DMA-buffer..)?
> >
>
> vm_map_submap(9) might help you.
> btw, it's called only from one place I can find: kmem_suballoc.

Ok, then the next question: If I have some kernel virtual addres, what is
the best way to find out which submap it belongs to?


>
>
> > Thanks,
>
> --
> wbr,
> pluknet
>
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


kernel vm_submap's

2008-12-04 Thread Alexej Sokolov
Hello,
Where/How can I get information about vm_submap's in the actual stable
kernel:
% uname -v
FreeBSD 7.0-RELEASE-p5 #0: Tue Oct  7 19:05:20 CEST 2008
And what kind of data is present in these submaps (mallocs, mbufs,
DMA-buffer..)?

Thanks,
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: vm_map_entry for kernel virtual addres

2008-12-04 Thread Alexej Sokolov
2008/12/3 Mark Tinguely <[EMAIL PROTECTED]>

> >  2008/12/3 Mark Tinguely <[EMAIL PROTECTED]>
> >
> >  > on 3 Dec 2008 15:35:27, Alexej Sokolov <[EMAIL PROTECTED]>
> asked:
> >  >
> >  > >  Hello,
> >  > >  If I allocate memory from a kernel module:
> >  > >  MALLOC(addr, vm_offset_t, PAGE_SIZE, M_DEVBUF, M_WAITOK | M_ZERO);
> >  > >
> >  > >  how can I get a pointer to vm_map_entry structure which describes
> the
> >  > memory
> >  > >  region where "addr" is ?
> >  > >
> >  > >  Thanks,
> >  > >  Alexey
> >  >
> >  > MALLOC is a macro for malloc() which returns a kernel virtual address
> into
> >  > the variable addr in this case.
> >  >
> >  > You want to find the vm_map_entry, use something like:
> >  >
> >  >vm_map_entry_t *result;
> >  >if (vm_map_lookup_entry(kernel_map, addr, result)) {
> >  >/* found */
> >  >} else {
> >  >/* not found */
> >  >}
> >
> >
> >  1. Should i use any locks or mutex for doing it ?
>
>  Good question, it really should be:
>
>vm_map_lock(map);
>
> >  2. What map is used by MALLOC? It can be a some submap. Should i use
> then a
> >  submap for searching entry?
>
> I thought originally that malloc() allocated memory from kernel map
> (kernel_map), but on closer inspection, malloc() seems to use the
> default UMA zone allocator [page_alloc()] which takes the memory from
> the kmem_map. Which I should have know, big mallocs fill the kmem space.
> sooo I guess the more correct code would be:
>
>vm_map_entry_t result;
>vm_map_lock(kmem_map);
>if (vm_map_lookup_entry(kmem_map, addr, &result)) {
>/* found */
>} else {
>/* not found */
>}
>vm_map_unlock(kmem_map);
>
> Ok, thanks a lot!
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


vm_map_entry for kernel virtual addres

2008-12-03 Thread Alexej Sokolov
Hello,
If I allocate memory from a kernel module:
MALLOC(addr, vm_offset_t, PAGE_SIZE, M_DEVBUF, M_WAITOK | M_ZERO);

how can I get a pointer to vm_map_entry structure which describes the memory
region where "addr" is ?

Thanks,
Alexey
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


getting vm_object from allocated memory in kernel

2008-12-01 Thread Alexej Sokolov
Hello,
I try to allocate a memory in the system call and then I would like to get
vm_object
of allocated space to remap it later:

/* Syscall func */
static int
syscf(struct thread *td, void *sa)
{
...
vm_offset_t addr;
...
MALLOC(addr, vm_offset_t, PAGE_SIZE, M_DEVBUF, M_WAITOK | M_ZERO);

/* Then I try to get vm_obj */
vm_map_lookup(&kernel_map, addr, VM_PROT_ALL,
&myentry, &myobject, &mypindex, &myprot, &mywired);
/* OUT */
vm_map_lookup_done(&kernel_map, myentry);

/* If i try to make system call it work successful but after a few seconds
happens
kernel panic */

...
}

could anyone give me a tip what I do wrong ?

# kgdb kernel.debug
vmcore.10
/home/alexandre/alexandre-da/misc/crash
kgdb: kvm_nlist(_stopped_cpus):
kgdb: kvm_nlist(_stoppcbs):
[GDB will not be able to debug user-mode threads: /usr/lib/libthread_db.so:
Undefined symbol "ps_pglobal_lookup"]
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-marcel-freebsd".

Unread portion of the kernel message buffer:
kernel trap 12 with interrupts disabled


Fatal trap 12: page fault while in kernel mode
fault virtual address   = 0x14
fault code  = supervisor read, page not present
instruction pointer = 0x20:0xc0589028
stack pointer   = 0x28:0xe7a83758
frame pointer   = 0x28:0xe7a83774
code segment= base 0x0, limit 0xf, type 0x1b
= DPL 0, pres 1, def32 1, gran 1
processor eflags= resume, IOPL = 0
current process = 792 (zsh)
panic: from debugger
Uptime: 20m59s
Physical memory: 2034 MB
Dumping 73 MB: 58 42 26 10

#0  doadump () at pcpu.h:195
195 pcpu.h: No such file or directory.
in pcpu.h
(kgdb)) bt
#0  doadump () at pcpu.h:195
#1  0xc0558c03 in boot (howto=260) at /usr/src/sys/kern/kern_shutdown.c:409
#2  0xc0558e2c in panic (fmt=Variable "fmt" is not available.
) at /usr/src/sys/kern/kern_shutdown.c:563
#3  0xc0457927 in db_panic (addr=Could not find the frame base for
"db_panic".
) at /usr/src/sys/ddb/db_command.c:433
#4  0xc0458085 in db_command_loop () at /usr/src/sys/ddb/db_command.c:401
#5  0xc0459ab5 in db_trap (type=12, code=0) at
/usr/src/sys/ddb/db_main.c:222
#6  0xc057ed84 in kdb_trap (type=12, code=0, tf=0xe7a83718) at
/usr/src/sys/kern/subr_kdb.c:502
#7  0xc06b3edf in trap_fatal (frame=0xe7a83718, eva=20) at
/usr/src/sys/i386/i386/trap.c:890
#8  0xc06b489a in trap (frame=0xe7a83718) at
/usr/src/sys/i386/i386/trap.c:280
#9  0xc069dacb in calltrap () at /usr/src/sys/i386/i386/exception.s:139
#10 0xc0589028 in propagate_priority (td=0xc5963210) at
/usr/src/sys/kern/subr_turnstile.c:272
#11 0xc05899a9 in turnstile_wait (ts=0xc5083870, owner=0xc5963210,
queue=Variable "queue" is not available.
) at /usr/src/sys/kern/subr_turnstile.c:739
#12 0xc054cdbd in _mtx_lock_sleep (m=0xc14540e8, tid=3312898576, opts=0,
file=0x0, line=0) at /usr/src/sys/kern/kern_mutex.c:416
#13 0xc054d141 in _mtx_lock_flags (m=0xc14540e8, opts=0, file=0x0, line=0)
at /usr/src/sys/kern/kern_mutex.c:186
#14 0xc066c234 in _vm_map_lock (map=0xc145408c, file=0x0, line=0) at
/usr/src/sys/vm/vm_map.c:449
#15 0xc0669e4a in kmem_malloc (map=0xc145408c, size=4096, flags=259) at
/usr/src/sys/vm/vm_kern.c:296
#16 0xc0660a77 in page_alloc (zone=0xc1445780, bytes=4096, pflag=0xe7a8388f
"\002\200\207D�\003", wait=259) at /usr/src/sys/vm/uma_core.c:955
#17 0xc065fb3c in slab_zalloc (zone=0xc1445780, wait=259) at
/usr/src/sys/vm/uma_core.c:820
#18 0xc0660014 in uma_zone_slab (zone=0xc1445780, flags=3) at
/usr/src/sys/vm/uma_core.c:2010
#19 0xc0663286 in uma_zalloc_arg (zone=0xc1445780, udata=0x0, flags=3) at
/usr/src/sys/vm/uma_core.c:2111
#20 0xc05bf62f in cache_enter (dvp=0xc5724770, vp=0x0, cnp=0xe7a83bd0) at
uma.h:277
#21 0xc06521d8 in ufs_lookup (ap=0xe7a83a00) at
/usr/src/sys/ufs/ufs/ufs_lookup.c:446
#22 0xc06c9ee2 in VOP_CACHEDLOOKUP_APV (vop=0xc073a180, a=0xe7a83a00) at
vnode_if.c:153
#23 0xc05bffa0 in vfs_cache_lookup (ap=0xe7a83a84) at vnode_if.h:83
#24 0xc06cbb26 in VOP_LOOKUP_APV (vop=0xc073a6a0, a=0xe7a83a84) at
vnode_if.c:99
#25 0xc05c64c1 in lookup (ndp=0xe7a83ba8) at vnode_if.h:57
#26 0xc05c7118 in namei (ndp=0xe7a83ba8) at
/usr/src/sys/kern/vfs_lookup.c:219
#27 0xc05d4b5d in kern_stat (td=0xc576d210, path=0xbfbe5238 , pathseg=UIO_USERSPACE, sbp=0xe7a83c18)
at /usr/src/sys/kern/vfs_syscalls.c:2109
#28 0xc05d4d0f in stat (td=0xc576d210, uap=0xe7a83cfc) at
/usr/src/sys/kern/vfs_syscalls.c:2093
#29 0xc06b44b7 in syscall (frame=0xe7a83d38) at
/usr/src/sys/i386/i386/trap.c:1035
#30 0xc069db30 in Xint0x80_syscall () at
/usr/src/sys/i386/i386/exception.s:196
#31 0x0033 in ?? ()
Previous frame inn

Re: remapping kernel buffer in VMS of user process

2008-12-01 Thread Alexej Sokolov
On Mon, Dec 01, 2008 at 10:12:09AM -0500, Alexander Kabaev wrote:
> On Mon, 1 Dec 2008 02:38:51 +0100
> Alexej Sokolov <[EMAIL PROTECTED]> wrote:
> 
> > Hello, 
> > 
> > I would like to remap some buffers allocated in kernel space to memory
> > space of certain process. 
> > 
> The simplest way is to expose this buffer through device pager.
> Implement the driver callback and let userland to simply mmap the page.
> 
Sorry, but I don't understand how to do it. I know how to implement mmap
through character device. But I am working with network driver. Network
devices doesn't appear in file system and they don't have any interface
for mmaping. 

I think I can try to solve with task with: 
vm_map_lookup - to get a vm_object of allocated space and then 
vm_map_find (map_of_process, ... founded_object ...) - allocate a new
space in the vms of process. 

I try to do it now with a small hope of success :-)


> -- 
> Alexander Kabaev



-- 
Alexej Sokolov <[EMAIL PROTECTED]>
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


remapping kernel buffer in VMS of user process

2008-11-30 Thread Alexej Sokolov
Hello, 

I would like to remap some buffers allocated in kernel space to memory
space of certain process. 

For Example, in attach function of driver: 

static int
driver_attach {
...
struct vmspace *vms = some_thread->td_proc->p_vmspace;
bufp = malloc (PAGE_SIZE, M_DEVBUF, M_NOWAIT);

/*  How to create in vms of some_thread->td_proc remapping of 
buffer 
pointed  (in kernel) by bufp ? 
some_thread should access the buffer using its virtual user 
addresses  and driver should access the same data using its 
kernel 
virtual addresses (bufp) 
*/

...

}
-- 
Alexej Sokolov <[EMAIL PROTECTED]>
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: copy, copyin, copyout

2008-11-25 Thread Alexej Sokolov
On Tue, Nov 25, 2008 at 06:55:21PM +0100, Max Laier wrote:
> On Tuesday 25 November 2008 18:37:50 Alexej Sokolov wrote:
> > Hello,
> > could anyone please explain to me the difference between functions:
> > copystr() and copyinstr() ?
> >
> > For i386 copyinstr is implemented in assembler. I can not read
> > the assembler code very well.
> >
> > I tried to allocate a memory in space of user process using vm_map_find
> > and then with copystr() I could copy data between user and kernel
> > memory. copystr() seemed to be  able to do the same what copyinstr do.
> 
> You might get lucky with copystr() if the user page is already resident, but 
> if you page fault copystr() will kill the kernel.  copyinstr() handles page 
> faults.
Thanks a lot! I was lucky because I wired allocated pages before. 

 
> 
> -- 
> /"\  Best regards,  | [EMAIL PROTECTED]
> \ /  Max Laier  | ICQ #67774661
>  X   http://pf4freebsd.love2party.net/  | [EMAIL PROTECTED]
> / \  ASCII Ribbon Campaign  | Against HTML Mail and News

-- 
Alexej Sokolov <[EMAIL PROTECTED]>
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


copy, copyin, copyout

2008-11-25 Thread Alexej Sokolov
Hello, 
could anyone please explain to me the difference between functions: 
copystr() and copyinstr() ? 

For i386 copyinstr is implemented in assembler. I can not read
the assembler code very well. 

I tried to allocate a memory in space of user process using vm_map_find
and then with copystr() I could copy data between user and kernel
memory. copystr() seemed to be  able to do the same what copyinstr do. 

% uname -rp
7.0-RELEASE-p5 i386

-- 
Alexej Sokolov <[EMAIL PROTECTED]>
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: Ответ: KLD loading, liking

2008-11-18 Thread Alexej Sokolov
On Mon, Nov 17, 2008 at 09:43:44PM +0100, Ed Schouten wrote:
> * Aleksandr Litvinov <[EMAIL PROTECTED]> wrote:
> > Hello,
> > You  can receive a little information about KLD from the book
> > "designing BSD rootkits".
> 
> I don't own this book myself, but a colleague at Snow B.V. once showed
> it to me. I only looked through it a couple of minutes, but it seemed
> like a book nice to have. It also shows some techniques on how to hide
> KLD's.
I have this book. It shows some techniques, but it doesn't explain many
things. And for KLD loading it gives only easy examples without
explaining how KLD-Loader works. 
It's not absolutely necessary to bye this book. There are some papers,
which explain the topics of the book very well: 

1. Fun and Games with FreeBSD Kernel Modules
http://www.r4k.net/mod/fbsdfun.html

2. Attacking FreeBSD with Kernel Modules:
http://packetstormsecurity.org/papers/unix/bsdkern.htm


> 
> -- 
>  Ed Schouten <[EMAIL PROTECTED]>
>  WWW: http://80386.nl/



-- 
Alexej Sokolov <[EMAIL PROTECTED]>
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: KLD loading, liking

2008-11-17 Thread Alexej Sokolov
On Sun, Nov 16, 2008 at 11:09:00AM +0100, Ed Schouten wrote:
> * Alexej Sokolov <[EMAIL PROTECTED]> wrote:

> > What exact does the macro MODULE_DEPEND ? The man page is to short, and I
> > guess it tell no all things that the macro does.
> 
> MODULE_DEPEND is used to say: this kernel module also depends on another
> module (i.e. the USB printer module depends on the USB code). Tools like
> kldload can then automatically load the missing modules.
Not only that. The use of the MODULE_DEPEND macro allows one module to access 
the variables of modules on which it depends. But man page of
MODULE_DEPEND doesn't tell anything about this functionality. Hence I
am looking for any good documentation of KLD loader. But I didn't find
anything. May be looking in the source code is the best solution. 
 
> 
> -- 
>  Ed Schouten <[EMAIL PROTECTED]>
>  WWW: http://80386.nl/



-- 
Alexej Sokolov <[EMAIL PROTECTED]>
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: vm_map_find

2008-11-15 Thread Alexej Sokolov
On Sat, Nov 15, 2008 at 11:10:25PM -0500, Robert Noland wrote:
> On Sun, 2008-11-16 at 04:42 +0059, Alexej Sokolov wrote:
> > Hello,
> > my question is about vm_map_find (9)
> >  int
> >  vm_map_find(vm_map_t map, vm_object_t object, vm_ooffset_t offset,
> >  vm_offset_t *addr, vm_size_t length, boolean_t find_space,
> >  vm_prot_t prot, vm_prot_t max, int cow);
> > 
> > Could anyone explain what exactly parameter "cow" for ? Which values and
> > meanings ?
> 
> Well, cow is COPY_ON_WRITE.  See vm_map(9) for the list of flags.
> 
> robert.
Ok, 
thanx a lot, but I find it strange that the info about possible values
of "cow" isn't  present in man pages vm_map_insert and vm_map_find


Thnks again!

> 
> > man page dives not enough informations about it.
> > 
> > Thanks
> > ___
> > freebsd-hackers@freebsd.org mailing list
> > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> > To unsubscribe, send any mail to "[EMAIL PROTECTED]"

___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Make files for /usr/src/sys/dev/*

2008-11-15 Thread Alexej Sokolov
hello,
where are the Makefiles for drivers in /usr/src/dev/*

% uname -v
FreeBSD 7.0-RELEASE-p5

Thanks
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


vm_map_find

2008-11-15 Thread Alexej Sokolov
Hello,
my question is about vm_map_find (9)
 int
 vm_map_find(vm_map_t map, vm_object_t object, vm_ooffset_t offset,
 vm_offset_t *addr, vm_size_t length, boolean_t find_space,
 vm_prot_t prot, vm_prot_t max, int cow);

Could anyone explain what exactly parameter "cow" for ? Which values and
meanings ?
man page dives not enough informations about it.

Thanks
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


KLD loading, liking

2008-11-15 Thread Alexej Sokolov
Hello,
i am looking for some infos (may be papers) about how KLD linker works.
After kompiling the KLD contain two important sections:
% readelf -S mymod.ko | grep set
[ 7] set_sysinit_set   PROGBITS0560 000560 04 00   A  0   0
4
[ 8] set_modmetadata_s PROGBITS0564 000564 08 00   A  0   0
4
.

sysinit_set -contain a structure with a pointer to function which will be
called by loading of KLD

modmetadata_set - what kind of information is there and which functions of
linking/loading use it ?

What exact does the macro MODULE_DEPEND ? The man page is to short, and I
guess it tell no all things that the macro does.

Thanks
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"