RE: Copying from Virtual Address Space to Physical Address

2002-08-30 Thread Kip Macy

While we're on the topic of vmapbuf:
I have a kernel module that maps two 64k chunks of user memory into the kernel
using the same set of steps that cam_periph_mapmem uses. However, I inevitably
get the following panic after running the code for a bit:

Aug 30 14:55:26 testhost /kernel: panic: worklist_remove: not on list
Aug 30 14:55:26 testhost /kernel: 
Aug 30 14:55:26 testhost /kernel: syncing disks... 8 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
1 1 1 
Aug 30 14:55:26 testhost /kernel: giving up on 1 buffers

This is a panic in ffs_softdep.c, it implies to me that either the FFS code
isn't recognizing that not all buffers belong to it or getpbuf isn't doing all
the needed accounting. I notice that I am calling getpbuf(NULL), just as
cam_periph_mapmem does. But above its definition in the comment is:

 *  NOTE: pfreecnt can be NULL, but this 'feature' will be removed
 *  relatively soon when the rest of the subsystems get smart about it. XXX


Also worthy of note is that my kernel module has a lot of printfs which
obviously translate to a lot of synchronous writes by syslog, presumably putting
memory pressure on the file system.

When guessing whether Kirk is at fault or I am fault, it is usually a safe bet
that I am at fault ;-). Any insights?

-Kip


On Fri, 30 Aug 2002, Julian Elischer wrote:

> 
> 
> On Fri, 30 Aug 2002, Balaji, Pavan wrote:
> 
> > 
> > Thanx. It's nearly done. I just need to know two more small things.
> > 
> > physio() requires a dev_t as a parameter. What do I give in over here? I
> > can't give NULL, cause it does use it for some stuff in the function
> > definition.
> 
> I wasn't suggesting that you use physio() but that you use it and it's
> friend as a prototype for yourself when you write a function to do what
> you want. The dev_t is associated with the device this is doing
> IO from so it's not necessarily relelvant to you.
> 
> you haven't told us enough about what you want to do to allow us to
> really understand your problem.
> 
> 
> 
> 
> 
> 
> > 
> > Also, the only other parameters to physio() are the uio and the ioflag
> > (which is not used at all). So, where is the kernel virtual address mapping?
> > Do I have to do something this this dev_t thing to open a virtual device
> > which maps to the kernel virtual address. If yes, how do I do this?
> > 
> > Thanx.
> > 
> 
> 
> To Unsubscribe: send mail to [EMAIL PROTECTED]
> with "unsubscribe freebsd-hackers" in the body of the message
> 


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



RE: Copying from Virtual Address Space to Physical Address

2002-08-30 Thread Julian Elischer



On Fri, 30 Aug 2002, Balaji, Pavan wrote:

> 
> Thanx. It's nearly done. I just need to know two more small things.
> 
> physio() requires a dev_t as a parameter. What do I give in over here? I
> can't give NULL, cause it does use it for some stuff in the function
> definition.

I wasn't suggesting that you use physio() but that you use it and it's
friend as a prototype for yourself when you write a function to do what
you want. The dev_t is associated with the device this is doing
IO from so it's not necessarily relelvant to you.

you haven't told us enough about what you want to do to allow us to
really understand your problem.






> 
> Also, the only other parameters to physio() are the uio and the ioflag
> (which is not used at all). So, where is the kernel virtual address mapping?
> Do I have to do something this this dev_t thing to open a virtual device
> which maps to the kernel virtual address. If yes, how do I do this?
> 
> Thanx.
> 


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



RE: Copying from Virtual Address Space to Physical Address

2002-08-30 Thread Balaji, Pavan


Thanx. It's nearly done. I just need to know two more small things.

physio() requires a dev_t as a parameter. What do I give in over here? I
can't give NULL, cause it does use it for some stuff in the function
definition.

