|
@@ -510,8 +510,16 @@ static long hugetlbfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
|
|
|
|
|
|
if (hole_end > hole_start) {
|
|
if (hole_end > hole_start) {
|
|
struct address_space *mapping = inode->i_mapping;
|
|
struct address_space *mapping = inode->i_mapping;
|
|
|
|
+ struct hugetlbfs_inode_info *info = HUGETLBFS_I(inode);
|
|
|
|
|
|
inode_lock(inode);
|
|
inode_lock(inode);
|
|
|
|
+
|
|
|
|
+ /* protected by i_mutex */
|
|
|
|
+ if (info->seals & F_SEAL_WRITE) {
|
|
|
|
+ inode_unlock(inode);
|
|
|
|
+ return -EPERM;
|
|
|
|
+ }
|
|
|
|
+
|
|
i_mmap_lock_write(mapping);
|
|
i_mmap_lock_write(mapping);
|
|
if (!RB_EMPTY_ROOT(&mapping->i_mmap.rb_root))
|
|
if (!RB_EMPTY_ROOT(&mapping->i_mmap.rb_root))
|
|
hugetlb_vmdelete_list(&mapping->i_mmap,
|
|
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)
|
|
loff_t len)
|
|
{
|
|
{
|
|
struct inode *inode = file_inode(file);
|
|
struct inode *inode = file_inode(file);
|
|
|
|
+ struct hugetlbfs_inode_info *info = HUGETLBFS_I(inode);
|
|
struct address_space *mapping = inode->i_mapping;
|
|
struct address_space *mapping = inode->i_mapping;
|
|
struct hstate *h = hstate_inode(inode);
|
|
struct hstate *h = hstate_inode(inode);
|
|
struct vm_area_struct pseudo_vma;
|
|
struct vm_area_struct pseudo_vma;
|
|
@@ -560,6 +569,11 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset,
|
|
if (error)
|
|
if (error)
|
|
goto out;
|
|
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
|
|
* Initialize a pseudo vma as this is required by the huge page
|
|
* allocation routines. If NUMA is configured, use page index
|
|
* 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);
|
|
struct hstate *h = hstate_inode(inode);
|
|
int error;
|
|
int error;
|
|
unsigned int ia_valid = attr->ia_valid;
|
|
unsigned int ia_valid = attr->ia_valid;
|
|
|
|
+ struct hugetlbfs_inode_info *info = HUGETLBFS_I(inode);
|
|
|
|
|
|
BUG_ON(!inode);
|
|
BUG_ON(!inode);
|
|
|
|
|
|
@@ -658,9 +673,16 @@ static int hugetlbfs_setattr(struct dentry *dentry, struct iattr *attr)
|
|
return error;
|
|
return error;
|
|
|
|
|
|
if (ia_valid & ATTR_SIZE) {
|
|
if (ia_valid & ATTR_SIZE) {
|
|
- if (attr->ia_size & ~huge_page_mask(h))
|
|
|
|
|
|
+ loff_t oldsize = inode->i_size;
|
|
|
|
+ loff_t newsize = attr->ia_size;
|
|
|
|
+
|
|
|
|
+ if (newsize & ~huge_page_mask(h))
|
|
return -EINVAL;
|
|
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)
|
|
if (error)
|
|
return error;
|
|
return error;
|
|
}
|
|
}
|
|
@@ -712,6 +734,8 @@ static struct inode *hugetlbfs_get_inode(struct super_block *sb,
|
|
|
|
|
|
inode = new_inode(sb);
|
|
inode = new_inode(sb);
|
|
if (inode) {
|
|
if (inode) {
|
|
|
|
+ struct hugetlbfs_inode_info *info = HUGETLBFS_I(inode);
|
|
|
|
+
|
|
inode->i_ino = get_next_ino();
|
|
inode->i_ino = get_next_ino();
|
|
inode_init_owner(inode, dir, mode);
|
|
inode_init_owner(inode, dir, mode);
|
|
lockdep_set_class(&inode->i_mapping->i_mmap_rwsem,
|
|
lockdep_set_class(&inode->i_mapping->i_mmap_rwsem,
|
|
@@ -719,6 +743,7 @@ static struct inode *hugetlbfs_get_inode(struct super_block *sb,
|
|
inode->i_mapping->a_ops = &hugetlbfs_aops;
|
|
inode->i_mapping->a_ops = &hugetlbfs_aops;
|
|
inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
|
|
inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
|
|
inode->i_mapping->private_data = resv_map;
|
|
inode->i_mapping->private_data = resv_map;
|
|
|
|
+ info->seals = F_SEAL_SEAL;
|
|
switch (mode & S_IFMT) {
|
|
switch (mode & S_IFMT) {
|
|
default:
|
|
default:
|
|
init_special_inode(inode, mode, dev);
|
|
init_special_inode(inode, mode, dev);
|