From patchwork Mon Nov 17 07:26:13 2008 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sonny Rao X-Patchwork-Id: 9073 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id 0B169DDF6D for ; Mon, 17 Nov 2008 18:26:39 +1100 (EST) X-Original-To: linuxppc-dev@ozlabs.org Delivered-To: linuxppc-dev@ozlabs.org Received: from e33.co.us.ibm.com (e33.co.us.ibm.com [32.97.110.151]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "e32.co.us.ibm.com", Issuer "Equifax" (verified OK)) by ozlabs.org (Postfix) with ESMTPS id 3FD9BDDD0B for ; Mon, 17 Nov 2008 18:26:18 +1100 (EST) Received: from d03relay02.boulder.ibm.com (d03relay02.boulder.ibm.com [9.17.195.227]) by e33.co.us.ibm.com (8.13.1/8.13.1) with ESMTP id mAH7Pjo8012671 for ; Mon, 17 Nov 2008 00:25:45 -0700 Received: from d03av01.boulder.ibm.com (d03av01.boulder.ibm.com [9.17.195.167]) by d03relay02.boulder.ibm.com (8.13.8/8.13.8/NCO v9.1) with ESMTP id mAH7QDBD145804 for ; Mon, 17 Nov 2008 00:26:13 -0700 Received: from d03av01.boulder.ibm.com (loopback [127.0.0.1]) by d03av01.boulder.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id mAH7QDD6014267 for ; Mon, 17 Nov 2008 00:26:13 -0700 Received: from us.ibm.com (dyn9414181.austin.ibm.com [9.41.41.81]) by d03av01.boulder.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id mAH7QD70014261; Mon, 17 Nov 2008 00:26:13 -0700 Received: by us.ibm.com (Postfix, from userid 1000) id 46AE667C37E; Mon, 17 Nov 2008 01:26:13 -0600 (CST) Date: Mon, 17 Nov 2008 01:26:13 -0600 From: Sonny Rao To: Paul Mackerras Subject: Re: [PATCH] Fix BSR to allow mmap of small BSR on 64k kernel Message-ID: <20081117072613.GO16240@us.ibm.com> References: <20081107003841.GE7533@us.ibm.com> <18707.53757.132643.518167@cargo.ozlabs.ibm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <18707.53757.132643.518167@cargo.ozlabs.ibm.com> User-Agent: Mutt/1.5.17+20080114 (2008-01-14) Cc: linuxppc-dev@ozlabs.org X-BeenThere: linuxppc-dev@ozlabs.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org On Fri, Nov 07, 2008 at 04:28:29PM +1100, Paul Mackerras wrote: > Sonny Rao writes: > > > Fix the BSR driver to allow small BSR devices, which are limited to a > > single 4k space, on a 64k page kernel. Previously the driver would > > reject the mmap since the size was smaller than PAGESIZE (or because > > the size was greater than the size of the device). Now, we check for > > this case use remap_4k_pfn(). Also, take out code to set vm_flags, > > as the remap_pfn functions will do this for us. > > Thanks. > > Do we know that the BSR size will always be 4k if it's not a multiple > of 64k? Is it possible that we could get 8k, 16k or 32k or BSRs? > If it is possible, what does the user need to be able to do? Do they > just want to map 4k, or might then want to map the whole thing? Hi Paul, I took a look at changing the driver to reject a request for mapping more than a single 4k page, however the only indication we get of the requested size in the mmap function is the vma size, and this is always one page at minimum. So, it's not possible to determine if the user wants one 4k page or more. As I noted in my first response, there is only one case where this is even possible and I don't think it is a significant concern. I did notice that I left out the check to see if the user is trying to map more than the device length, so I fixed that. Here's the revised patch. -------- Fix the BSR driver to allow small BSR devices on a 64k page kernel. Previously the driver would reject the mmap since the size was smaller than PAGESIZE. This patch adds a check for this case and uses remap_4k_pfn(). Also, take out code to set vm_flags, as the remap_pfn functions will do this for us. Signed-off-by: Sonny Rao Index: linux/drivers/char/bsr.c =================================================================== --- linux.orig/drivers/char/bsr.c 2008-11-17 00:29:23.000000000 -0600 +++ linux/drivers/char/bsr.c 2008-11-17 00:59:57.000000000 -0600 @@ -27,6 +27,7 @@ #include #include #include +#include #include /* @@ -115,15 +116,22 @@ { unsigned long size = vma->vm_end - vma->vm_start; struct bsr_dev *dev = filp->private_data; + int ret; - if (size > dev->bsr_len || (size & (PAGE_SIZE-1))) - return -EINVAL; - - vma->vm_flags |= (VM_IO | VM_DONTEXPAND); vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); - if (io_remap_pfn_range(vma, vma->vm_start, dev->bsr_addr >> PAGE_SHIFT, - size, vma->vm_page_prot)) + /* check for the case of a small BSR device and map one 4k page for it*/ + if (dev->bsr_len < PAGE_SIZE && size == PAGE_SIZE) + ret = remap_4k_pfn(vma, vma->vm_start, dev->bsr_addr >> 12, + vma->vm_page_prot); + else if (size <= dev->bsr_len) + ret = io_remap_pfn_range(vma, vma->vm_start, + dev->bsr_addr >> PAGE_SHIFT, + size, vma->vm_page_prot); + else + return -EINVAL; + + if (ret) return -EAGAIN; return 0;