Also, the only other parameters to physio() are the uio and the ioflag
(which is not used at all). So, where is the kernel virtual address mapping?
Do I have to do something this this dev_t thing to open a virtual device
which maps to the kernel virtual address. If yes, how do I do this?

Thanx.

Pavan Balaji,
Intel Corporation
Email: [EMAIL PROTECTED]

"Only the Paranoid Survive"  --  Andy Grove


> -Original Message-
> From: Julian Elischer [mailto:[EMAIL PROTECTED]]
> Sent: Friday, August 30, 2002 3:49 PM
> To: Balaji, Pavan
> Cc: '[EMAIL PROTECTED]'
> Subject: RE: Copying from Virtual Address Space to Physical Address
> 
> 
> 
> 
> On Fri, 30 Aug 2002, Balaji, Pavan wrote:
> 
> > 
> > I'm a little bit confused about this vmapbuf() thing. This 
> is what I think,
> > correct me if I'm wrong.
> > 
> > I have this User Virtual address, userbuf --> associated to physadd
> > 
> > Now, I do vmapbuf(physadd), and I get a Kernel Virtual 
> Address associated to
> > this "physadd". Now, I write to this Kernel Virtual Address 
> and it reflects
> > in userbuf? OhmyGod!!! Is that what it's supposed to do? 
> Hope it doesn't
> > oops my machine..
> > 
> > Also, if this is right, how do I get the kernel virtual address it's
> > associated to? The function returns a void.
> 
> The initial input to physio is a uio.
> A uio is a structure that points to a range of memory, (or 
> several ranges
> of memeory that are to betreated as a set of buffers) in user space
> or in kernel space.. (it has a flag to say which).
> 
> For now just talk about the userland case.
> For each range of addresses, a 'buf' is assigned that can 
> point to a range
> of memory. The pointers in the buf are set to be the same as the first
> region of the uio. Then vmapbuf() is called, that iterates 
> thtough all teh
> pages in the userland memory buffer, and one by one, finds 
> the physical
> address of those pages, and maps them into a contiguous region in 
> kernel space.  Now those pages are mapped in 2 places. 
> The user space and the kernel. if you wrote to them in the kernel,
> the data will appear in the userspace buffer.. of course
> it will also be on the PHYSICAL pages involved as well.
> 
> You want to do just the 2nd part of this..
> you want tostart with a list of physical pages, and map them into the
> kernel space somewhere. That way you can write to them. 
> WHen you are finished, you then unmap them.. 
> 
> 
> 
> > 
> > Thanx.
> > 
> > Pavan Balaji,
> > Intel Corporation
> > Email: [EMAIL PROTECTED]
> > 
> > "Only the Paranoid Survive"  --  Andy Grove
> > 
> > 
> > > -Original Message-
> > > From: Julian Elischer [mailto:[EMAIL PROTECTED]]
> > > Sent: Friday, August 30, 2002 3:20 PM
> > > To: Balaji, Pavan
> > > Cc: '[EMAIL PROTECTED]'
> > > Subject: Re: Copying from Virtual Address Space to 
> Physical Address
> > > 
> > > 
> > > 
> > > 
> > > On Fri, 30 Aug 2002, Julian Elischer wrote:
> > > 
> > > > Physio() does this.. first it finds the physical addresses 
> > > of the user
> > > > pages targetted, then it maps those pages into kernel 
> > > space, and then it
> > > > initiates IO to them. (this actually needs to change but 
> > > for now it's
> > > > true.
> > > 
> > > 
> > > to correct myself..
> > > physio() calls vmapbuf(bp) in order to do it..
> > > 
> > > 
> > 
> > To Unsubscribe: send mail to [EMAIL PROTECTED]
> > with "unsubscribe freebsd-hackers" in the body of the message
> > 
> 

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



RE: Copying from Virtual Address Space to Physical Address

2002-08-30 Thread Julian Elischer



On Fri, 30 Aug 2002, Balaji, Pavan wrote:

> 
> I'm a little bit confused about this vmapbuf() thing. This is what I think,
> correct me if I'm wrong.
> 
> I have this User Virtual address, userbuf --> associated to physadd
> 
> Now, I do vmapbuf(physadd), and I get a Kernel Virtual Address associated to
> this "physadd". Now, I write to this Kernel Virtual Address and it reflects
> in userbuf? OhmyGod!!! Is that what it's supposed to do? Hope it doesn't
> oops my machine..
> 
> Also, if this is right, how do I get the kernel virtual address it's
> associated to? The function returns a void.

The initial input to physio is a uio.
A uio is a structure that points to a range of memory, (or several ranges
of memeory that are to betreated as a set of buffers) in user space
or in kernel space.. (it has a flag to say which).

For now just talk about the userland case.
For each range of addresses, a 'buf' is assigned that can point to a range
of memory. The pointers in the buf are set to be the same as the first
region of the uio. Then vmapbuf() is called, that iterates thtough all teh
pages in the userland memory buffer, and one by one, finds the physical
address of those pages, and maps them into a contiguous region in 
kernel space.  Now those pages are mapped in 2 places. 
The user space and the kernel. if you wrote to them in the kernel,
the data will appear in the userspace buffer.. of course
it will also be on the PHYSICAL pages involved as well.

You want to do just the 2nd part of this..
you want tostart with a list of physical pages, and map them into the
kernel space somewhere. That way you can write to them. 
WHen you are finished, you then unmap them.. 



> 
> Thanx.
> 
> Pavan Balaji,
> Intel Corporation
> Email: [EMAIL PROTECTED]
> 
> "Only the Paranoid Survive"  --  Andy Grove
> 
> 
> > -Original Message-
> > From: Julian Elischer [mailto:[EMAIL PROTECTED]]
> > Sent: Friday, August 30, 2002 3:20 PM
> > To: Balaji, Pavan
> > Cc: '[EMAIL PROTECTED]'
> > Subject: Re: Copying from Virtual Address Space to Physical Address
> > 
> > 
> > 
> > 
> > On Fri, 30 Aug 2002, Julian Elischer wrote:
> > 
> > > Physio() does this.. first it finds the physical addresses 
> > of the user
> > > pages targetted, then it maps those pages into kernel 
> > space, and then it
> > > initiates IO to them. (this actually needs to change but 
> > for now it's
> > > true.
> > 
> > 
> > to correct myself..
> > physio() calls vmapbuf(bp) in order to do it..
> > 
> > 
> 
> To Unsubscribe: send mail to [EMAIL PROTECTED]
> with "unsubscribe freebsd-hackers" in the body of the message
> 


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



RE: Copying from Virtual Address Space to Physical Address

2002-08-30 Thread Julian Elischer



On Fri, 30 Aug 2002, Balaji, Pavan wrote:

> 
> I'm a little bit confused about this vmapbuf() thing. This is what I think,
> correct me if I'm wrong.
> 
> I have this User Virtual address, userbuf --> associated to physadd
> 
> Now, I do vmapbuf(physadd), and I get a Kernel Virtual Address associated to
> this "physadd". Now, I write to this Kernel Virtual Address and it reflects
> in userbuf? OhmyGod!!! Is that what it's supposed to do? Hope it doesn't
> oops my machine..

no that is correct. this function is for making user space buffers map
into kernel space.. 

you just want the second half of this..

Now I have a question for you
how do you know what pages you want to map into kernel virtual space?


> 
> Also, if this is right, how do I get the kernel virtual address it's
> associated to? The function returns a void.


The buf steucture is updated to hold KV addresses for the region.
'bp' is a pointer to a complicated struct that defines the buffer, not
to the address of the buffer itself.


> 
> Thanx.
> 
> Pavan Balaji,
> Intel Corporation
> Email: [EMAIL PROTECTED]
> 
> "Only the Paranoid Survive"  --  Andy Grove
> 
> 
> > -Original Message-
> > From: Julian Elischer [mailto:[EMAIL PROTECTED]]
> > Sent: Friday, August 30, 2002 3:20 PM
> > To: Balaji, Pavan
> > Cc: '[EMAIL PROTECTED]'
> > Subject: Re: Copying from Virtual Address Space to Physical Address
> > 
> > 
> > 
> > 
> > On Fri, 30 Aug 2002, Julian Elischer wrote:
> > 
> > > Physio() does this.. first it finds the physical addresses 
> > of the user
> > > pages targetted, then it maps those pages into kernel 
> > space, and then it
> > > initiates IO to them. (this actually needs to change but 
> > for now it's
> > > true.
> > 
> > 
> > to correct myself..
> > physio() calls vmapbuf(bp) in order to do it..
> > 
> > 
> 
> To Unsubscribe: send mail to [EMAIL PROTECTED]
> with "unsubscribe freebsd-hackers" in the body of the message
> 


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



RE: Copying from Virtual Address Space to Physical Address

2002-08-30 Thread Balaji, Pavan


I'm a little bit confused about this vmapbuf() thing. This is what I think,
correct me if I'm wrong.

I have this User Virtual address, userbuf --> associated to physadd

Now, I do vmapbuf(physadd), and I get a Kernel Virtual Address associated to
this "physadd". Now, I write to this Kernel Virtual Address and it reflects
in userbuf? OhmyGod!!! Is that what it's supposed to do? Hope it doesn't
oops my machine..

Also, if this is right, how do I get the kernel virtual address it's
associated to? The function returns a void.

Thanx.

Pavan Balaji,
Intel Corporation
Email: [EMAIL PROTECTED]

"Only the Paranoid Survive"  --  Andy Grove


> -Original Message-
> From: Julian Elischer [mailto:[EMAIL PROTECTED]]
> Sent: Friday, August 30, 2002 3:20 PM
> To: Balaji, Pavan
> Cc: '[EMAIL PROTECTED]'
> Subject: Re: Copying from Virtual Address Space to Physical Address
> 
> 
> 
> 
> On Fri, 30 Aug 2002, Julian Elischer wrote:
> 
> > Physio() does this.. first it finds the physical addresses 
> of the user
> > pages targetted, then it maps those pages into kernel 
> space, and then it
> > initiates IO to them. (this actually needs to change but 
> for now it's
> > true.
> 
> 
> to correct myself..
> physio() calls vmapbuf(bp) in order to do it..
> 
> 

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Re: Copying from Virtual Address Space to Physical Address

2002-08-30 Thread Julian Elischer



On Fri, 30 Aug 2002, Julian Elischer wrote:

> Physio() does this.. first it finds the physical addresses of the user
> pages targetted, then it maps those pages into kernel space, and then it
> initiates IO to them. (this actually needs to change but for now it's
> true.


to correct myself..
physio() calls vmapbuf(bp) in order to do it..



To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Re: Copying from Virtual Address Space to Physical Address

2002-08-30 Thread Julian Elischer



On Fri, 30 Aug 2002, Balaji, Pavan wrote:

> Hi,
> 
> Is there some function using which I can copy data from the Kernel Virtual
> Space to a pinned Physical Address Page.

Not as such, though there are plenty of places that do such a thing. The
answer is always to map the physical page somewhere into kernel space.

This is true because the processer can not access pages by their physical
address once it is in virtual address mode.

Physio() does this.. first it finds the physical addresses of the user
pages targetted, then it maps those pages into kernel space, and then it
initiates IO to them. (this actually needs to change but for now it's
true.

> 
> Thanx,
> 
> Pavan Balaji,
> Intel Corporation
> Email: [EMAIL PROTECTED]
> 
> "Only the Paranoid Survive"  --  Andy Grove

"until they die of ulcers" :-)

> 
> 


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message