Author: manu Date: Fri Feb 21 09:28:45 2020 New Revision: 358217 URL: https://svnweb.freebsd.org/changeset/base/358217
Log: linuxkpi: Move shmem related functions in it's own file For drmkpi (D23085) we don't want the Linux struct file as we don't emulate everything. Also the prototypes should be in shmem_fs.h to have 100% compatibility with Linux. Reviewed by: hselasky MFC after: Maybe Differential Revision: https://reviews.freebsd.org/D23764 Added: head/sys/compat/linuxkpi/common/include/linux/shmem_fs.h (contents, props changed) head/sys/compat/linuxkpi/common/src/linux_shmemfs.c (contents, props changed) Modified: head/sys/compat/linuxkpi/common/include/linux/fs.h head/sys/compat/linuxkpi/common/src/linux_page.c head/sys/conf/files head/sys/modules/linuxkpi/Makefile Modified: head/sys/compat/linuxkpi/common/include/linux/fs.h ============================================================================== --- head/sys/compat/linuxkpi/common/include/linux/fs.h Fri Feb 21 09:07:01 2020 (r358216) +++ head/sys/compat/linuxkpi/common/include/linux/fs.h Fri Feb 21 09:28:45 2020 (r358217) @@ -302,25 +302,4 @@ call_mmap(struct linux_file *file, struct vm_area_stru return (file->f_op->mmap(file, vma)); } -/* Shared memory support */ -unsigned long linux_invalidate_mapping_pages(vm_object_t, pgoff_t, pgoff_t); -struct page *linux_shmem_read_mapping_page_gfp(vm_object_t, int, gfp_t); -struct linux_file *linux_shmem_file_setup(const char *, loff_t, unsigned long); -void linux_shmem_truncate_range(vm_object_t, loff_t, loff_t); - -#define invalidate_mapping_pages(...) \ - linux_invalidate_mapping_pages(__VA_ARGS__) - -#define shmem_read_mapping_page(...) \ - linux_shmem_read_mapping_page_gfp(__VA_ARGS__, 0) - -#define shmem_read_mapping_page_gfp(...) \ - linux_shmem_read_mapping_page_gfp(__VA_ARGS__) - -#define shmem_file_setup(...) \ - linux_shmem_file_setup(__VA_ARGS__) - -#define shmem_truncate_range(...) \ - linux_shmem_truncate_range(__VA_ARGS__) - #endif /* _LINUX_FS_H_ */ Added: head/sys/compat/linuxkpi/common/include/linux/shmem_fs.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/compat/linuxkpi/common/include/linux/shmem_fs.h Fri Feb 21 09:28:45 2020 (r358217) @@ -0,0 +1,55 @@ +/*- + * Copyright (c) 2010 Isilon Systems, Inc. + * Copyright (c) 2010 iX Systems, Inc. + * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013-2018 Mellanox Technologies, Ltd. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ +#ifndef _LINUX_SHMEM_FS_H_ +#define _LINUX_SHMEM_FS_H_ + +/* Shared memory support */ +unsigned long linux_invalidate_mapping_pages(vm_object_t, pgoff_t, pgoff_t); +struct page *linux_shmem_read_mapping_page_gfp(vm_object_t, int, gfp_t); +struct linux_file *linux_shmem_file_setup(const char *, loff_t, unsigned long); +void linux_shmem_truncate_range(vm_object_t, loff_t, loff_t); + +#define invalidate_mapping_pages(...) \ + linux_invalidate_mapping_pages(__VA_ARGS__) + +#define shmem_read_mapping_page(...) \ + linux_shmem_read_mapping_page_gfp(__VA_ARGS__, 0) + +#define shmem_read_mapping_page_gfp(...) \ + linux_shmem_read_mapping_page_gfp(__VA_ARGS__) + +#define shmem_file_setup(...) \ + linux_shmem_file_setup(__VA_ARGS__) + +#define shmem_truncate_range(...) \ + linux_shmem_truncate_range(__VA_ARGS__) + +#endif /* _LINUX_SHMEM_FS_H_ */ Modified: head/sys/compat/linuxkpi/common/src/linux_page.c ============================================================================== --- head/sys/compat/linuxkpi/common/src/linux_page.c Fri Feb 21 09:07:01 2020 (r358216) +++ head/sys/compat/linuxkpi/common/src/linux_page.c Fri Feb 21 09:28:45 2020 (r358217) @@ -62,6 +62,7 @@ __FBSDID("$FreeBSD$"); #include <linux/mm.h> #include <linux/preempt.h> #include <linux/fs.h> +#include <linux/shmem_fs.h> void si_meminfo(struct sysinfo *si) @@ -274,87 +275,4 @@ int is_vmalloc_addr(const void *addr) { return (vtoslab((vm_offset_t)addr & ~UMA_SLAB_MASK) != NULL); -} - -struct page * -linux_shmem_read_mapping_page_gfp(vm_object_t obj, int pindex, gfp_t gfp) -{ - vm_page_t page; - int rv; - - if ((gfp & GFP_NOWAIT) != 0) - panic("GFP_NOWAIT is unimplemented"); - - VM_OBJECT_WLOCK(obj); - rv = vm_page_grab_valid(&page, obj, pindex, VM_ALLOC_NORMAL | - VM_ALLOC_NOBUSY | VM_ALLOC_WIRED); - VM_OBJECT_WUNLOCK(obj); - if (rv != VM_PAGER_OK) - return (ERR_PTR(-EINVAL)); - return (page); -} - -struct linux_file * -linux_shmem_file_setup(const char *name, loff_t size, unsigned long flags) -{ - struct fileobj { - struct linux_file file __aligned(sizeof(void *)); - struct vnode vnode __aligned(sizeof(void *)); - }; - struct fileobj *fileobj; - struct linux_file *filp; - struct vnode *vp; - int error; - - fileobj = kzalloc(sizeof(*fileobj), GFP_KERNEL); - if (fileobj == NULL) { - error = -ENOMEM; - goto err_0; - } - filp = &fileobj->file; - vp = &fileobj->vnode; - - filp->f_count = 1; - filp->f_vnode = vp; - filp->f_shmem = vm_pager_allocate(OBJT_DEFAULT, NULL, size, - VM_PROT_READ | VM_PROT_WRITE, 0, curthread->td_ucred); - if (filp->f_shmem == NULL) { - error = -ENOMEM; - goto err_1; - } - return (filp); -err_1: - kfree(filp); -err_0: - return (ERR_PTR(error)); -} - -static vm_ooffset_t -linux_invalidate_mapping_pages_sub(vm_object_t obj, vm_pindex_t start, - vm_pindex_t end, int flags) -{ - int start_count, end_count; - - VM_OBJECT_WLOCK(obj); - start_count = obj->resident_page_count; - vm_object_page_remove(obj, start, end, flags); - end_count = obj->resident_page_count; - VM_OBJECT_WUNLOCK(obj); - return (start_count - end_count); -} - -unsigned long -linux_invalidate_mapping_pages(vm_object_t obj, pgoff_t start, pgoff_t end) -{ - - return (linux_invalidate_mapping_pages_sub(obj, start, end, OBJPR_CLEANONLY)); -} - -void -linux_shmem_truncate_range(vm_object_t obj, loff_t lstart, loff_t lend) -{ - vm_pindex_t start = OFF_TO_IDX(lstart + PAGE_SIZE - 1); - vm_pindex_t end = OFF_TO_IDX(lend + 1); - - (void) linux_invalidate_mapping_pages_sub(obj, start, end, 0); } Added: head/sys/compat/linuxkpi/common/src/linux_shmemfs.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/compat/linuxkpi/common/src/linux_shmemfs.c Fri Feb 21 09:28:45 2020 (r358217) @@ -0,0 +1,128 @@ +/*- + * Copyright (c) 2010 Isilon Systems, Inc. + * Copyright (c) 2016 Matthew Macy (mm...@mattmacy.io) + * Copyright (c) 2017 Mellanox Technologies, Ltd. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/rwlock.h> + +#include <vm/vm.h> +#include <vm/pmap.h> +#include <vm/vm_object.h> +#include <vm/vm_map.h> +#include <vm/vm_page.h> +#include <vm/vm_pager.h> + +#include <linux/fs.h> +#include <linux/mm.h> +#include <linux/shmem_fs.h> + +struct page * +linux_shmem_read_mapping_page_gfp(vm_object_t obj, int pindex, gfp_t gfp) +{ + vm_page_t page; + int rv; + + if ((gfp & GFP_NOWAIT) != 0) + panic("GFP_NOWAIT is unimplemented"); + + VM_OBJECT_WLOCK(obj); + rv = vm_page_grab_valid(&page, obj, pindex, VM_ALLOC_NORMAL | + VM_ALLOC_NOBUSY | VM_ALLOC_WIRED); + VM_OBJECT_WUNLOCK(obj); + if (rv != VM_PAGER_OK) + return (ERR_PTR(-EINVAL)); + return (page); +} + +struct linux_file * +linux_shmem_file_setup(const char *name, loff_t size, unsigned long flags) +{ + struct fileobj { + struct linux_file file __aligned(sizeof(void *)); + struct vnode vnode __aligned(sizeof(void *)); + }; + struct fileobj *fileobj; + struct linux_file *filp; + struct vnode *vp; + int error; + + fileobj = kzalloc(sizeof(*fileobj), GFP_KERNEL); + if (fileobj == NULL) { + error = -ENOMEM; + goto err_0; + } + filp = &fileobj->file; + vp = &fileobj->vnode; + + filp->f_count = 1; + filp->f_vnode = vp; + filp->f_shmem = vm_pager_allocate(OBJT_DEFAULT, NULL, size, + VM_PROT_READ | VM_PROT_WRITE, 0, curthread->td_ucred); + if (filp->f_shmem == NULL) { + error = -ENOMEM; + goto err_1; + } + return (filp); +err_1: + kfree(filp); +err_0: + return (ERR_PTR(error)); +} + +static vm_ooffset_t +linux_invalidate_mapping_pages_sub(vm_object_t obj, vm_pindex_t start, + vm_pindex_t end, int flags) +{ + int start_count, end_count; + + VM_OBJECT_WLOCK(obj); + start_count = obj->resident_page_count; + vm_object_page_remove(obj, start, end, flags); + end_count = obj->resident_page_count; + VM_OBJECT_WUNLOCK(obj); + return (start_count - end_count); +} + +unsigned long +linux_invalidate_mapping_pages(vm_object_t obj, pgoff_t start, pgoff_t end) +{ + + return (linux_invalidate_mapping_pages_sub(obj, start, end, OBJPR_CLEANONLY)); +} + +void +linux_shmem_truncate_range(vm_object_t obj, loff_t lstart, loff_t lend) +{ + vm_pindex_t start = OFF_TO_IDX(lstart + PAGE_SIZE - 1); + vm_pindex_t end = OFF_TO_IDX(lend + 1); + + (void) linux_invalidate_mapping_pages_sub(obj, start, end, 0); +} Modified: head/sys/conf/files ============================================================================== --- head/sys/conf/files Fri Feb 21 09:07:01 2020 (r358216) +++ head/sys/conf/files Fri Feb 21 09:28:45 2020 (r358217) @@ -4476,6 +4476,8 @@ compat/linuxkpi/common/src/linux_rcu.c optional compa compile-with "${LINUXKPI_C} -I$S/contrib/ck/include" compat/linuxkpi/common/src/linux_schedule.c optional compat_linuxkpi \ compile-with "${LINUXKPI_C}" +compat/linuxkpi/common/src/linux_shmemfs.c optional compat_linuxkpi \ + compile-with "${LINUXKPI_C}" compat/linuxkpi/common/src/linux_slab.c optional compat_linuxkpi \ compile-with "${LINUXKPI_C}" compat/linuxkpi/common/src/linux_usb.c optional compat_linuxkpi usb \ Modified: head/sys/modules/linuxkpi/Makefile ============================================================================== --- head/sys/modules/linuxkpi/Makefile Fri Feb 21 09:07:01 2020 (r358216) +++ head/sys/modules/linuxkpi/Makefile Fri Feb 21 09:28:45 2020 (r358217) @@ -15,6 +15,7 @@ SRCS= linux_compat.c \ linux_rcu.c \ linux_seq_file.c \ linux_schedule.c \ + linux_shmemfs.c \ linux_slab.c \ linux_tasklet.c \ linux_usb.c \ _______________________________________________ svn-src-all@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"