memfd: add sealing to hugetlb-backed memory
Subsystems (6)
v3 cover memfd: add sealing to hugetlb-backed memory
Hi,
Recently, Mike Kravetz added hugetlbfs support to memfd. However, he didn't add sealing support. One of the reasons to use memfd is to have shared memory sealing when doing IPC or sharing memory with another process with some extra safety. qemu uses shared memory & hugetables with vhost-user (used by dpdk), so it is reasonable to use memfd now instead for convenience and security reasons.
Thanks!
v3:
- do remaining MFD_DEF_SIZE/mfd_def_size substitutions
- fix missing unistd.h include in common.c
- tweaked a bit commit message prefixes
- added reviewed-by tags
v2:
- add "memfd-hugetlb:" prefix in memfd-test
- run fuse test on hugetlb backend memory
- rename function memfd_file_get_seals() -> memfd_file_seals_ptr()
- update commit messages
- added reviewed-by tags
RFC->v1:
- split rfc patch, after early review feedback
- added patch for memfd-test changes
- fix build with hugetlbfs disabled
- small code and commit messages improvements
Marc-AndrA(C) Lureau (9):
shmem: unexport shmem_add_seals()/shmem_get_seals()
shmem: rename functions that are memfd-related
hugetlb: expose hugetlbfs_inode_info in header
hugetlb: implement memfd sealing
shmem: add sealing support to hugetlb-backed memfd
memfd-test: test hugetlbfs sealing
memfd-test: add 'memfd-hugetlb:' prefix when testing hugetlbfs
memfd-test: move common code to a shared unit
memfd-test: run fuse test on hugetlb backend memory
fs/fcntl.c | 2 +- fs/hugetlbfs/inode.c | 39 +++-- include/linux/hugetlb.h | 11 ++ include/linux/shmem_fs.h | 6 +- mm/shmem.c | 59 ++++--- tools/testing/selftests/memfd/Makefile | 5 + tools/testing/selftests/memfd/common.c | 46 ++++++ tools/testing/selftests/memfd/common.h | 9 ++ tools/testing/selftests/memfd/fuse_test.c | 44 +++-- tools/testing/selftests/memfd/memfd_test.c | 212 ++++--------------------- tools/testing/selftests/memfd/run_fuse_test.sh | 2 +- tools/testing/selftests/memfd/run_tests.sh | 1 + 12 files changed, 200 insertions(+), 236 deletions(-) create mode 100644 tools/testing/selftests/memfd/common.c create mode 100644 tools/testing/selftests/memfd/common.h
Signature · 7 lines
2.15.0.125.g8f49766d64 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v3 1/9 shmem: unexport shmem_add_seals()/shmem_get_seals()
The functions are called through shmem_fcntl() only. And no danger in removing the EXPORTs as the routines only work with shmem file structs.
--- include/linux/shmem_fs.h | 2 -- mm/shmem.c | 6 ++---- 2 files changed, 2 insertions(+), 6 deletions(-)
include/linux/shmem_fs.h +0 -2
@@ -110,8 +110,6 @@ extern void shmem_uncharge(struct inode *inode, long pages);#ifdef CONFIG_TMPFS -extern int shmem_add_seals (struct file *file,unsigned int seals); -extern int shmem_get_seals (struct file *file);extern long shmem_fcntl (struct file *file,unsigned int cmd,unsigned long arg);#else
mm/shmem.c +2 -4
@@ -2722,7 +2722,7 @@ static int shmem_wait_for_pins(struct address_space *mapping) F_SEAL_GROW | \ F_SEAL_WRITE) -int shmem_add_seals (struct file *file,unsigned int seals) +static int shmem_add_seals (struct file *file,unsigned int seals) {struct inode *inode =file_inode (file);struct shmem_inode_info *info =SHMEM_I (inode);
@@ -2791,16 +2791,14 @@ int shmem_add_seals(struct file *file, unsigned int seals)inode_unlock (inode);return error; } -EXPORT_SYMBOL_GPL (shmem_add_seals); -int shmem_get_seals (struct file *file) +static int shmem_get_seals (struct file *file) {if (file->f_op != &shmem_file_operations)return -EINVAL ;return SHMEM_I (file_inode (file))->seals; } -EXPORT_SYMBOL_GPL (shmem_get_seals);long shmem_fcntl (struct file *file,unsigned int cmd,unsigned long arg) {
Signature · 7 lines
2.15.0.125.g8f49766d64 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v3 2/9 shmem: rename functions that are memfd-related
In reply to Marc-André LureauThose functions are called for memfd files, backed by shmem or hugetlb (the next patches will handle hugetlb).
--- fs/fcntl.c | 2 +- include/linux/shmem_fs.h | 4 ++-- mm/shmem.c | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-)
fs/fcntl.c +1 -1
@@ -418,7 +418,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,break ;case F_ADD_SEALS :case F_GET_SEALS : - err =shmem_fcntl (filp, cmd, arg); + err =memfd_fcntl (filp, cmd, arg);break ;case F_GET_RW_HINT :case F_SET_RW_HINT :
include/linux/shmem_fs.h +2 -2
@@ -110,11 +110,11 @@ extern void shmem_uncharge(struct inode *inode, long pages);#ifdef CONFIG_TMPFS -extern long shmem_fcntl (struct file *file,unsigned int cmd,unsigned long arg); +extern long memfd_fcntl (struct file *file,unsigned int cmd,unsigned long arg);#else -static inline long shmem_fcntl (struct file *f,unsigned int c,unsigned long a) +static inline long memfd_fcntl (struct file *f,unsigned int c,unsigned long a) {return -EINVAL ; }
mm/shmem.c +5 -5
@@ -2722,7 +2722,7 @@ static int shmem_wait_for_pins(struct address_space *mapping) F_SEAL_GROW | \ F_SEAL_WRITE) -static int shmem_add_seals (struct file *file,unsigned int seals) +static int memfd_add_seals (struct file *file,unsigned int seals) {struct inode *inode =file_inode (file);struct shmem_inode_info *info =SHMEM_I (inode);
@@ -2792,7 +2792,7 @@ static int shmem_add_seals(struct file *file, unsigned int seals)return error; } -static int shmem_get_seals (struct file *file) +static int memfd_get_seals (struct file *file) {if (file->f_op != &shmem_file_operations)return -EINVAL ;
@@ -2800,7 +2800,7 @@ static int shmem_get_seals(struct file *file)return SHMEM_I (file_inode (file))->seals; } -long shmem_fcntl (struct file *file,unsigned int cmd,unsigned long arg) +long memfd_fcntl (struct file *file,unsigned int cmd,unsigned long arg) {long error;
@@ -2810,10 +2810,10 @@ long shmem_fcntl(struct file *file, unsigned int cmd, unsigned long arg)if (arg >UINT_MAX )return -EINVAL ; - error =shmem_add_seals (file, arg); + error =memfd_add_seals (file, arg);break ;case F_GET_SEALS : - error =shmem_get_seals (file); + error =memfd_get_seals (file);break ;default : error = -EINVAL ;
Signature · 7 lines
2.15.0.125.g8f49766d64 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v3 3/9 hugetlb: expose hugetlbfs_inode_info in header
In reply to Marc-André Lureauhugetlbfs inode information will need to be accessed by code in mm/shmem.c for file sealing operations. Move inode information definition from .c file to header for needed access.
--- fs/hugetlbfs/inode.c | 10 ---------- include/linux/hugetlb.h | 10 ++++++++++ 2 files changed, 10 insertions(+), 10 deletions(-)
fs/hugetlbfs/inode.c +0 -10
@@ -55,16 +55,6 @@ struct hugetlbfs_config {umode_t mode; }; -struct hugetlbfs_inode_info { -struct shared_policy policy; -struct inode vfs_inode; -}; - -static inline struct hugetlbfs_inode_info *HUGETLBFS_I (struct inode *inode) -{ - return container_of(inode, struct hugetlbfs_inode_info, vfs_inode); -} -int sysctl_hugetlb_shm_group;enum {
include/linux/hugetlb.h +10 -0
@@ -279,6 +279,16 @@ static inline struct hugetlbfs_sb_info *HUGETLBFS_SB(struct super_block *sb)return sb->s_fs_info; } +struct hugetlbfs_inode_info { +struct shared_policy policy; +struct inode vfs_inode; +}; + +static inline struct hugetlbfs_inode_info *HUGETLBFS_I (struct inode *inode) +{ + return container_of(inode, struct hugetlbfs_inode_info, vfs_inode); +} +extern const struct file_operations hugetlbfs_file_operations;extern const struct vm_operations_struct hugetlb_vm_ops; struct file *hugetlb_file_setup(const char *name, size_t size, vm_flags_t acct,
Signature · 7 lines
2.15.0.125.g8f49766d64 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v3 4/9 hugetlb: implement memfd sealing
In reply to Marc-André LureauImplements memfd sealing, similar to shmem:
- WRITE: deny fallocate(PUNCH_HOLE). mmap() write is denied in memfd_add_seals(). write() doesn't exist for hugetlbfs.
- SHRINK: added similar check as shmem_setattr()
- GROW: added similar check as shmem_setattr() & shmem_fallocate()
Except write() operation that doesn't exist with hugetlbfs, that should make sealing as close as it can be to shmem support.
--- fs/hugetlbfs/inode.c | 29 +++++++++++++++++++++++++++-- include/linux/hugetlb.h | 1 + 2 files changed, 28 insertions(+), 2 deletions(-)
fs/hugetlbfs/inode.c +27 -2
@@ -510,8 +510,16 @@ static long hugetlbfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)if (hole_end > hole_start) {struct address_space *mapping = inode->i_mapping; +struct hugetlbfs_inode_info *info =HUGETLBFS_I (inode);inode_lock (inode); + +/* protected by i_mutex */ +if (info->seals &F_SEAL_WRITE ) { +inode_unlock (inode); +return -EPERM ; + } +i_mmap_lock_write (mapping);if (!RB_EMPTY_ROOT (&mapping->i_mmap.rb_root)) hugetlb_vmdelete_list(&mapping->i_mmap,
@@ -529,6 +537,7 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len) {struct inode *inode =file_inode (file); +struct hugetlbfs_inode_info *info =HUGETLBFS_I (inode);struct address_space *mapping = inode->i_mapping;struct hstate *h =hstate_inode (inode);struct vm_area_struct pseudo_vma;
@@ -560,6 +569,11 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset,if (error) goto out; +if ((info->seals &F_SEAL_GROW ) && offset + len > inode->i_size) { + error = -EPERM ; + goto out; + } +/* * Initialize a pseudo vma as this is required by the huge page * allocation routines. If NUMA is configured, use page index
@@ -650,6 +664,7 @@ static int hugetlbfs_setattr(struct dentry *dentry, struct iattr *attr)struct hstate *h =hstate_inode (inode);int error;unsigned int ia_valid = attr->ia_valid; +struct hugetlbfs_inode_info *info =HUGETLBFS_I (inode);BUG_ON (!inode);
@@ -658,10 +673,17 @@ static int hugetlbfs_setattr(struct dentry *dentry, struct iattr *attr)return error;if (ia_valid &ATTR_SIZE ) { +loff_t oldsize = inode->i_size; +loff_t newsize = attr->ia_size; + error = -EINVAL ; -if (attr->ia_size & ~huge_page_mask (h)) +if (newsize & ~huge_page_mask (h))return -EINVAL ; - error =hugetlb_vmtruncate (inode, attr->ia_size); +/* protected by i_mutex */ +if ((newsize < oldsize && (info->seals &F_SEAL_SHRINK )) || + (newsize > oldsize && (info->seals &F_SEAL_GROW ))) +return -EPERM ; + error =hugetlb_vmtruncate (inode, newsize);if (error)return error; }
@@ -713,6 +735,8 @@ static struct inode *hugetlbfs_get_inode(struct super_block *sb, inode =new_inode (sb);if (inode) { +struct hugetlbfs_inode_info *info =HUGETLBFS_I (inode); + inode->i_ino =get_next_ino ();inode_init_owner (inode, dir, mode); lockdep_set_class(&inode->i_mapping->i_mmap_rwsem,
@@ -720,6 +744,7 @@ static struct inode *hugetlbfs_get_inode(struct super_block *sb, inode->i_mapping->a_ops = &hugetlbfs_aops; inode->i_atime = inode->i_mtime = inode->i_ctime =current_time (inode); inode->i_mapping->private_data = resv_map; + info->seals =F_SEAL_SEAL ;switch (mode &S_IFMT ) {default :init_special_inode (inode, mode, dev);
include/linux/hugetlb.h +1 -0
@@ -282,6 +282,7 @@ static inline struct hugetlbfs_sb_info *HUGETLBFS_SB(struct super_block *sb)struct hugetlbfs_inode_info {struct shared_policy policy;struct inode vfs_inode; +unsigned int seals; };static inline struct hugetlbfs_inode_info *HUGETLBFS_I (struct inode *inode)
Signature · 7 lines
2.15.0.125.g8f49766d64 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v3 5/9 shmem: add sealing support to hugetlb-backed memfd
In reply to Marc-André LureauAdapt add_seals()/get_seals() to work with hugetbfs-backed memory.
Teach memfd_create() to allow sealing operations on MFD_HUGETLB.
--- mm/shmem.c | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-)
mm/shmem.c +28 -19
@@ -2717,6 +2717,19 @@ static int shmem_wait_for_pins(struct address_space *mapping)return error; } +static unsigned int *memfd_file_seals_ptr (struct file *file) +{ +if (file->f_op == &shmem_file_operations) +return &SHMEM_I (file_inode (file))->seals; + +#ifdef CONFIG_HUGETLBFS +if (file->f_op == &hugetlbfs_file_operations) +return &HUGETLBFS_I (file_inode (file))->seals; +#endif + +return NULL ; +} +#define F_ALL_SEALS (F_SEAL_SEAL | \ F_SEAL_SHRINK | \ F_SEAL_GROW | \
@@ -2725,7 +2738,7 @@ static int shmem_wait_for_pins(struct address_space *mapping)static int memfd_add_seals (struct file *file,unsigned int seals) {struct inode *inode =file_inode (file); -struct shmem_inode_info *info =SHMEM_I (inode); +unsigned int *file_seals;int error;/*
@@ -2758,8 +2771,6 @@ static int memfd_add_seals(struct file *file, unsigned int seals)* other file types. */ -if (file->f_op != &shmem_file_operations) -return -EINVAL ;if (!(file->f_mode &FMODE_WRITE ))return -EPERM ;if (seals & ~(unsigned int )F_ALL_SEALS )
@@ -2767,12 +2778,18 @@ static int memfd_add_seals(struct file *file, unsigned int seals)inode_lock (inode); -if (info->seals &F_SEAL_SEAL ) { + file_seals =memfd_file_seals_ptr (file); +if (!file_seals) { + error = -EINVAL ; + goto unlock; + } + +if (*file_seals &F_SEAL_SEAL ) { error = -EPERM ; goto unlock; } -if ((seals &F_SEAL_WRITE ) && !(info->seals &F_SEAL_WRITE )) { +if ((seals &F_SEAL_WRITE ) && !(*file_seals &F_SEAL_WRITE )) { error =mapping_deny_writable (file->f_mapping);if (error) goto unlock;
@@ -2784,7 +2801,7 @@ static int memfd_add_seals(struct file *file, unsigned int seals) } } - info->seals |= seals; + *file_seals |= seals; error =0 ; unlock:
@@ -2794,10 +2811,9 @@ static int memfd_add_seals(struct file *file, unsigned int seals)static int memfd_get_seals (struct file *file) { -if (file->f_op != &shmem_file_operations) -return -EINVAL ; +unsigned int *seals =memfd_file_seals_ptr (file); -return SHMEM_I (file_inode (file))->seals; +return seals ? *seals : -EINVAL ; }long memfd_fcntl (struct file *file,unsigned int cmd,unsigned long arg)
@@ -3657,7 +3673,7 @@ SYSCALL_DEFINE2(memfd_create, const char __user *, uname, unsigned int, flags) { - struct shmem_inode_info *info; + unsigned int *file_seals;struct file *file;int fd, error;char *name;
@@ -3667,9 +3683,6 @@ SYSCALL_DEFINE2(memfd_create,if (flags & ~(unsigned int )MFD_ALL_FLAGS )return -EINVAL ; }else { -/* Sealing not supported in hugetlbfs (MFD_HUGETLB) */ -if (flags &MFD_ALLOW_SEALING ) -return -EINVAL ;/* Allow huge page size encoding in flags. */ if (flags & ~(unsigned int )(MFD_ALL_FLAGS | (MFD_HUGE_MASK <<MFD_HUGE_SHIFT )))
@@ -3722,12 +3735,8 @@ SYSCALL_DEFINE2(memfd_create, file->f_flags |=O_RDWR |O_LARGEFILE ;if (flags &MFD_ALLOW_SEALING ) { -/* -* flags check at beginning of function ensures -* this is not a hugetlbfs (MFD_HUGETLB) file. -*/ - info =SHMEM_I (file_inode (file)); - info->seals &= ~F_SEAL_SEAL ; + file_seals =memfd_file_seals_ptr (file); + *file_seals &= ~F_SEAL_SEAL ; }fd_install (fd, file);
Signature · 7 lines
2.15.0.125.g8f49766d64 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v3 6/9 memfd-test: test hugetlbfs sealing
In reply to Marc-André LureauRemove most of the special-casing of hugetlbfs now that sealing is supported.
--- tools/testing/selftests/memfd/memfd_test.c | 150 +++-------------------------- 1 file changed, 15 insertions(+), 135 deletions(-)
tools/testing/selftests/memfd/memfd_test.c +15 -135
@@ -513,6 +513,10 @@ static void mfd_assert_grow_write(int fd)static char *buf;ssize_t l; +/* hugetlbfs does not support write */ +if (hugetlbfs_test) +return ; + buf =malloc (mfd_def_size *8 );if (!buf) {printf ("malloc(%d) failed: %m\n" , mfd_def_size *8 );
@@ -533,6 +537,10 @@ static void mfd_fail_grow_write(int fd)static char *buf;ssize_t l; +/* hugetlbfs does not support write */ +if (hugetlbfs_test) +return ; + buf =malloc (mfd_def_size *8 );if (!buf) {printf ("malloc(%d) failed: %m\n" , mfd_def_size *8 );
@@ -627,18 +635,13 @@ static void test_create(void) fd =mfd_assert_new ("" ,0 ,MFD_CLOEXEC );close (fd); -if (!hugetlbfs_test) { -/* verify MFD_ALLOW_SEALING is allowed */ - fd =mfd_assert_new ("" ,0 ,MFD_ALLOW_SEALING ); -close (fd); - -/* verify MFD_ALLOW_SEALING | MFD_CLOEXEC is allowed */ - fd =mfd_assert_new ("" ,0 ,MFD_ALLOW_SEALING |MFD_CLOEXEC ); -close (fd); - }else { -/* sealing is not supported on hugetlbfs */ -mfd_fail_new ("" ,MFD_ALLOW_SEALING ); - } +/* verify MFD_ALLOW_SEALING is allowed */ + fd =mfd_assert_new ("" ,0 ,MFD_ALLOW_SEALING ); +close (fd); + +/* verify MFD_ALLOW_SEALING | MFD_CLOEXEC is allowed */ + fd =mfd_assert_new ("" ,0 ,MFD_ALLOW_SEALING |MFD_CLOEXEC ); +close (fd); }/*
@@ -649,10 +652,6 @@ static void test_basic(void) {int fd; -/* hugetlbfs does not contain sealing support */ -if (hugetlbfs_test) -return ; -printf ("%s BASIC\n" ,MEMFD_STR ); fd = mfd_assert_new("kern_memfd_basic",
@@ -697,28 +696,6 @@ static void test_basic(void)close (fd); } -/* -* hugetlbfs doesn't support seals or write, so just verify grow and shrink -* on a hugetlbfs file created via memfd_create. -*/ -static void test_hugetlbfs_grow_shrink (void ) -{ -int fd; - -printf ("%s HUGETLBFS-GROW-SHRINK\n" ,MEMFD_STR ); - - fd =mfd_assert_new ("kern_memfd_seal_write" , - mfd_def_size, -MFD_CLOEXEC ); - -mfd_assert_read (fd); -mfd_assert_write (fd); -mfd_assert_shrink (fd); -mfd_assert_grow (fd); - -close (fd); -} -/* * Test SEAL_WRITE * Test whether SEAL_WRITE actually prevents modifications.
@@ -727,13 +704,6 @@ static void test_seal_write(void) {int fd; -/* -* hugetlbfs does not contain sealing or write support. Just test -* basic grow and shrink via test_hugetlbfs_grow_shrink. -*/ -if (hugetlbfs_test) -return test_hugetlbfs_grow_shrink (); -printf ("%s SEAL-WRITE\n" ,MEMFD_STR ); fd = mfd_assert_new("kern_memfd_seal_write",
@@ -760,10 +730,6 @@ static void test_seal_shrink(void) {int fd; -/* hugetlbfs does not contain sealing support */ -if (hugetlbfs_test) -return ; -printf ("%s SEAL-SHRINK\n" ,MEMFD_STR ); fd = mfd_assert_new("kern_memfd_seal_shrink",
@@ -790,10 +756,6 @@ static void test_seal_grow(void) {int fd; -/* hugetlbfs does not contain sealing support */ -if (hugetlbfs_test) -return ; -printf ("%s SEAL-GROW\n" ,MEMFD_STR ); fd = mfd_assert_new("kern_memfd_seal_grow",
@@ -820,10 +782,6 @@ static void test_seal_resize(void) {int fd; -/* hugetlbfs does not contain sealing support */ -if (hugetlbfs_test) -return ; -printf ("%s SEAL-RESIZE\n" ,MEMFD_STR ); fd = mfd_assert_new("kern_memfd_seal_resize",
@@ -842,32 +800,6 @@ static void test_seal_resize(void)close (fd); } -/* -* hugetlbfs does not support seals. Basic test to dup the memfd created -* fd and perform some basic operations on it. -*/ -static void hugetlbfs_dup (char *b_suffix) -{ -int fd, fd2; - -printf ("%s HUGETLBFS-DUP %s\n" ,MEMFD_STR , b_suffix); - - fd =mfd_assert_new ("kern_memfd_share_dup" , - mfd_def_size, -MFD_CLOEXEC ); - - fd2 =mfd_assert_dup (fd); - -mfd_assert_read (fd); -mfd_assert_write (fd); - -mfd_assert_shrink (fd2); -mfd_assert_grow (fd2); - -close (fd2); -close (fd); -} -/* * Test sharing via dup() * Test that seals are shared between dupped FDs and they're all equal.
@@ -876,15 +808,6 @@ static void test_share_dup(char *banner, char *b_suffix) {int fd, fd2; -/* -* hugetlbfs does not contain sealing support. Perform some -* basic testing on dup'ed fd instead via hugetlbfs_dup. -*/ -if (hugetlbfs_test) { -hugetlbfs_dup (b_suffix); -return ; - } -printf ("%s %s %s\n" ,MEMFD_STR , banner, b_suffix); fd = mfd_assert_new("kern_memfd_share_dup",
@@ -927,10 +850,6 @@ static void test_share_mmap(char *banner, char *b_suffix)int fd;void *p; -/* hugetlbfs does not contain sealing support */ -if (hugetlbfs_test) -return ; -printf ("%s %s %s\n" ,MEMFD_STR , banner, b_suffix); fd = mfd_assert_new("kern_memfd_share_mmap",
@@ -955,32 +874,6 @@ static void test_share_mmap(char *banner, char *b_suffix)close (fd); } -/* -* Basic test to make sure we can open the hugetlbfs fd via /proc and -* perform some simple operations on it. -*/ -static void hugetlbfs_proc_open (char *b_suffix) -{ -int fd, fd2; - -printf ("%s HUGETLBFS-PROC-OPEN %s\n" ,MEMFD_STR , b_suffix); - - fd =mfd_assert_new ("kern_memfd_share_open" , - mfd_def_size, -MFD_CLOEXEC ); - - fd2 =mfd_assert_open (fd,O_RDWR ,0 ); - -mfd_assert_read (fd); -mfd_assert_write (fd); - -mfd_assert_shrink (fd2); -mfd_assert_grow (fd2); - -close (fd2); -close (fd); -} -/* * Test sealing with open(/proc/self/fd/%d) * Via /proc we can get access to a separate file-context for the same memfd.
@@ -991,15 +884,6 @@ static void test_share_open(char *banner, char *b_suffix) {int fd, fd2; -/* -* hugetlbfs does not contain sealing support. So test basic -* functionality of using /proc fd via hugetlbfs_proc_open -*/ -if (hugetlbfs_test) { -hugetlbfs_proc_open (b_suffix); -return ; - } -printf ("%s %s %s\n" ,MEMFD_STR , banner, b_suffix); fd = mfd_assert_new("kern_memfd_share_open",
@@ -1043,10 +927,6 @@ static void test_share_fork(char *banner, char *b_suffix)int fd;pid_t pid; -/* hugetlbfs does not contain sealing support */ -if (hugetlbfs_test) -return ; -printf ("%s %s %s\n" ,MEMFD_STR , banner, b_suffix); fd = mfd_assert_new("kern_memfd_share_fork",
Signature · 7 lines
2.15.0.125.g8f49766d64 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v3 7/9 memfd-test: add 'memfd-hugetlb:' prefix when testing hugetlbfs
In reply to Marc-André Lureau--- tools/testing/selftests/memfd/memfd_test.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-)
tools/testing/selftests/memfd/memfd_test.c +16 -10
@@ -20,6 +20,7 @@#include <unistd.h> #define MEMFD_STR "memfd:" +#define MEMFD_HUGE_STR "memfd-hugetlb:"#define SHARED_FT_STR "(shared file-table)"#define MFD_DEF_SIZE 8192
@@ -30,6 +31,7 @@*/ static int hugetlbfs_test;static size_t mfd_def_size =MFD_DEF_SIZE ; +static const char *memfd_str =MEMFD_STR ;/* * Copied from mlock2-tests.c
@@ -606,7 +608,7 @@ static void test_create(void)char buf[2048 ];int fd; -printf ("%s CREATE\n" ,MEMFD_STR ); +printf ("%s CREATE\n" , memfd_str);/* test NULL name */ mfd_fail_new (NULL ,0 );
@@ -652,7 +654,7 @@ static void test_basic(void) {int fd; -printf ("%s BASIC\n" ,MEMFD_STR ); +printf ("%s BASIC\n" , memfd_str); fd = mfd_assert_new("kern_memfd_basic", mfd_def_size,
@@ -704,7 +706,7 @@ static void test_seal_write(void) {int fd; -printf ("%s SEAL-WRITE\n" ,MEMFD_STR ); +printf ("%s SEAL-WRITE\n" , memfd_str); fd = mfd_assert_new("kern_memfd_seal_write", mfd_def_size,
@@ -730,7 +732,7 @@ static void test_seal_shrink(void) {int fd; -printf ("%s SEAL-SHRINK\n" ,MEMFD_STR ); +printf ("%s SEAL-SHRINK\n" , memfd_str); fd = mfd_assert_new("kern_memfd_seal_shrink", mfd_def_size,
@@ -756,7 +758,7 @@ static void test_seal_grow(void) {int fd; -printf ("%s SEAL-GROW\n" ,MEMFD_STR ); +printf ("%s SEAL-GROW\n" , memfd_str); fd = mfd_assert_new("kern_memfd_seal_grow", mfd_def_size,
@@ -782,7 +784,7 @@ static void test_seal_resize(void) {int fd; -printf ("%s SEAL-RESIZE\n" ,MEMFD_STR ); +printf ("%s SEAL-RESIZE\n" , memfd_str); fd = mfd_assert_new("kern_memfd_seal_resize", mfd_def_size,
@@ -808,7 +810,7 @@ static void test_share_dup(char *banner, char *b_suffix) {int fd, fd2; -printf ("%s %s %s\n" ,MEMFD_STR , banner, b_suffix); +printf ("%s %s %s\n" , memfd_str, banner, b_suffix); fd = mfd_assert_new("kern_memfd_share_dup", mfd_def_size,
@@ -850,7 +852,7 @@ static void test_share_mmap(char *banner, char *b_suffix)int fd;void *p; -printf ("%s %s %s\n" ,MEMFD_STR , banner, b_suffix); +printf ("%s %s %s\n" , memfd_str, banner, b_suffix); fd = mfd_assert_new("kern_memfd_share_mmap", mfd_def_size,
@@ -884,7 +886,7 @@ static void test_share_open(char *banner, char *b_suffix) {int fd, fd2; -printf ("%s %s %s\n" ,MEMFD_STR , banner, b_suffix); +printf ("%s %s %s\n" , memfd_str, banner, b_suffix); fd = mfd_assert_new("kern_memfd_share_open", mfd_def_size,
@@ -927,7 +929,7 @@ static void test_share_fork(char *banner, char *b_suffix)int fd;pid_t pid; -printf ("%s %s %s\n" ,MEMFD_STR , banner, b_suffix); +printf ("%s %s %s\n" , memfd_str, banner, b_suffix); fd = mfd_assert_new("kern_memfd_share_fork", mfd_def_size,
@@ -963,7 +965,11 @@ int main(int argc, char **argv) } hugetlbfs_test =1 ; + memfd_str =MEMFD_HUGE_STR ; mfd_def_size = hpage_size *2 ; + }else { +printf ("Unknown option: %s\n" , argv[1 ]); +abort (); } }
Signature · 7 lines
2.15.0.125.g8f49766d64 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v3 8/9 memfd-test: move common code to a shared unit
In reply to Marc-André LureauThe memfd & fuse tests will share more common code in the following commits to test hugetlb support.
--- tools/testing/selftests/memfd/Makefile | 5 ++++ tools/testing/selftests/memfd/common.c | 46 ++++++++++++++++++++++++++++++ tools/testing/selftests/memfd/common.h | 9 ++++++ tools/testing/selftests/memfd/fuse_test.c | 8 ++---- tools/testing/selftests/memfd/memfd_test.c | 36 ++--------------------- 5 files changed, 64 insertions(+), 40 deletions(-) create mode 100644 tools/testing/selftests/memfd/common.c create mode 100644 tools/testing/selftests/memfd/common.h
tools/testing/selftests/memfd/Makefile +5 -0
@@ -12,3 +12,8 @@ fuse_mnt.o: CFLAGS += $(shell pkg-config fuse --cflags) include ../lib.mk $(OUTPUT)/fuse_mnt: LDLIBS += $(shell pkg-config fuse --libs) + +$(OUTPUT)/memfd_test: memfd_test.c common.o +$(OUTPUT)/fuse_test: fuse_test.c common.o + +EXTRA_CLEAN = common.o
tools/testing/selftests/memfd/common.c new file +46 -0
46 lines not on this page · raw message
tools/testing/selftests/memfd/common.h new file +9 -0
@@ -0,0 +1,9 @@ +#ifndef COMMON_H_ +#define COMMON_H_ + +extern int hugetlbfs_test; + +unsigned long default_huge_page_size (void ); +int sys_memfd_create (const char *name,unsigned int flags); + +#endif
tools/testing/selftests/memfd/fuse_test.c +2 -6
@@ -33,15 +33,11 @@#include <sys/wait.h> #include <unistd.h> +#include "common.h" +#define MFD_DEF_SIZE 8192#define STACK_SIZE 65536 -static int sys_memfd_create (const char *name, -unsigned int flags) -{ -return syscall (__NR_memfd_create, name, flags); -} -static int mfd_assert_new (const char *name,loff_t sz,unsigned int flags) {int r, fd;
tools/testing/selftests/memfd/memfd_test.c +2 -34
@@ -19,6 +19,8 @@#include <sys/wait.h> #include <unistd.h> +#include "common.h" +#define MEMFD_STR "memfd:"#define MEMFD_HUGE_STR "memfd-hugetlb:"#define SHARED_FT_STR "(shared file-table)"
@@ -29,43 +31,9 @@/* * Default is not to test hugetlbfs */ -static int hugetlbfs_test;static size_t mfd_def_size =MFD_DEF_SIZE ;static const char *memfd_str =MEMFD_STR ; -/* -* Copied from mlock2-tests.c -*/ -static unsigned long default_huge_page_size (void ) -{ -unsigned long hps =0 ; -char *line =NULL ; -size_t linelen =0 ; -FILE *f =fopen ("/proc/meminfo" ,"r" ); - -if (!f) -return 0 ; -while (getline (&line, &linelen, f) >0 ) { -if (sscanf (line,"Hugepagesize: %lu kB" , &hps) ==1 ) { - hps <<=10 ; -break ; - } - } - -free (line); -fclose (f); -return hps; -} - -static int sys_memfd_create (const char *name, -unsigned int flags) -{ -if (hugetlbfs_test) - flags |=MFD_HUGETLB ; - -return syscall (__NR_memfd_create, name, flags); -} -static int mfd_assert_new (const char *name,loff_t sz,unsigned int flags) {int r, fd;
Signature · 7 lines
2.15.0.125.g8f49766d64 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v3 9/9 memfd-test: run fuse test on hugetlb backend memory
In reply to Marc-André Lureau--- tools/testing/selftests/memfd/fuse_test.c | 38 ++++++++++++++++++++------ tools/testing/selftests/memfd/run_fuse_test.sh | 2 +- tools/testing/selftests/memfd/run_tests.sh | 1 + 3 files changed, 32 insertions(+), 9 deletions(-)
tools/testing/selftests/memfd/fuse_test.c +30 -8
@@ -38,6 +38,8 @@#define MFD_DEF_SIZE 8192#define STACK_SIZE 65536 +static size_t mfd_def_size =MFD_DEF_SIZE ; +static int mfd_assert_new (const char *name,loff_t sz,unsigned int flags) {int r, fd;
@@ -123,7 +125,7 @@ static void *mfd_assert_mmap_shared(int fd)void *p; p = mmap(NULL, - MFD_DEF_SIZE, + mfd_def_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd,
@@ -141,7 +143,7 @@ static void *mfd_assert_mmap_private(int fd)void *p; p = mmap(NULL, - MFD_DEF_SIZE, + mfd_def_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd,
@@ -174,7 +176,7 @@ static int sealing_thread_fn(void *arg)usleep (200000 );/* unmount mapping before sealing to avoid i_mmap_writable failures */ -munmap (global_p,MFD_DEF_SIZE ); +munmap (global_p, mfd_def_size);/* Try sealing the global file; expect EBUSY or success. Current * kernels will never succeed, but in the future, kernels might
@@ -224,7 +226,7 @@ static void join_sealing_thread(pid_t pid)int main (int argc,char **argv) { -static const char zero[MFD_DEF_SIZE ]; +char *zero;int fd, mfd, r;void *p;int was_sealed;
@@ -235,6 +237,25 @@ int main(int argc, char **argv)abort (); } +if (argc >=3 ) { +if (!strcmp (argv[2 ],"hugetlbfs" )) { +unsigned long hpage_size =default_huge_page_size (); + +if (!hpage_size) { +printf ("Unable to determine huge page size\n" ); +abort (); + } + + hugetlbfs_test =1 ; + mfd_def_size = hpage_size *2 ; + }else { +printf ("Unknown option: %s\n" , argv[2 ]); +abort (); + } + } + + zero =calloc (sizeof (*zero), mfd_def_size); +/* open FUSE memfd file for GUP testing */ printf ("opening: %s\n" , argv[1 ]); fd =open (argv[1 ],O_RDONLY |O_CLOEXEC );
@@ -245,7 +266,7 @@ int main(int argc, char **argv)/* create new memfd-object */ mfd =mfd_assert_new ("kern_memfd_fuse" , -MFD_DEF_SIZE , + mfd_def_size,MFD_CLOEXEC |MFD_ALLOW_SEALING );/* mmap memfd-object for writing */
@@ -264,7 +285,7 @@ int main(int argc, char **argv)* This guarantees that the receive-buffer is pinned for 1s until the * data is written into it. The racing ADD_SEALS should thus fail as * the pages are still pinned. */ - r =read (fd, p,MFD_DEF_SIZE ); + r =read (fd, p, mfd_def_size);if (r <0 ) {printf ("read() failed: %m\n" );abort ();
@@ -291,10 +312,10 @@ int main(int argc, char **argv)* enough to avoid any in-flight writes. */ p =mfd_assert_mmap_private (mfd); -if (was_sealed &&memcmp (p, zero,MFD_DEF_SIZE )) { +if (was_sealed &&memcmp (p, zero, mfd_def_size)) {printf ("memfd sealed during read() but data not discarded\n" );abort (); - }else if (!was_sealed && !memcmp (p, zero,MFD_DEF_SIZE )) { + }else if (!was_sealed && !memcmp (p, zero, mfd_def_size)) {printf ("memfd sealed after read() but data discarded\n" );abort (); }
@@ -303,6 +324,7 @@ int main(int argc, char **argv)close (fd);printf ("fuse: DONE\n" ); +free (zero);return 0 ; }
tools/testing/selftests/memfd/run_fuse_test.sh +1 -1
@@ -10,6 +10,6 @@ set -e mkdir mnt ./fuse_mnt ./mnt -./fuse_test ./mnt/memfd +./fuse_test ./mnt/memfd $@ fusermount -u ./mnt rmdir ./mnt
tools/testing/selftests/memfd/run_tests.sh +1 -0
@@ -60,6 +60,7 @@ fi # Run the hugetlbfs test # ./memfd_test hugetlbfs +./run_fuse_test.sh hugetlbfs # # Give back any huge pages allocated for the test
Signature · 7 lines
2.15.0.125.g8f49766d64 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v3 9/9] memfd-test: run fuse test on hugetlb backend memory
Quoted 2 lines · Marc-AndrA(C) Lureau
Suggested-by Mike Kravetz <[email protected]>Signed-off-by Marc-AndrA(C) Lureau <[email protected]>
Signature · 1 line
Mike Kravetz
Quoted 138 lines
--- tools/testing/selftests/memfd/fuse_test.c | 38 ++++++++++++++++++++------ tools/testing/selftests/memfd/run_fuse_test.sh | 2 +- tools/testing/selftests/memfd/run_tests.sh | 1 + 3 files changed, 32 insertions(+), 9 deletions(-)tools/testing/selftests/memfd/fuse_test.c +30
-8@@ -38,6 +38,8 @@#define MFD_DEF_SIZE 8192#define STACK_SIZE 65536 +static size_t mfd_def_size =MFD_DEF_SIZE ; +static int mfd_assert_new (const char *name,loff_t sz,unsigned int flags) {int r, fd;@@ -123,7 +125,7 @@ static void *mfd_assert_mmap_shared(int fd)void *p; p = mmap(NULL, - MFD_DEF_SIZE, + mfd_def_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd,@@ -141,7 +143,7 @@ static void *mfd_assert_mmap_private(int fd)void *p; p = mmap(NULL, - MFD_DEF_SIZE, + mfd_def_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd,@@ -174,7 +176,7 @@ static int sealing_thread_fn(void *arg)usleep (200000 );/* unmount mapping before sealing to avoid i_mmap_writable failures */ -munmap (global_p,MFD_DEF_SIZE ); +munmap (global_p, mfd_def_size);/* Try sealing the global file; expect EBUSY or success. Current * kernels will never succeed, but in the future, kernels might @@ -224,7 +226,7 @@ static void join_sealing_thread(pid_t pid)int main (int argc,char **argv) { -static const char zero[MFD_DEF_SIZE ]; +char *zero;int fd, mfd, r;void *p;int was_sealed;@@ -235,6 +237,25 @@ int main(int argc, char **argv)abort (); } +if (argc >=3 ) { +if (!strcmp (argv[2 ],"hugetlbfs" )) { +unsigned long hpage_size =default_huge_page_size (); + +if (!hpage_size) { +printf ("Unable to determine huge page size\n" ); +abort (); + } + + hugetlbfs_test =1 ; + mfd_def_size = hpage_size *2 ; + }else { +printf ("Unknown option: %s\n" , argv[2 ]); +abort (); + } + } + + zero =calloc (sizeof (*zero), mfd_def_size); +/* open FUSE memfd file for GUP testing */ printf ("opening: %s\n" , argv[1 ]); fd =open (argv[1 ],O_RDONLY |O_CLOEXEC );@@ -245,7 +266,7 @@ int main(int argc, char **argv)/* create new memfd-object */ mfd =mfd_assert_new ("kern_memfd_fuse" , -MFD_DEF_SIZE , + mfd_def_size,MFD_CLOEXEC |MFD_ALLOW_SEALING );/* mmap memfd-object for writing */ @@ -264,7 +285,7 @@ int main(int argc, char **argv)* This guarantees that the receive-buffer is pinned for 1s until the * data is written into it. The racing ADD_SEALS should thus fail as * the pages are still pinned. */ - r =read (fd, p,MFD_DEF_SIZE ); + r =read (fd, p, mfd_def_size);if (r <0 ) {printf ("read() failed: %m\n" );abort ();@@ -291,10 +312,10 @@ int main(int argc, char **argv)* enough to avoid any in-flight writes. */ p =mfd_assert_mmap_private (mfd); -if (was_sealed &&memcmp (p, zero,MFD_DEF_SIZE )) { +if (was_sealed &&memcmp (p, zero, mfd_def_size)) {printf ("memfd sealed during read() but data not discarded\n" );abort (); - }else if (!was_sealed && !memcmp (p, zero,MFD_DEF_SIZE )) { + }else if (!was_sealed && !memcmp (p, zero, mfd_def_size)) {printf ("memfd sealed after read() but data discarded\n" );abort (); }@@ -303,6 +324,7 @@ int main(int argc, char **argv)close (fd);printf ("fuse: DONE\n" ); +free (zero);return 0 ; }tools/testing/selftests/memfd/run_fuse_test.sh +1
-1@@ -10,6 +10,6 @@ set -e mkdir mnt ./fuse_mnt ./mnt -./fuse_test ./mnt/memfd +./fuse_test ./mnt/memfd $@ fusermount -u ./mnt rmdir ./mnttools/testing/selftests/memfd/run_tests.sh +0
-0
tools/testing/selftests/memfd/run_tests.sh fi · line 66
Quoted 7 lines
tools/testing/selftests/memfd/run_tests.sh +1
-0@@ -60,6 +60,7 @@ fi # Run the hugetlbfs test # ./memfd_test hugetlbfs +./run_fuse_test.sh hugetlbfs # # Give back any huge pages allocated for the test
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
+Cc: Andrew, Michal, David
Are there any other comments on this patch series from Marc-AndrA(C)? Is anything else needed to move forward?
I have reviewed the patches in the series. David Herrmann (the original memfd_create/file sealing author) has also taken a look at the patches.
One outstanding issue is sorting out the config option dependencies. Although, IMO this is not a strict requirement for this series. I have addressed this issue in a follow on series:
http://lkml.kernel.org/r/[email protected]
Signature · 1 line
Mike Kravetz
Quoted 41 lines · Marc-AndrA(C) Lureau
Hi,
Recently, Mike Kravetz added hugetlbfs support to memfd. However, he didn't add sealing support. One of the reasons to use memfd is to have shared memory sealing when doing IPC or sharing memory with another process with some extra safety. qemu uses shared memory & hugetables with vhost-user (used by dpdk), so it is reasonable to use memfd now instead for convenience and security reasons.
Thanks!
v3:
- do remaining MFD_DEF_SIZE/mfd_def_size substitutions
- fix missingunistd.hinclude incommon.c
- tweaked a bit commit message prefixes
- added reviewed-by tagsv2:
- add "memfd-hugetlb:" prefix in memfd-test
- run fuse test on hugetlb backend memory
- rename functionmemfd_file_get_seals()->memfd_file_seals_ptr()
- update commit messages
- added reviewed-by tags
RFC->v1:
- split rfc patch, after early review feedback
- added patch for memfd-test changes
- fix build with hugetlbfs disabled
- small code and commit messages improvementsMarc-AndrA(C) Lureau (9):
shmem: unexport shmem_add_seals()/shmem_get_seals()
shmem: rename functions that are memfd-related
hugetlb: exposehugetlbfs_inode_infoin header
hugetlb: implement memfd sealing
shmem: add sealing support to hugetlb-backed memfd
memfd-test: test hugetlbfs sealing
memfd-test: add 'memfd-hugetlb:' prefix when testing hugetlbfs
memfd-test: move common code to a shared unit
memfd-test: run fuse test on hugetlb backend memory
Quoted 16 lines
fs/fcntl.c | 2 +- fs/hugetlbfs/inode.c | 39 +++-- include/linux/hugetlb.h | 11 ++ include/linux/shmem_fs.h | 6 +- mm/shmem.c | 59 ++++--- tools/testing/selftests/memfd/Makefile | 5 + tools/testing/selftests/memfd/common.c | 46 ++++++ tools/testing/selftests/memfd/common.h | 9 ++ tools/testing/selftests/memfd/fuse_test.c | 44 +++-- tools/testing/selftests/memfd/memfd_test.c | 212 ++++--------------------- tools/testing/selftests/memfd/run_fuse_test.sh | 2 +- tools/testing/selftests/memfd/run_tests.sh | 1 + 12 files changed, 200 insertions(+), 236 deletions(-) create mode 100644 tools/testing/selftests/memfd/common.c create mode 100644 tools/testing/selftests/memfd/common.h
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Hi
Quoted 5 lines · Mike Kravetz
+Cc: Andrew, Michal, David
Are there any other comments on this patch series from Marc-André? Is anything else needed to move forward?
Quoted 7 lines
I have reviewed the patches in the series. David Herrmann (the original memfd_create/file sealing author) has also taken a look at the patches.
One outstanding issue is sorting out the config option dependencies. Although, IMO this is not a strict requirement for this series. I have addressed this issue in a follow on series:
http://lkml.kernel.org/r/[email protected]
Are we good for the next merge window? Is Hugh Dickins the maintainer with the final word, and doing the pull request? (sorry, I am not very familiar with kernel development)
thanks!
Quoted 57 lines
Quoted 57 lines
Hi,
Recently, Mike Kravetz added hugetlbfs support to memfd. However, he didn't add sealing support. One of the reasons to use memfd is to have shared memory sealing when doing IPC or sharing memory with another process with some extra safety. qemu uses shared memory & hugetables with vhost-user (used by dpdk), so it is reasonable to use memfd now instead for convenience and security reasons.
Thanks!
v3:
- do remaining MFD_DEF_SIZE/mfd_def_size substitutions
- fix missingunistd.hinclude incommon.c
- tweaked a bit commit message prefixes
- added reviewed-by tagsv2:
- add "memfd-hugetlb:" prefix in memfd-test
- run fuse test on hugetlb backend memory
- rename functionmemfd_file_get_seals()->memfd_file_seals_ptr()
- update commit messages
- added reviewed-by tags
RFC->v1:
- split rfc patch, after early review feedback
- added patch for memfd-test changes
- fix build with hugetlbfs disabled
- small code and commit messages improvementsMarc-André Lureau (9):
shmem: unexport shmem_add_seals()/shmem_get_seals()
shmem: rename functions that are memfd-related
hugetlb: exposehugetlbfs_inode_infoin header
hugetlb: implement memfd sealing
shmem: add sealing support to hugetlb-backed memfd
memfd-test: test hugetlbfs sealing
memfd-test: add 'memfd-hugetlb:' prefix when testing hugetlbfs
memfd-test: move common code to a shared unit
memfd-test: run fuse test on hugetlb backend memoryfs/fcntl.c | 2 +- fs/hugetlbfs/inode.c | 39 +++-- include/linux/hugetlb.h | 11 ++ include/linux/shmem_fs.h | 6 +- mm/shmem.c | 59 ++++--- tools/testing/selftests/memfd/Makefile | 5 + tools/testing/selftests/memfd/common.c | 46 ++++++ tools/testing/selftests/memfd/common.h | 9 ++ tools/testing/selftests/memfd/fuse_test.c | 44 +++-- tools/testing/selftests/memfd/memfd_test.c | 212 ++++--------------------- tools/testing/selftests/memfd/run_fuse_test.sh | 2 +- tools/testing/selftests/memfd/run_tests.sh | 1 + 12 files changed, 200 insertions(+), 236 deletions(-) create mode 100644 tools/testing/selftests/memfd/common.c create mode 100644 tools/testing/selftests/memfd/common.h
Signature · 7 lines
Marc-André Lureau -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 11 lines · Marc-Andre Lureau
Hi
Quoted 8 lines · Mike Kravetz
+Cc: Andrew, Michal, David
Are there any other comments on this patch series from Marc-Andre? Is anything else needed to move forward?
I have reviewed the patches in the series. David Herrmann (the original memfd_create/file sealing author) has also taken a look at the patches.
Quoted 8 lines
Quoted 4 lines
One outstanding issue is sorting out the config option dependencies. Although, IMO this is not a strict requirement for this series. I have addressed this issue in a follow on series:
http://lkml.kernel.org/r/[email protected]Are we good for the next merge window? Is Hugh Dickins the maintainer with the final word, and doing the pull request? (sorry, I am not very familiar with kernel development)
Andrew will pick it up, I assume. I will try to get and review this but there is way too much going on before holiday.
If Mieke feels sufficiently confident about this then I won't object to the go ahead.
Signature · 8 lines
Michal Hocko SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Andrew Morton
maintainerQuoted 17 lines · On Wed, 20 Dec 2017 16:10:51 +0100 Michal Hocko <[email protected]> wrote:
Quoted 16 lines · Marc-André Lureau
Hi
Quoted 12 lines · Mike Kravetz
+Cc: Andrew, Michal, David
Are there any other comments on this patch series from Marc-André? Is anything else needed to move forward?
I have reviewed the patches in the series. David Herrmann (the original memfd_create/file sealing author) has also taken a look at the patches.
One outstanding issue is sorting out the config option dependencies. Although, IMO this is not a strict requirement for this series. I have addressed this issue in a follow on series:
http://lkml.kernel.org/r/[email protected]
Quoted 6 lines
Quoted 3 lines
Are we good for the next merge window? Is Hugh Dickins the maintainer with the final word, and doing the pull request? (sorry, I am not very familiar with kernel development)
Andrew will pick it up, I assume. I will try to get and review this but there is way too much going on before holiday.
Yup, things are quiet at present.
I'll suck these up for a bit of testing - please let me know if you'd prefer them to be held back for a cycle (ie: for 4.17-rc1)
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 23 lines · Andrew Morton
Quoted 21 lines · On Wed, 20 Dec 2017 16:10:51 +0100 Michal Hocko <[email protected]> wrote:
Quoted 19 lines · Marc-AndrA(C) Lureau
Hi
Quoted 5 lines · Mike Kravetz
+Cc: Andrew, Michal, David
Are there any other comments on this patch series from Marc-AndrA(C)? Is anything else needed to move forward?
Quoted 7 lines
I have reviewed the patches in the series. David Herrmann (the original memfd_create/file sealing author) has also taken a look at the patches.
One outstanding issue is sorting out the config option dependencies. Although, IMO this is not a strict requirement for this series. I have addressed this issue in a follow on series:
http://lkml.kernel.org/r/[email protected]Are we good for the next merge window? Is Hugh Dickins the maintainer with the final word, and doing the pull request? (sorry, I am not very familiar with kernel development)
Quoted 7 lines
Quoted 2 lines
Andrew will pick it up, I assume. I will try to get and review this but there is way too much going on before holiday.
Yup, things are quiet at present.
I'll suck these up for a bit of testing - please let me know if you'd prefer them to be held back for a cycle (ie: for 4.17-rc1)
Thanks Andrew,
As mentioned above there is one issue related to this series that we may want to address. It is described in the series at:
http://lkml.kernel.org/r/[email protected]
I did not get many comments on this series/issue. If we want to do something like this, now might be a good time.
Signature · 7 lines
Mike Kravetz -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Hi Mike
Quoted 32 lines · Mike Kravetz
Quoted 23 lines · Andrew Morton
Quoted 21 lines · On Wed, 20 Dec 2017 16:10:51 +0100 Michal Hocko <[email protected]> wrote:
Quoted 19 lines · Marc-André Lureau
Hi
Quoted 5 lines · Mike Kravetz
+Cc: Andrew, Michal, David
Are there any other comments on this patch series from Marc-André? Is anything else needed to move forward?
Quoted 7 lines
I have reviewed the patches in the series. David Herrmann (the original memfd_create/file sealing author) has also taken a look at the patches.
One outstanding issue is sorting out the config option dependencies. Although, IMO this is not a strict requirement for this series. I have addressed this issue in a follow on series:
http://lkml.kernel.org/r/[email protected]Are we good for the next merge window? Is Hugh Dickins the maintainer with the final word, and doing the pull request? (sorry, I am not very familiar with kernel development)
Quoted 7 lines
Quoted 2 lines
Andrew will pick it up, I assume. I will try to get and review this but there is way too much going on before holiday.
Yup, things are quiet at present.
I'll suck these up for a bit of testing - please let me know if you'd prefer them to be held back for a cycle (ie: for 4.17-rc1)
Quoted 8 lines
Thanks Andrew,
As mentioned above there is one issue related to this series that we may want to address. It is described in the series at:
http://lkml.kernel.org/r/[email protected]I did not get many comments on this series/issue. If we want to do something like this, now might be a good time.
I am not the best person to say, but I think that series makes a lot of sense (and looks good to me). However, I don't think we need to wait for it to get the sealing support added (furthermore, your rfc series is on top).
Thanks!
Signature · 7 lines
Marc-André Lureau -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>