From owner-svn-src-all@freebsd.org Fri Sep 11 00:20:16 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A9357A0139F; Fri, 11 Sep 2015 00:20:16 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 98B6319C0; Fri, 11 Sep 2015 00:20:16 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t8B0KGAL082687; Fri, 11 Sep 2015 00:20:16 GMT (envelope-from jhb@FreeBSD.org) Received: (from jhb@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t8B0KGZU082685; Fri, 11 Sep 2015 00:20:16 GMT (envelope-from jhb@FreeBSD.org) Message-Id: <201509110020.t8B0KGZU082685@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jhb set sender to jhb@FreeBSD.org using -f From: John Baldwin Date: Fri, 11 Sep 2015 00:20:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r287637 - in stable: 10/sys/ofed/include/linux 9/sys/ofed/include/linux X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Sep 2015 00:20:16 -0000 Author: jhb Date: Fri Sep 11 00:20:15 2015 New Revision: 287637 URL: https://svnweb.freebsd.org/changeset/base/287637 Log: MFC 287440: Currently the Linux character device mmap handling only supports mmap operations that map a single page that has an associated vm_page_t. This does not permit mapping larger regions (such as a PCI memory BAR) and it does not permit mapping addresses beyond the top of RAM (such as a 64-bit BAR located above the top of RAM). Instead of using a single OBJT_DEVICE object and passing the physaddr via the offset as a hack, create a new sglist and OBJT_SG object for each mmap request. The requested memory attribute is applied to the object thus affecting all pages mapped by the request. Sponsored by: Chelsio Modified: stable/10/sys/ofed/include/linux/linux_compat.c stable/10/sys/ofed/include/linux/mm.h Directory Properties: stable/10/ (props changed) Changes in other areas also in this revision: Modified: stable/9/sys/ofed/include/linux/linux_compat.c stable/9/sys/ofed/include/linux/mm.h Directory Properties: stable/9/sys/ (props changed) Modified: stable/10/sys/ofed/include/linux/linux_compat.c ============================================================================== --- stable/10/sys/ofed/include/linux/linux_compat.c Fri Sep 11 00:19:49 2015 (r287636) +++ stable/10/sys/ofed/include/linux/linux_compat.c Fri Sep 11 00:20:15 2015 (r287637) @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -414,16 +415,6 @@ linux_dev_poll(struct cdev *dev, int eve } static int -linux_dev_mmap(struct cdev *dev, vm_ooffset_t offset, vm_paddr_t *paddr, - int nprot, vm_memattr_t *memattr) -{ - - /* XXX memattr not honored. */ - *paddr = offset; - return (0); -} - -static int linux_dev_mmap_single(struct cdev *dev, vm_ooffset_t *offset, vm_size_t size, struct vm_object **object, int nprot) { @@ -431,36 +422,41 @@ linux_dev_mmap_single(struct cdev *dev, struct linux_file *filp; struct file *file; struct vm_area_struct vma; - vm_paddr_t paddr; - vm_page_t m; int error; file = curthread->td_fpop; ldev = dev->si_drv1; if (ldev == NULL) return (ENODEV); - if (size != PAGE_SIZE) - return (EINVAL); if ((error = devfs_get_cdevpriv((void **)&filp)) != 0) return (error); filp->f_flags = file->f_flag; vma.vm_start = 0; - vma.vm_end = PAGE_SIZE; + vma.vm_end = size; vma.vm_pgoff = *offset / PAGE_SIZE; vma.vm_pfn = 0; vma.vm_page_prot = 0; if (filp->f_op->mmap) { error = -filp->f_op->mmap(filp, &vma); if (error == 0) { - paddr = (vm_paddr_t)vma.vm_pfn << PAGE_SHIFT; - *offset = paddr; - m = PHYS_TO_VM_PAGE(paddr); - *object = vm_pager_allocate(OBJT_DEVICE, dev, - PAGE_SIZE, nprot, *offset, curthread->td_ucred); - if (*object == NULL) - return (EINVAL); - if (vma.vm_page_prot != VM_MEMATTR_DEFAULT) - pmap_page_set_memattr(m, vma.vm_page_prot); + struct sglist *sg; + + sg = sglist_alloc(1, M_WAITOK); + sglist_append_phys(sg, + (vm_paddr_t)vma.vm_pfn << PAGE_SHIFT, vma.vm_len); + *object = vm_pager_allocate(OBJT_SG, sg, vma.vm_len, + nprot, 0, curthread->td_ucred); + if (*object == NULL) { + sglist_free(sg); + return (EINVAL); + } + *offset = 0; + if (vma.vm_page_prot != VM_MEMATTR_DEFAULT) { + VM_OBJECT_WLOCK(*object); + vm_object_set_memattr(*object, + vma.vm_page_prot); + VM_OBJECT_WUNLOCK(*object); + } } } else error = ENODEV; @@ -477,7 +473,6 @@ struct cdevsw linuxcdevsw = { .d_write = linux_dev_write, .d_ioctl = linux_dev_ioctl, .d_mmap_single = linux_dev_mmap_single, - .d_mmap = linux_dev_mmap, .d_poll = linux_dev_poll, }; Modified: stable/10/sys/ofed/include/linux/mm.h ============================================================================== --- stable/10/sys/ofed/include/linux/mm.h Fri Sep 11 00:19:49 2015 (r287636) +++ stable/10/sys/ofed/include/linux/mm.h Fri Sep 11 00:20:15 2015 (r287637) @@ -40,6 +40,7 @@ struct vm_area_struct { vm_offset_t vm_end; vm_offset_t vm_pgoff; vm_paddr_t vm_pfn; /* PFN For mmap. */ + vm_size_t vm_len; /* length for mmap. */ vm_memattr_t vm_page_prot; }; @@ -78,6 +79,7 @@ io_remap_pfn_range(struct vm_area_struct { vma->vm_page_prot = prot; vma->vm_pfn = pfn; + vma->vm_len = size; return (0); }