aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Petter Selasky <hselasky@FreeBSD.org>2021-05-11 18:49:13 +0000
committerHans Petter Selasky <hselasky@FreeBSD.org>2021-06-02 11:25:20 +0000
commit28d95cc69fee30b160418d83bebaf7fddae6058e (patch)
treefdc057d12984da9ec7aa30f0ef9c5a741da342ae
parentfba2292d65e04d3a07eb5d089f511f230d344ac8 (diff)
downloadsrc-28d95cc69fee30b160418d83bebaf7fddae6058e.tar.gz
src-28d95cc69fee30b160418d83bebaf7fddae6058e.zip
Implement read-only VM_SHARED flag in the LinuxKPI.
For use by mmap(2) callbacks. Sponsored by: Mellanox Technologies // NVIDIA Networking (cherry picked from commit 904390b4787d2e4a0d9d8ca9cb0d6da5a4fb320c)
-rw-r--r--sys/compat/linuxkpi/common/include/linux/mm.h1
-rw-r--r--sys/compat/linuxkpi/common/src/linux_compat.c14
2 files changed, 9 insertions, 6 deletions
diff --git a/sys/compat/linuxkpi/common/include/linux/mm.h b/sys/compat/linuxkpi/common/include/linux/mm.h
index f6f53afbc8a9..68a0f34acaf3 100644
--- a/sys/compat/linuxkpi/common/include/linux/mm.h
+++ b/sys/compat/linuxkpi/common/include/linux/mm.h
@@ -63,6 +63,7 @@ CTASSERT((VM_PROT_ALL & -(1 << 8)) == 0);
#define VM_DONTCOPY (1 << 14)
#define VM_DONTEXPAND (1 << 15)
#define VM_DONTDUMP (1 << 16)
+#define VM_SHARED (1 << 17)
#define VMA_MAX_PREFAULT_RECORD 1
diff --git a/sys/compat/linuxkpi/common/src/linux_compat.c b/sys/compat/linuxkpi/common/src/linux_compat.c
index 0fc0ad702788..4337f1f7bbd7 100644
--- a/sys/compat/linuxkpi/common/src/linux_compat.c
+++ b/sys/compat/linuxkpi/common/src/linux_compat.c
@@ -1226,7 +1226,7 @@ linux_file_kqfilter(struct file *file, struct knote *kn)
static int
linux_file_mmap_single(struct file *fp, const struct file_operations *fop,
vm_ooffset_t *offset, vm_size_t size, struct vm_object **object,
- int nprot, struct thread *td)
+ int nprot, bool is_shared, struct thread *td)
{
struct task_struct *task;
struct vm_area_struct *vmap;
@@ -1261,6 +1261,8 @@ linux_file_mmap_single(struct file *fp, const struct file_operations *fop,
vmap->vm_pgoff = *offset / PAGE_SIZE;
vmap->vm_pfn = 0;
vmap->vm_flags = vmap->vm_page_prot = (nprot & VM_PROT_ALL);
+ if (is_shared)
+ vmap->vm_flags |= VM_SHARED;
vmap->vm_ops = NULL;
vmap->vm_file = get_file(filp);
vmap->vm_mm = mm;
@@ -1595,21 +1597,21 @@ linux_file_ioctl(struct file *fp, u_long cmd, void *data, struct ucred *cred,
static int
linux_file_mmap_sub(struct thread *td, vm_size_t objsize, vm_prot_t prot,
- vm_prot_t *maxprotp, int *flagsp, struct file *fp,
+ vm_prot_t maxprot, int flags, struct file *fp,
vm_ooffset_t *foff, const struct file_operations *fop, vm_object_t *objp)
{
/*
* Character devices do not provide private mappings
* of any kind:
*/
- if ((*maxprotp & VM_PROT_WRITE) == 0 &&
+ if ((maxprot & VM_PROT_WRITE) == 0 &&
(prot & VM_PROT_WRITE) != 0)
return (EACCES);
- if ((*flagsp & (MAP_PRIVATE | MAP_COPY)) != 0)
+ if ((flags & (MAP_PRIVATE | MAP_COPY)) != 0)
return (EINVAL);
return (linux_file_mmap_single(fp, fop, foff, objsize, objp,
- (int)prot, td));
+ (int)prot, (flags & MAP_SHARED) ? true : false, td));
}
static int
@@ -1667,7 +1669,7 @@ linux_file_mmap(struct file *fp, vm_map_t map, vm_offset_t *addr, vm_size_t size
maxprot &= cap_maxprot;
linux_get_fop(filp, &fop, &ldev);
- error = linux_file_mmap_sub(td, size, prot, &maxprot, &flags, fp,
+ error = linux_file_mmap_sub(td, size, prot, maxprot, flags, fp,
&foff, fop, &object);
if (error != 0)
goto out;