* Mmap problem (VM_DENYWRITE)
[not found] <20040519062044.15651.qmail@web90107.mail.scd.yahoo.com>
@ 2004-05-24 18:49 ` shanthi kiran pendyala
2004-05-24 18:58 ` Tommy Reynolds
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: shanthi kiran pendyala @ 2004-05-24 18:49 UTC (permalink / raw)
To: linux-kernel
Hi,
<<I am not subscribed to this list b'cos of the volume of emails. Please
include my email in the reply.>>
I am writing a device driver for a fpga device.
I implemented a dummy char device to gain user space access to the device
registers thru mmap.
The kernel is 2.4.18.
The CPU is sibyte (mips64 cpu) with 40 bits of physical addressing and 44
bits of virtual addressing.
After mmaping in userspace any writes to the mmap region is not working.
I think it is b'cos of the protection field in the vma is set to
VM_DENYWRITE.
The complete prot flag is (VM_READ | VM_WRITE | VM_EXEC | VM_GROWSUP |
VM_DENYWRITE)
Why is this happening? I need to have both read and write access to region.
How do I fix this ?
Thanks for you help
Shanthi kiran
Output after running test program
=================================
building page tables for va 0x2aac5000 phy 0x10940000
vsize 0x20000 psize 0x20000 prot 0xa07
===================================================================
My mmap implementation is as follow
#define FPGA_CSR_ADDR_START 0x10940000
#define FPGA_CSR_ADDR_END 0x1095ffff
#define MMAP_SIZE (FPGA_CSR_ADDR_END + 1 - FPGA_CSR_ADDR_START)
int
fpga_mmap(struct file *filp, struct vm_area_struct *vma) {
unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
unsigned long vsize = vma->vm_end - vma->vm_start;
unsigned long phys = FPGA_CSR_ADDR_START + offset;
unsigned long psize = MMAP_SIZE - offset;
if(vsize > psize)
return -EINVAL;
printk("<1> building page tables for va 0x%lx phy 0x%lx \n",
vma->vm_start, phys);
printk("<1> vsize 0x%lx psize 0x%lx prot 0x%lx\n",
vsize, psize, vma->vm_page_prot.pgprot);
/* build new page tables */
if (remap_page_range(vma->vm_start, phys, vsize, vma->vm_page_prot))
return -EAGAIN;
return 0;
}
================================================================
I try to access to the device memory region with this user space test
program
....
fpga_fd = open(FPGA_DEV_FILE_NAME, O_RDWR);
if(cde_fd < 0) {
printf("can't open %s err %d\n", FPGA_DEV_FILE_NAME, fpga_fd);
goto finish;
}
offset = 0;
fpga_csr_start = mmap(0, MMAP_SIZE,
PROT_READ|PROT_WRITE, MAP_SHARED,
fpga_fd, offset);
if (fpga_csr_start < 0 ) {
printf(" error in mmap errno %d", errno);
goto finish;
}
...
============================================================================
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Mmap problem (VM_DENYWRITE)
2004-05-24 18:49 ` Mmap problem (VM_DENYWRITE) shanthi kiran pendyala
@ 2004-05-24 18:58 ` Tommy Reynolds
2004-05-24 20:22 ` Richard B. Johnson
2004-05-24 20:29 ` Chris Wright
2 siblings, 0 replies; 4+ messages in thread
From: Tommy Reynolds @ 2004-05-24 18:58 UTC (permalink / raw)
To: shanthi kiran pendyala; +Cc: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 650 bytes --]
Uttered "shanthi kiran pendyala" <skiranp@cisco.com>, spake thus:
> After mmaping in userspace any writes to the mmap region is not working.
> I think it is b'cos of the protection field in the vma is set to
> VM_DENYWRITE.
> The complete prot flag is (VM_READ | VM_WRITE | VM_EXEC | VM_GROWSUP |
> VM_DENYWRITE)
>
> Why is this happening? I need to have both read and write access to region.
> How do I fix this ?
Take out the VM_DENYWRITE flag. Duh.
Are you gonna put code in the mapped area? No? Turn off VM_EXEC.
Are you gonna place your stack in the mapped area? No? Turn of
VM_GROWSUP.
Have you read "man mmap"? No? Try it.
Cheers!
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Mmap problem (VM_DENYWRITE)
2004-05-24 18:49 ` Mmap problem (VM_DENYWRITE) shanthi kiran pendyala
2004-05-24 18:58 ` Tommy Reynolds
@ 2004-05-24 20:22 ` Richard B. Johnson
2004-05-24 20:29 ` Chris Wright
2 siblings, 0 replies; 4+ messages in thread
From: Richard B. Johnson @ 2004-05-24 20:22 UTC (permalink / raw)
To: shanthi kiran pendyala; +Cc: linux-kernel
On Mon, 24 May 2004, shanthi kiran pendyala wrote:
> Hi,
>
> <<I am not subscribed to this list b'cos of the volume of emails. Please
> include my email in the reply.>>
>
> ===================================================================
> My mmap implementation is as follow
Can't you just use ioremap_nocache(FPGA_CSR_ADDR_START, MMAP_SIZE);
>
> #define FPGA_CSR_ADDR_START 0x10940000
> #define FPGA_CSR_ADDR_END 0x1095ffff
> #define MMAP_SIZE (FPGA_CSR_ADDR_END + 1 - FPGA_CSR_ADDR_START)
>
> }
> ================================================================
> I try to access to the device memory region with this user space test
> program
> ....
> fpga_fd = open("/dev/mem", O_RDWR);
If you want to get the physical address from your driver, just
make an ioctl() to return it. In the meantime, mmap() with this
fd.
>
> if(cde_fd < 0) {
> printf("can't open %s err %d\n", FPGA_DEV_FILE_NAME, fpga_fd);
> goto finish;
> }
>
> hint = 0x10000000;
> fpga_csr_start = mmap(hint, MMAP_SIZE,
> PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED,
> fpga_fd, FPGA_CSR_ADDR_START);
>
> if (fpga_csr_start == (void *)-1 ) {
|_______________ Read docs, don't assume!!
> printf(" error in mmap errno %d", errno);
> goto finish;
> }
close(fpga_fd); // Not needed anymore
>
> ...
> ============================================================================
>
Cheers,
Dick Johnson
Penguin : Linux version 2.4.26 on an i686 machine (5570.56 BogoMips).
Note 96.31% of all statistics are fiction.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Mmap problem (VM_DENYWRITE)
2004-05-24 18:49 ` Mmap problem (VM_DENYWRITE) shanthi kiran pendyala
2004-05-24 18:58 ` Tommy Reynolds
2004-05-24 20:22 ` Richard B. Johnson
@ 2004-05-24 20:29 ` Chris Wright
2 siblings, 0 replies; 4+ messages in thread
From: Chris Wright @ 2004-05-24 20:29 UTC (permalink / raw)
To: shanthi kiran pendyala; +Cc: linux-kernel
* shanthi kiran pendyala (skiranp@cisco.com) wrote:
> The complete prot flag is (VM_READ | VM_WRITE | VM_EXEC | VM_GROWSUP |
> VM_DENYWRITE)
[snip]
> Output after running test program
> =================================
> building page tables for va 0x2aac5000 phy 0x10940000
> vsize 0x20000 psize 0x20000 prot 0xa07
>
[snip]
> printk("<1> vsize 0x%lx psize 0x%lx prot 0x%lx\n",
> vsize, psize, vma->vm_page_prot.pgprot);
I believe you've drawn the wrong conclusion. This contains page
protection bits relevant for the page tables. You've decoded
vm_page_prot as if it were vm_flags.
thanks,
-chris
--
Linux Security Modules http://lsm.immunix.org http://lsm.bkbits.net
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-05-24 20:30 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20040519062044.15651.qmail@web90107.mail.scd.yahoo.com>
2004-05-24 18:49 ` Mmap problem (VM_DENYWRITE) shanthi kiran pendyala
2004-05-24 18:58 ` Tommy Reynolds
2004-05-24 20:22 ` Richard B. Johnson
2004-05-24 20:29 ` Chris Wright
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®