* Re: mmap
@ 2001-07-02 14:00 mdaljeet
2001-07-03 17:47 ` mmap Jens Axboe
0 siblings, 1 reply; 15+ messages in thread
From: mdaljeet @ 2001-07-02 14:00 UTC (permalink / raw)
To: Gerd Knorr; +Cc: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1313 bytes --]
I use the 'map_user_kiobuf' and 'lock_kiovec' kernel routines in a module
for 'user space memory'. After that if I pass the
'(iobuf->maplist[0])-mem_map) << PAGE_SHIFT)' to the hardware for DMA
operations and it works fine for Intel platforms. Now how can I use the
'iobuf' struct obtained after lock_kiovec operation to get a PCI bus
address that I can pass to hardware for DMA operations on my Apple
machine.?
thanks,
Daljeet.
|--------+----------------------->
| | Gerd Knorr |
| | <kraxel@bytes|
| | ex.org> |
| | |
| | 05/15/01 |
| | 01:03 PM |
| | Please |
| | respond to |
| | Gerd Knorr |
| | |
|--------+----------------------->
>-----------------------------------------------------------------------|
| |
| To: linux-kernel@vger.kernel.org |
| cc: (bcc: Daljeet Maini/India/IBM) |
| Subject: Re: mmap |
>-----------------------------------------------------------------------|
[-- Attachment #2: Type: text/plain, Size: 1125 bytes --]
mdaljeet@in.ibm.com wrote:
> I am doing the following:
>
> malloc some memory is user space
> pass its pointer to some kernel module
> in the kernel module...do a pci_alloc_consistent so that i get a
memory
> region for PCI DMA operations
Wrong approach, you can use kiobufs if you want DMA to the malloc()ed
userspace memory:
* lock down the user memory using map_user_kiobuf() + lock_kiovec()
(see linux/iobuf.h).
* translate the iobuf->maplist into a scatterlist [1]
* feed pci_map_sg() with the scatterlist to get DMA addresses.
you can pass to the hardware.
And the reverse to free everything when you are done of course.
Gerd
[1] IMHO it would be more useful if iobufs would use a scatterlist
instead of an struct page* array.
--
Gerd Knorr <kraxel@bytesex.org> -- SuSE Labs, Außenstelle Berlin
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: mmap
2001-07-02 14:00 mmap mdaljeet
@ 2001-07-03 17:47 ` Jens Axboe
0 siblings, 0 replies; 15+ messages in thread
From: Jens Axboe @ 2001-07-03 17:47 UTC (permalink / raw)
To: mdaljeet; +Cc: Gerd Knorr, linux-kernel
On Mon, Jul 02 2001, mdaljeet@in.ibm.com wrote:
> [1] IMHO it would be more useful if iobufs would use a scatterlist
> instead of an struct page* array.
No that would be horrible, at least with the current scatterlist. A page
based scatterlist would be alright though -- but this boils down to the
per-page offset debate again.
--
Jens Axboe
^ permalink raw reply [flat|nested] 15+ messages in thread
* mmap
@ 2012-08-23 13:06 Christophe Hauser
2012-08-23 14:18 ` mmap Mulyadi Santosa
0 siblings, 1 reply; 15+ messages in thread
From: Christophe Hauser @ 2012-08-23 13:06 UTC (permalink / raw)
To: kernelnewbies
Hi all,
When tracking mmaps from LSM with the following hook:
static int file_mmap(struct file *file, unsigned long reqprot,
unsigned long prot, unsigned long flags,
unsigned long addr, unsigned long addr_only);
I often get:
file = NULL
flags = 0x0 (MAP_FILE)
prot = 0x0 (PROT_NONE)
I am wondering what is the use for mmap with MAP_FILE and PROT_NONE together ?
Not sure how to interpret that ?
--
Christophe
^ permalink raw reply [flat|nested] 15+ messages in thread* mmap
2012-08-23 13:06 mmap Christophe Hauser
@ 2012-08-23 14:18 ` Mulyadi Santosa
0 siblings, 0 replies; 15+ messages in thread
From: Mulyadi Santosa @ 2012-08-23 14:18 UTC (permalink / raw)
To: kernelnewbies
Hi...
On Thu, Aug 23, 2012 at 8:06 PM, Christophe Hauser
<christophe.hauser@supelec.fr> wrote:
> I often get:
> file = NULL
> flags = 0x0 (MAP_FILE)
> prot = 0x0 (PROT_NONE)
>
> I am wondering what is the use for mmap with MAP_FILE and PROT_NONE together ?
> Not sure how to interpret that ?
hmm, things that cross my mind:
- protecting low memory address (capturing null pointer abuse)
- stack guard...to catch buffer over flow
Maybe there are others.... CMIIW
--
regards,
Mulyadi Santosa
Freelance Linux trainer and consultant
blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com
^ permalink raw reply [flat|nested] 15+ messages in thread
* mmap
@ 2011-12-02 12:20 Sébastien Paumier
2011-12-02 14:45 ` mmap Eric Dumazet
0 siblings, 1 reply; 15+ messages in thread
From: Sébastien Paumier @ 2011-12-02 12:20 UTC (permalink / raw)
To: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 699 bytes --]
Hi,
I have a question about mmap's behavior when one tries to map a file asking for
a length greater than the actual file size. When I run the attached code on a
100 bytes file, I have the following output:
(... file content followed by zeros...)
n=4096
write: Bad address
So, it seems that the actual memory area provided by mmap is one page large and
not the requested length of filesize+10000. I guess that 'write' writes less
than requested because it was interrupted by the SIGBUS signal. And my question is:
shouldn't mmap either complain about the requested length or provide an
accessible area of the requested length, instead of silently failing ?
Best regards,
Sébastien Paumier
[-- Attachment #2: mmap.c --]
[-- Type: text/x-csrc, Size: 884 bytes --]
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include <signal.h>
#include <time.h>
#include <errno.h>
int main(int argc, char* argv[]){
if(argc != 2) {
fprintf(stderr,"Usage: %s <file>\n",argv[0]);
exit(1);
}
int fd = open(argv[argc-1],O_RDONLY);
if (fd==-1) {
perror("open");
return 1;
}
struct stat status;
if(-1 == fstat(fd,&status)){
perror("fstat");
return 1;
}
char* mem=(char*) mmap(NULL, status.st_size+10000, PROT_READ, MAP_PRIVATE,fd,0);
if(mem == MAP_FAILED){
perror("mmap");
return 1;
}
int n;
if ( -1 == (n=write(1,mem, status.st_size+10000))) {
perror("write");
return 1;
}
printf("\nn=%d\n",n);
if( -1 == (n=write(1,mem+n, status.st_size+10000-n))) {
perror("write");
return 1;
}
printf("\nn=%d\n",n);
return 0;
}
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: mmap
2011-12-02 12:20 mmap Sébastien Paumier
@ 2011-12-02 14:45 ` Eric Dumazet
0 siblings, 0 replies; 15+ messages in thread
From: Eric Dumazet @ 2011-12-02 14:45 UTC (permalink / raw)
To: Sébastien Paumier; +Cc: linux-kernel
Le vendredi 02 décembre 2011 à 13:20 +0100, Sébastien Paumier a écrit :
> Hi,
> I have a question about mmap's behavior when one tries to map a file asking for
> a length greater than the actual file size. When I run the attached code on a
> 100 bytes file, I have the following output:
>
> (... file content followed by zeros...)
> n=4096
> write: Bad address
>
> So, it seems that the actual memory area provided by mmap is one page large and
> not the requested length of filesize+10000. I guess that 'write' writes less
> than requested because it was interrupted by the SIGBUS signal. And my question is:
>
> shouldn't mmap either complain about the requested length or provide an
> accessible area of the requested length, instead of silently failing ?
Accessing non existing memory leads to SIGBUS signal, not a silent
failure. Its documented behavior.
man mmap
SIGBUS Attempted access to a portion of the buffer that does not corre‐
spond to the file (for example, beyond the end of the file,
including the case where another process has truncated the
file).
^ permalink raw reply [flat|nested] 15+ messages in thread
* mmap
@ 2006-10-26 0:48 Sudharsan Rangarajan
2006-10-26 1:02 ` mmap Ian McDonald
2006-10-26 1:02 ` mmap Hagen Paul Pfeifer
0 siblings, 2 replies; 15+ messages in thread
From: Sudharsan Rangarajan @ 2006-10-26 0:48 UTC (permalink / raw)
To: dccp
Hi everyone,
I would like to look at the mmap implementation for dccp. I looked at
http://wlug.org.nz/DCCP to get the source, but cant seem to find it!
Can someone please help?
Thanks,
Sudharsan
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: mmap
2006-10-26 0:48 mmap Sudharsan Rangarajan
@ 2006-10-26 1:02 ` Ian McDonald
2006-10-26 1:02 ` mmap Hagen Paul Pfeifer
1 sibling, 0 replies; 15+ messages in thread
From: Ian McDonald @ 2006-10-26 1:02 UTC (permalink / raw)
To: dccp
On 10/26/06, Sudharsan Rangarajan <sudharsan.r@gmail.com> wrote:
> Hi everyone,
> I would like to look at the mmap implementation for dccp. I looked at
> http://wlug.org.nz/DCCP to get the source, but cant seem to find it!
> Can someone please help?
>
> Thanks,
> Sudharsan
It's at http://research.wand.net.nz/software/dccp.php
If you have questions then ask me although it's been a while since I
looked at the code.
It is not part of the kernel, but feel free to pick the mmap parts out
and put them forward for merging!
Ian
--
Ian McDonald
Web: http://wand.net.nz/~iam4
Blog: http://imcdnzl.blogspot.com
WAND Network Research Group
Department of Computer Science
University of Waikato
New Zealand
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: mmap
2006-10-26 0:48 mmap Sudharsan Rangarajan
2006-10-26 1:02 ` mmap Ian McDonald
@ 2006-10-26 1:02 ` Hagen Paul Pfeifer
1 sibling, 0 replies; 15+ messages in thread
From: Hagen Paul Pfeifer @ 2006-10-26 1:02 UTC (permalink / raw)
To: dccp
* Sudharsan Rangarajan | 2006-10-25 17:48:41 [-0700]:
>Hi everyone,
>I would like to look at the mmap implementation for dccp. I looked at
>http://wlug.org.nz/DCCP to get the source, but cant seem to find it!
>Can someone please help?
DCCP-Sockets implement no mmap operations, ENODEV is returned if you use it!
Take a look at you kernel-sources for dccp implementation details:
e.g. /usr/src/linux-2.6/net/dccp/*
>Thanks,
>Sudharsan
HGN
--
In the manual it said: 'For use with Windows95, 98, or better.' So I
installed LINUX...
unbekannter User
^ permalink raw reply [flat|nested] 15+ messages in thread
* RE: mmap
@ 2006-01-05 10:03 Fillod Stephane
0 siblings, 0 replies; 15+ messages in thread
From: Fillod Stephane @ 2006-01-05 10:03 UTC (permalink / raw)
To: Brett McNerney; +Cc: linuxppc-embedded
Brett McNerney wrote:
[...]
>I am open for other options on how I can do this other then mmap. And
am still not against a driver >built into the kernel if someone has a an
example I could see and can explain how to add it in so it >builds into
the kernel since I have had no success on that either and have tried a
couple different >tutorials I found online with no success.
Ah, this is the first one of 2006. Happy new year!
Your question is a linuxppc-embedded FAQ, coming at least every 3 months
here.
It is documented in Denx's FAQ[1], and accessible through shorter
URL[2].
For more information, please follow this thread[3] (not ppc specific
actually).
A good book of C language about what are pointers and how scanf works
might=20
help too in case of confusion :-)
[1]
http://www.denx.de/twiki/bin/view/PPCEmbedded/DeviceDrivers#Section_Acce
ssingPeripheralsFromUserSpace
[2] http://tinyurl.com/6c7th
[3] http://lists.linuxppc.org/linuxppc-embedded/200403/msg00059.html
Regards,
--=20
Stephane
^ permalink raw reply [flat|nested] 15+ messages in thread
* mmap
@ 2006-01-05 6:16 Brett McNerney
0 siblings, 0 replies; 15+ messages in thread
From: Brett McNerney @ 2006-01-05 6:16 UTC (permalink / raw)
To: linuxppc-embedded
[-- Attachment #1: Type: text/plain, Size: 1785 bytes --]
I have been trying to work with mmap to read and write to a custom hardware
module on a Xilinx virtex 4 board with linux running on the ppc. But I have
gotten many different errors. But the main one I am seeing is segmentation
error. Below is the code I am using. The device has a 256 address size
specified in the Xilinx tools and the base address I set in the Xilinx tools
was 0x81000000. Am I doing something wrong in the code? Any help would be
greatly appreciated as we have decided to try this method instead of using a
driver built into the kernel as this allows us some more flexibility. Also
the hardware module I am using for testing contains 3 hardware registers
which adds two of the registers and returns the result in the third one.
I am open for other options on how I can do this other then mmap. And am
still not against a driver built into the kernel if someone has a an example
I could see and can explain how to add it in so it builds into the kernel
since I have had no success on that either and have tried a couple different
tutorials I found online with no success.
Thanks for any help anyone can provide.
Brett
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
int main(void) {
int fd;
int *p;
fd = open("/dev/mem, O_RDWR);
p = (int *)mmap(0, 256, PROT_READ|PROT_WRITE,
MAP_PRIVATE, fd, 0x81000000);
if (p == MAP_FAILED) {
printf("Err: cannot access adder!/n");
return -1;
}
printf("input two numbers: ");
scanf("%d", &p);
scanf("%d", &p+1);
printf("%d + %d = %d\n", *p, *(p+1), *(p+2));
munmap(p,256);
close(fd);
return 0;
}
[-- Attachment #2: Type: text/html, Size: 9811 bytes --]
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: mmap
@ 2001-05-15 10:08 mdaljeet
0 siblings, 0 replies; 15+ messages in thread
From: mdaljeet @ 2001-05-15 10:08 UTC (permalink / raw)
To: Gerd Knorr; +Cc: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1077 bytes --]
When I malloc the memory in user space, the memory may be discontinuous for
large chunks of memory say 16k or 32k. Does the 'kiobuf' interface take
care of this or it assumes it to be continuous?
regards,
Daljeet Maini
IBM Global Services Ltd. - Bangalore
Ph. No. - 5267117 Extn 2954
|--------+----------------------->
| | Gerd Knorr |
| | <kraxel@bytes|
| | ex.org> |
| | |
| | 05/15/01 |
| | 01:03 PM |
| | Please |
| | respond to |
| | Gerd Knorr |
| | |
|--------+----------------------->
>--------------------------------------------------------|
| |
| To: linux-kernel@vger.kernel.org |
| cc: (bcc: Daljeet Maini/India/IBM) |
| Subject: Re: mmap |
>--------------------------------------------------------|
[-- Attachment #2: Type: text/plain, Size: 1125 bytes --]
mdaljeet@in.ibm.com wrote:
> I am doing the following:
>
> malloc some memory is user space
> pass its pointer to some kernel module
> in the kernel module...do a pci_alloc_consistent so that i get a
memory
> region for PCI DMA operations
Wrong approach, you can use kiobufs if you want DMA to the malloc()ed
userspace memory:
* lock down the user memory using map_user_kiobuf() + lock_kiovec()
(see linux/iobuf.h).
* translate the iobuf->maplist into a scatterlist [1]
* feed pci_map_sg() with the scatterlist to get DMA addresses.
you can pass to the hardware.
And the reverse to free everything when you are done of course.
Gerd
[1] IMHO it would be more useful if iobufs would use a scatterlist
instead of an struct page* array.
--
Gerd Knorr <kraxel@bytesex.org> -- SuSE Labs, Außenstelle Berlin
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
^ permalink raw reply [flat|nested] 15+ messages in thread* mmap
@ 2001-05-15 6:47 mdaljeet
2001-05-15 7:33 ` mmap Gerd Knorr
2001-05-15 9:42 ` mmap Alan Cox
0 siblings, 2 replies; 15+ messages in thread
From: mdaljeet @ 2001-05-15 6:47 UTC (permalink / raw)
To: linux-kernel
I am doing the following:
malloc some memory is user space
pass its pointer to some kernel module
in the kernel module...do a pci_alloc_consistent so that i get a memory
region for PCI DMA operations
now the problem is that i want to remap the address range pointed by the
user space pointer to the memory region allocated by the
'pci_alloc_consistent' inside the module. I think this is possible..need
some hints....
thanks,
Daljeet Maini
IBM Global Services Ltd. - Bangalore
Ph. No. - 5267117 Extn 2954
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: mmap
2001-05-15 6:47 mmap mdaljeet
@ 2001-05-15 7:33 ` Gerd Knorr
2001-05-15 9:42 ` mmap Alan Cox
1 sibling, 0 replies; 15+ messages in thread
From: Gerd Knorr @ 2001-05-15 7:33 UTC (permalink / raw)
To: linux-kernel
mdaljeet@in.ibm.com wrote:
> I am doing the following:
>
> malloc some memory is user space
> pass its pointer to some kernel module
> in the kernel module...do a pci_alloc_consistent so that i get a memory
> region for PCI DMA operations
Wrong approach, you can use kiobufs if you want DMA to the malloc()ed
userspace memory:
* lock down the user memory using map_user_kiobuf() + lock_kiovec()
(see linux/iobuf.h).
* translate the iobuf->maplist into a scatterlist [1]
* feed pci_map_sg() with the scatterlist to get DMA addresses.
you can pass to the hardware.
And the reverse to free everything when you are done of course.
Gerd
[1] IMHO it would be more useful if iobufs would use a scatterlist
instead of an struct page* array.
--
Gerd Knorr <kraxel@bytesex.org> -- SuSE Labs, Außenstelle Berlin
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: mmap
2001-05-15 6:47 mmap mdaljeet
2001-05-15 7:33 ` mmap Gerd Knorr
@ 2001-05-15 9:42 ` Alan Cox
1 sibling, 0 replies; 15+ messages in thread
From: Alan Cox @ 2001-05-15 9:42 UTC (permalink / raw)
To: mdaljeet; +Cc: linux-kernel
> now the problem is that i want to remap the address range pointed by the
> user space pointer to the memory region allocated by the
> 'pci_alloc_consistent' inside the module. I think this is possible..need
> some hints....
Wrong way around. Ask the device to create its mapping and reply with the size
mmap the object
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2012-08-23 14:18 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-07-02 14:00 mmap mdaljeet
2001-07-03 17:47 ` mmap Jens Axboe
-- strict thread matches above, loose matches on Subject: below --
2012-08-23 13:06 mmap Christophe Hauser
2012-08-23 14:18 ` mmap Mulyadi Santosa
2011-12-02 12:20 mmap Sébastien Paumier
2011-12-02 14:45 ` mmap Eric Dumazet
2006-10-26 0:48 mmap Sudharsan Rangarajan
2006-10-26 1:02 ` mmap Ian McDonald
2006-10-26 1:02 ` mmap Hagen Paul Pfeifer
2006-01-05 10:03 mmap Fillod Stephane
2006-01-05 6:16 mmap Brett McNerney
2001-05-15 10:08 mmap mdaljeet
2001-05-15 6:47 mmap mdaljeet
2001-05-15 7:33 ` mmap Gerd Knorr
2001-05-15 9:42 ` mmap Alan Cox
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.