Skip to contentSkip to conversation

Problem with remap_page_range/mmap

DISCUSSION Christian Leber 3 participants 5 messages Mar 25, 2004 – Mar 26, 2004

lore
Share & tools
lore
#0 lore raw

Hello,

I have a problem with mmaping memory to userspace.

It´s very simple:

addr = __get_free_pages(GFP_KERNEL,0);
int atoll_fops_mmap(struct file *filp, struct vm_area_struct *vma)

{
        vma->vm_flags |= VM_SHM | VM_LOCKED | VM_IO;
	
	if(remap_page_range_A(vma,
		vma->vm_start, addr, 4096,
		vma->vm_page_prot)) {
			printk("remapping send space failed\n");
			return -ENXIO;
	}
        *(unsigned long *)addr = 0x23;
        printk("mmap finished, first bytes: %lx\n",*(unsigned long *)addr);
	return 0;
}
int atoll_fops_release(struct inode *inode,struct file *filp)
{
	printk("release, first bytes: %lx\n",*(unsigned long *)addr);
	return 0;
}

complete code is here:
http://debian.christian-leber.de/mmap_problem/atollinit.txt
or as tar
http://debian.christian-leber.de/mmap_problem.tar.bz2

The stupid little testprogramm:
ptr=mmap(NULL,4096,PROT_READ|PROT_WRITE,MAP_SHARED,fdopen,0); if(ptr==-1) printf("ERROR\n");
*(ptr) = 0x42;
printf("%lx\n",*(ptr));

This works as expected with 2.6.3 on IA64
Testprogramm gives out "42"
and in the kernel log:
mmap finished, first bytes: 23
release, first bytes: 42

Now it gets odd:
On a Dual PIII; another one; dual xeon; another one; and a P3 laptop

The testprogramm gives out "ffffffff"
In the kernel log:
mmap finished, first bytes: 23
release, first bytes: 23

So never anything is written to memory.
(it also doesn´t depend on the kernel, i tried several versions/configurations)

On a Duron (also tried with exact the same kernel from one of the systems above), the Testprogramm gives correct output, but the kernel log says:
mmap finished, first bytes: 23
release, first bytes: 23

So also nothing is actually written to the memory.

Is that a bug (can´t imagine) or do I do a really stupid error?

Christian Leber

Signature · 3 lines
  "Omnis enim res, quae dando non deficit, dum habetur et non datur,
   nondum habetur, quomodo habenda est."       (Aurelius Augustinus)
  Translation: <http://gnuhh.org/work/fsf-europe/augustinus.html>
#1 lore raw
Quoted 11 lines · Christian Leber

addr = __get_free_pages(GFP_KERNEL,0);
int atoll_fops_mmap(struct file *filp, struct vm_area_struct *vma)

{
        vma->vm_flags |= VM_SHM | VM_LOCKED | VM_IO;
	
	if(remap_page_range_A(vma,
		vma->vm_start, addr, 4096,
		vma->vm_page_prot)) {
			printk("remapping send space failed\n");
			return -ENXIO;
	}

You can't call remap_page_range on normal kernel pages. It works only if you mark them PG_reserved, but even that use is usually not a good idea.

#2 lore raw
Quoted 2 lines · Christoph Hellwig

You can't call remap_page_range on normal kernel pages. It works only if you mark them PG_reserved, but even that use is usually not a good idea.

It also didn´t work with PG_reserved.
What would be the good idea? I need at least 8 at least 4MB (2MB are enough for 2.4) big physical memory pieces for DMA, mapped to userspace.

What is the reason why it doesn´t work? There seems to be no special remap_page_range for ia64.

Christian Leber

Signature · 3 lines
  "Omnis enim res, quae dando non deficit, dum habetur et non datur,
   nondum habetur, quomodo habenda est."       (Aurelius Augustinus)
  Translation: <http://gnuhh.org/work/fsf-europe/augustinus.html>
#3 lore raw
Quoted 6 lines · Christian Leber

It also didn´t work with PG_reserved.
What would be the good idea? I need at least 8 at least 4MB (2MB are enough for 2.4) big physical memory pieces for DMA, mapped to userspace.

What is the reason why it doesn´t work? There seems to be no special remap_page_range for ia64.

Put the page structs into an array and return them from ->nopage. The kernel pagefault code will set up the ptes for you.

Now actually getting 4MB of continguous memory is a different issue..

I'm surprised you actually managed to get the allocation to succeed.

#4 lore raw
Quoted 5 lines · On Fri, 26 Mar 2004 09:46:56 +0000 Christoph Hellwig <[email protected]> wrote:
Quoted 4 lines · Christian Leber

What would be the good idea? I need at least 8 at least 4MB (2MB are enough for 2.4) big physical memory pieces for DMA, mapped to userspace.

Quoted 8 lines
Quoted 1 line

remap_page_range for ia64.

Put the page structs into an array and return them from ->nopage. The kernel pagefault code will set up the ptes for you.

Now actually getting 4MB of continguous memory is a different issue..

I'm surprised you actually managed to get the allocation to succeed.

There is more detailed information about make page usable to user space,
http://www.xml.com/ldd/chapter/book/ch13.html

Hope that's useful.

Signature · 3 lines
Hu Gang / Steve
Linux Registered User 204016
GPG Public Key: http://soulinfo.com/~hugang/hugang.asc