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@chelsio.com>
MFC after:	1 week
Sponsored by:	Mellanox Technologies
This commit is contained in:
Hans Petter Selasky 2017-08-11 10:44:40 +00:00
parent 0b7bd01a82
commit ebf854802d
2 changed files with 14 additions and 16 deletions

View File

@ -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))

View File

@ -1210,7 +1210,7 @@ linux_dev_mmap_single(struct cdev *dev, vm_ooffset_t *offset,
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;