svn commit: r322397 - in head/sys/compat/linuxkpi/common: include/linux src
Hans Petter Selasky
hselasky at FreeBSD.org
Fri Aug 11 10:44:42 UTC 2017
Author: hselasky
Date: Fri Aug 11 10:44:40 2017
New Revision: 322397
URL: https://svnweb.freebsd.org/changeset/base/322397
Log:
Make sure the "vm_flags" and "vm_page_prot" fields get set correctly
in the VM area structure in the LinuxKPI when doing mmap() and that
unsupported bits are masked away.
While at it fix some redundant use of parenthesing inside some related
macros.
Found by: KrishnamRaju ErapaRaju <Krishna2 at chelsio.com>
MFC after: 1 week
Sponsored by: Mellanox Technologies
Modified:
head/sys/compat/linuxkpi/common/include/linux/page.h
head/sys/compat/linuxkpi/common/src/linux_compat.c
Modified: head/sys/compat/linuxkpi/common/include/linux/page.h
==============================================================================
--- head/sys/compat/linuxkpi/common/include/linux/page.h Fri Aug 11 10:08:18 2017 (r322396)
+++ head/sys/compat/linuxkpi/common/include/linux/page.h Fri Aug 11 10:44:40 2017 (r322397)
@@ -48,38 +48,36 @@ typedef unsigned long pgprot_t;
#define page vm_page
-#define LINUXKPI_PROT_VALID (1 << 4)
-#define LINUXKPI_CACHE_MODE_SHIFT 3
+#define LINUXKPI_PROT_VALID (1 << 3)
+#define LINUXKPI_CACHE_MODE_SHIFT 4
+CTASSERT((VM_PROT_ALL & -LINUXKPI_PROT_VALID) == 0);
+
static inline pgprot_t
cachemode2protval(vm_memattr_t attr)
{
- return ((attr | LINUXKPI_PROT_VALID) << LINUXKPI_CACHE_MODE_SHIFT);
+ return ((attr << LINUXKPI_CACHE_MODE_SHIFT) | LINUXKPI_PROT_VALID);
}
static inline vm_memattr_t
pgprot2cachemode(pgprot_t prot)
{
- int val;
-
- val = prot >> LINUXKPI_CACHE_MODE_SHIFT;
-
- if (val & LINUXKPI_PROT_VALID)
- return (val & ~LINUXKPI_PROT_VALID);
+ if (prot & LINUXKPI_PROT_VALID)
+ return (prot >> LINUXKPI_CACHE_MODE_SHIFT);
else
return (VM_MEMATTR_DEFAULT);
}
-#define virt_to_page(x) PHYS_TO_VM_PAGE(vtophys((x)))
-#define page_to_pfn(pp) (VM_PAGE_TO_PHYS((pp)) >> PAGE_SHIFT)
+#define virt_to_page(x) PHYS_TO_VM_PAGE(vtophys(x))
+#define page_to_pfn(pp) (VM_PAGE_TO_PHYS(pp) >> PAGE_SHIFT)
#define pfn_to_page(pfn) (PHYS_TO_VM_PAGE((pfn) << PAGE_SHIFT))
-#define nth_page(page,n) pfn_to_page(page_to_pfn((page)) + (n))
+#define nth_page(page,n) pfn_to_page(page_to_pfn(page) + (n))
-#define clear_page(page) memset((page), 0, PAGE_SIZE)
+#define clear_page(page) memset(page, 0, PAGE_SIZE)
#define pgprot_noncached(prot) \
- ((prot) | cachemode2protval(VM_MEMATTR_UNCACHEABLE))
+ (((prot) & VM_PROT_ALL) | cachemode2protval(VM_MEMATTR_UNCACHEABLE))
#define pgprot_writecombine(prot) \
- ((prot) | cachemode2protval(VM_MEMATTR_WRITE_COMBINING))
+ (((prot) & VM_PROT_ALL) | cachemode2protval(VM_MEMATTR_WRITE_COMBINING))
#undef PAGE_MASK
#define PAGE_MASK (~(PAGE_SIZE-1))
Modified: head/sys/compat/linuxkpi/common/src/linux_compat.c
==============================================================================
--- head/sys/compat/linuxkpi/common/src/linux_compat.c Fri Aug 11 10:08:18 2017 (r322396)
+++ head/sys/compat/linuxkpi/common/src/linux_compat.c Fri Aug 11 10:44:40 2017 (r322397)
@@ -1210,7 +1210,7 @@ linux_dev_mmap_single(struct cdev *dev, vm_ooffset_t *
vmap->vm_end = size;
vmap->vm_pgoff = *offset / PAGE_SIZE;
vmap->vm_pfn = 0;
- vmap->vm_flags = vmap->vm_page_prot = nprot;
+ vmap->vm_flags = vmap->vm_page_prot = (nprot & VM_PROT_ALL);
vmap->vm_ops = NULL;
vmap->vm_file = get_file(filp);
vmap->vm_mm = mm;
More information about the svn-src-all
mailing list