mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Sam Abu-Nassar" <djanssen1@hotmail.com>
To: nickpiggin@yahoo.com.au
Cc: linux-kernel@vger.kernel.org, karl.kiniger@med.ge.com
Subject: Re: Using remap_pfn_range causes system hang on app close in 2.6.15 & up
Date: Wed, 26 Apr 2006 18:47:59 +0000	[thread overview]
Message-ID: <BAY101-F13D9FEC07E274B8565DD3BF4BC0@phx.gbl> (raw)
In-Reply-To: <444F4B0B.20609@yahoo.com.au>

>Sam Abu-Nassar wrote:
>>Hello,
>>
>>I posted this query a couple of weeks ago regarding a problem with 
>>remap_pfn_range.  I was able to resolve the issue and I thought I would 
>>post my findings in case it helps someone else or results in a kernel fix. 
>>  I will try to keep this short.
>>
>>In a nutshell, my driver support user APIs that maps system RAM or a PCI 
>>BAR space to user space.  What I did not mention in my original post is 
>>that my driver performed a sort of custom protocol when mmap() is called.  
>>Since mmap() really only provides a limited amount of space (the offset 
>>field) that I can use to pass additional information to my driver, I had 
>>implemented a custom protocol, which works as follows:
>>
>>1.  API calls mmap to obtain a user virtual address
>>2.  Drivers mmap routine stores the VMA in an internal list and returns 
>>ok.
>>3.  API then issues a custom IOCTL to driver to complete mapping with 
>>additional info
>>4.  Driver retrieves VMA from internal list and performs mapping with 
>>io/remap_pfn_range, depending upon whether it's to system RAM or a PCI 
>>BAR.
>>
>>The mappings always work fine, but starting with 2.6.15, the system 
>>freeezes when the file descriptor is closed.  I tried numerous tests and 
>>compared my code with existing drivers, such as /dev/mem.  Here is what I 
>>found:
>>
>>The fix involved moving my calls to io/remap_pfn_range into my 
>>Dispatch_mmap() routine.  Once I did this, the system no longer crashed.  
>>I still implement sending some custom information to the driver, but now I 
>>use special values in the offset field, remembering that the offset is 
>>eventually shifted by PAGE_SIZE by the time it reaches the driver.  My 
>>driver code essentially did not change.  In effect, all I really did was 
>>move it to the driver's mmap() routine.
>>
>>I should mention that my original protocol has worked fine in kernels 2.2, 
>>2.4, and up to 2.6.14.  Some change to the VM subsystem in 2.6.15 broke my 
>>original code.  I don't believe there should be an issue with calling 
>>remap_pfn_range outside of the driver's mmap() routine, but I am not a 
>>kernel developer, so I could be wrong in my assumption.  One of my 
>>customers posed this question to Nick Piggin, and he seemed to think there 
>>should not be a problem with this.
>
>Nick Piggin wrote:
>Well, I think I said it shouldn't oops like this... I don't think it
>is particularly robust WRT error cases or concurrent page faults
>(between mmap and ioctl).
>
>As we established earlier with a debug patch, the reason for the oops
>is that VM_PFNMAP has been cleared from your vma->vm_flags for some
>reason. This is causing the unmap code to mistakenly try to remove
>reverse maps and refcounts from the struct pages.
>
>I don't know why VM_PFNMAP should be getting cleared. But if it
>remains set then the oops should go away.


As one of my tests, I manually added the VM_PFNMAP flag before calling 
remap_pfn_range().  This did not resolve the issue.  Also, I checked the 
kernel source (vanilla Fedora Core 5) and VM_PFNMAP is always added inside 
remap_pfn_range() anyway, along with VM_IO & VM_RESERVED.

Note that the kernel oops I posted only happened rarely.  Most of the time, 
the system completely froze immediately when the file descriptor was closed 
and I didn't get any oops message.



  reply	other threads:[~2006-04-26 18:48 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <5.1.0.14.2.20060425130439.00bc0008@exchange.plxtech.com>
2006-04-25 20:30 ` Sam Abu-Nassar
2006-04-26 10:27   ` Nick Piggin
2006-04-26 18:47     ` Sam Abu-Nassar [this message]
2006-04-27  3:36       ` Nick Piggin
2006-04-11 23:39 Sam Abu-Nassar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BAY101-F13D9FEC07E274B8565DD3BF4BC0@phx.gbl \
    --to=djanssen1@hotmail.com \
    --cc=karl.kiniger@med.ge.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nickpiggin@yahoo.com.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®