aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorPraneeth Bajjuri2017-08-28 18:03:19 -0500
committerPraneeth Bajjuri2017-08-28 18:03:19 -0500
commitdda8acaf6f2d9bddce62c305edf6b3071f04c136 (patch)
tree612f8b7b18ff3a84184ddc0ce456b9b0287cace6 /fs
parentb22bbe0c5fa4fd5eb4609108a750b28a744a643e (diff)
parenteabbcea7629d5f2ec91568f7bd104536614107db (diff)
downloadkernel-omap-6AM.1.3-rvc-video.tar.gz
kernel-omap-6AM.1.3-rvc-video.tar.xz
kernel-omap-6AM.1.3-rvc-video.zip
Merge branch 'p-ti-lsk-android-linux-4.4.y' of git://git.omapzoom.org/kernel/omap into 6AM.1.3-rvc-video6AM.1.3-rvc-video
* 'p-ti-lsk-android-linux-4.4.y' of git://git.omapzoom.org/kernel/omap: (2048 commits) ARM: dts: dra7: Remove deprecated PCI compatible string ARM: dts: dra76-evm: Enable x2 PCIe lanes ARM: dts: DRA72x: Use PCIe compatible specific to dra72 ARM: dts: DRA74x: Use PCIe compatible specific to dra74 ARM: dts: dra7: Add properties to enable PCIe x2 lane mode PCI: dwc: pci-dra7xx: Enable x2 mode support PCI: dwc: dra7xx: Add support for SoC specific compatible strings dt-bindings: PCI: dra7xx: Add properties to enable x2 lane in dra7 dt-bindings: PCI: dra7xx: Add SoC specific compatible strings ARM: dts: dra7-evm: Move pcie RC node to common file ARM: dts: dra76-evm: add higher speed MMC/SD modes Linux 4.4.84 usb: qmi_wwan: add D-Link DWM-222 device ID usb: optimize acpi companion search for usb port devices perf/x86: Fix LBR related crashes on Intel Atom pids: make task_tgid_nr_ns() safe Sanitize 'move_pages()' permission checks irqchip/atmel-aic: Fix unbalanced refcount in aic_common_rtc_irq_fixup() irqchip/atmel-aic: Fix unbalanced of_node_put() in aic_common_irq_fixup() x86/asm/64: Clear AC on NMI entries ... Signed-off-by: Praneeth Bajjuri <praneeth@ti.com> Conflicts: arch/arm/boot/dts/Makefile drivers/gpu/drm/omapdrm/dss/dispc.c
Diffstat (limited to 'fs')
-rw-r--r--fs/9p/acl.c2
-rw-r--r--fs/Makefile2
-rw-r--r--fs/attr.c14
-rw-r--r--fs/autofs4/dev-ioctl.c2
-rw-r--r--fs/binfmt_elf.c60
-rw-r--r--fs/block_dev.c12
-rw-r--r--fs/btrfs/extent-tree.c1
-rw-r--r--fs/btrfs/file.c2
-rw-r--r--fs/btrfs/inode.c28
-rw-r--r--fs/buffer.c12
-rw-r--r--fs/ceph/acl.c4
-rw-r--r--fs/ceph/addr.c2
-rw-r--r--fs/ceph/dir.c5
-rw-r--r--fs/ceph/inode.c27
-rw-r--r--fs/ceph/mds_client.c5
-rw-r--r--fs/ceph/super.h1
-rw-r--r--fs/ceph/xattr.c3
-rw-r--r--fs/cifs/cifs_unicode.c6
-rw-r--r--fs/cifs/cifs_unicode.h5
-rw-r--r--fs/cifs/cifsglob.h12
-rw-r--r--fs/cifs/cifssmb.c7
-rw-r--r--fs/cifs/connect.c37
-rw-r--r--fs/cifs/file.c6
-rw-r--r--fs/cifs/ioctl.c2
-rw-r--r--fs/cifs/readdir.c1
-rw-r--r--fs/cifs/smb1ops.c19
-rw-r--r--fs/cifs/smb2misc.c44
-rw-r--r--fs/cifs/smb2ops.c8
-rw-r--r--fs/cifs/smb2pdu.c23
-rw-r--r--fs/cifs/smb2proto.h7
-rw-r--r--fs/cifs/smb2transport.c58
-rw-r--r--fs/cifs/transport.c2
-rw-r--r--fs/configfs/symlink.c3
-rw-r--r--fs/coredump.c20
-rw-r--r--fs/dcache.c32
-rw-r--r--fs/debugfs/inode.c10
-rw-r--r--fs/direct-io.c2
-rw-r--r--fs/exec.c37
-rw-r--r--fs/ext2/ext2.h3
-rw-r--r--fs/ext2/super.c25
-rw-r--r--fs/ext2/xattr.c143
-rw-r--r--fs/ext2/xattr.h21
-rw-r--r--fs/ext4/Kconfig1
-rw-r--r--fs/ext4/crypto.c96
-rw-r--r--fs/ext4/crypto_fname.c5
-rw-r--r--fs/ext4/crypto_key.c129
-rw-r--r--fs/ext4/crypto_policy.c70
-rw-r--r--fs/ext4/dir.c6
-rw-r--r--fs/ext4/ext4.h24
-rw-r--r--fs/ext4/ext4_crypto.h5
-rw-r--r--fs/ext4/extents.c32
-rw-r--r--fs/ext4/file.c53
-rw-r--r--fs/ext4/inline.c26
-rw-r--r--fs/ext4/inode.c107
-rw-r--r--fs/ext4/ioctl.c7
-rw-r--r--fs/ext4/mballoc.c7
-rw-r--r--fs/ext4/move_extent.c2
-rw-r--r--fs/ext4/namei.c22
-rw-r--r--fs/ext4/page-io.c14
-rw-r--r--fs/ext4/readpage.c8
-rw-r--r--fs/ext4/resize.c3
-rw-r--r--fs/ext4/super.c25
-rw-r--r--fs/ext4/sysfs.c2
-rw-r--r--fs/ext4/xattr.c168
-rw-r--r--fs/ext4/xattr.h5
-rw-r--r--fs/f2fs/acl.c2
-rw-r--r--fs/f2fs/crypto_fname.c2
-rw-r--r--fs/f2fs/crypto_key.c28
-rw-r--r--fs/f2fs/crypto_policy.c68
-rw-r--r--fs/f2fs/data.c34
-rw-r--r--fs/f2fs/dir.c32
-rw-r--r--fs/f2fs/f2fs.h17
-rw-r--r--fs/f2fs/f2fs_crypto.h1
-rw-r--r--fs/f2fs/file.c9
-rw-r--r--fs/f2fs/hash.c7
-rw-r--r--fs/f2fs/inline.c17
-rw-r--r--fs/f2fs/super.c121
-rw-r--r--fs/fat/inode.c13
-rw-r--r--fs/fcntl.c14
-rw-r--r--fs/fs_struct.c3
-rw-r--r--fs/fscache/cookie.c5
-rw-r--r--fs/fscache/netfs.c1
-rw-r--r--fs/fscache/object.c32
-rw-r--r--fs/fuse/dev.c4
-rw-r--r--fs/fuse/file.c3
-rw-r--r--fs/gfs2/dir.c4
-rw-r--r--fs/gfs2/glock.c16
-rw-r--r--fs/gfs2/incore.h3
-rw-r--r--fs/hugetlbfs/inode.c2
-rw-r--r--fs/inode.c6
-rw-r--r--fs/internal.h4
-rw-r--r--fs/jbd2/transaction.c4
-rw-r--r--fs/jfs/super.c4
-rw-r--r--fs/mbcache2.c359
-rw-r--r--fs/mount.h4
-rw-r--r--fs/mpage.c8
-rw-r--r--fs/namei.c187
-rw-r--r--fs/namespace.c192
-rw-r--r--fs/nfs/Kconfig1
-rw-r--r--fs/nfs/dir.c33
-rw-r--r--fs/nfs/flexfilelayout/flexfilelayoutdev.c1
-rw-r--r--fs/nfs/inode.c4
-rw-r--r--fs/nfs/nfs4proc.c15
-rw-r--r--fs/nfs/nfs4state.c1
-rw-r--r--fs/nfs/nfs4xdr.c2
-rw-r--r--fs/nfsd/blocklayout.c4
-rw-r--r--fs/nfsd/nfs3xdr.c12
-rw-r--r--fs/nfsd/nfs4layouts.c5
-rw-r--r--fs/nfsd/nfs4proc.c13
-rw-r--r--fs/nfsd/nfs4state.c19
-rw-r--r--fs/nfsd/nfs4xdr.c21
-rw-r--r--fs/nfsd/nfssvc.c36
-rw-r--r--fs/nfsd/nfsxdr.c10
-rw-r--r--fs/nfsd/state.h4
-rw-r--r--fs/nfsd/vfs.c59
-rw-r--r--fs/nilfs2/btnode.c2
-rw-r--r--fs/nilfs2/inode.c4
-rw-r--r--fs/nilfs2/mdt.c4
-rw-r--r--fs/nilfs2/segment.c2
-rw-r--r--fs/notify/fanotify/fanotify_user.c2
-rw-r--r--fs/notify/fsnotify.c8
-rw-r--r--fs/notify/inotify/inotify_user.c2
-rw-r--r--fs/ocfs2/aops.c2
-rw-r--r--fs/ocfs2/cluster/heartbeat.c8
-rw-r--r--fs/ocfs2/file.c2
-rw-r--r--fs/open.c43
-rw-r--r--fs/pnode.c278
-rw-r--r--fs/pnode.h4
-rw-r--r--fs/proc/base.c2
-rw-r--r--fs/proc/generic.c1
-rw-r--r--fs/proc/task_mmu.c13
-rw-r--r--fs/proc_namespace.c8
-rw-r--r--fs/pstore/ram.c5
-rw-r--r--fs/pstore/ram_core.c25
-rw-r--r--fs/reiserfs/file.c2
-rw-r--r--fs/reiserfs/inode.c2
-rw-r--r--fs/romfs/super.c23
-rw-r--r--fs/sdcardfs/dentry.c49
-rw-r--r--fs/sdcardfs/derived_perm.c378
-rw-r--r--fs/sdcardfs/file.c113
-rw-r--r--fs/sdcardfs/inode.c408
-rw-r--r--fs/sdcardfs/lookup.c220
-rw-r--r--fs/sdcardfs/main.c180
-rw-r--r--fs/sdcardfs/mmap.c76
-rw-r--r--fs/sdcardfs/multiuser.h30
-rw-r--r--fs/sdcardfs/packagelist.c859
-rw-r--r--fs/sdcardfs/sdcardfs.h244
-rw-r--r--fs/sdcardfs/super.c82
-rw-r--r--fs/seq_file.c7
-rw-r--r--fs/splice.c1
-rw-r--r--fs/squashfs/Kconfig28
-rw-r--r--fs/squashfs/Makefile3
-rw-r--r--fs/squashfs/block.c546
-rw-r--r--fs/squashfs/cache.c73
-rw-r--r--fs/squashfs/decompressor.c55
-rw-r--r--fs/squashfs/file.c140
-rw-r--r--fs/squashfs/file_cache.c38
-rw-r--r--fs/squashfs/file_direct.c245
-rw-r--r--fs/squashfs/lz4_wrapper.c32
-rw-r--r--fs/squashfs/lzo_wrapper.c40
-rw-r--r--fs/squashfs/page_actor.c175
-rw-r--r--fs/squashfs/page_actor.h84
-rw-r--r--fs/squashfs/squashfs.h11
-rw-r--r--fs/squashfs/squashfs_fs_sb.h2
-rw-r--r--fs/squashfs/super.c7
-rw-r--r--fs/squashfs/xz_wrapper.c15
-rw-r--r--fs/squashfs/zlib_wrapper.c14
-rw-r--r--fs/stat.c3
-rw-r--r--fs/super.c28
-rw-r--r--fs/sync.c1
-rw-r--r--fs/sysfs/file.c6
-rw-r--r--fs/timerfd.c17
-rw-r--r--fs/udf/inode.c6
-rw-r--r--fs/ufs/balloc.c26
-rw-r--r--fs/ufs/inode.c9
-rw-r--r--fs/ufs/super.c18
-rw-r--r--fs/ufs/util.h10
-rw-r--r--fs/utimes.c2
-rw-r--r--fs/xattr.c2
-rw-r--r--fs/xfs/libxfs/xfs_bmap.c7
-rw-r--r--fs/xfs/libxfs/xfs_btree.c2
-rw-r--r--fs/xfs/libxfs/xfs_inode_buf.c8
-rw-r--r--fs/xfs/xfs_aops.c31
-rw-r--r--fs/xfs/xfs_attr.h1
-rw-r--r--fs/xfs/xfs_attr_list.c8
-rw-r--r--fs/xfs/xfs_bmap_util.c9
-rw-r--r--fs/xfs/xfs_buf.c25
-rw-r--r--fs/xfs/xfs_buf.h1
-rw-r--r--fs/xfs/xfs_dir2_readdir.c15
-rw-r--r--fs/xfs/xfs_file.c35
-rw-r--r--fs/xfs/xfs_icache.c58
-rw-r--r--fs/xfs/xfs_icache.h8
-rw-r--r--fs/xfs/xfs_inode.h4
-rw-r--r--fs/xfs/xfs_ioctl.c11
-rw-r--r--fs/xfs/xfs_qm.c7
-rw-r--r--fs/xfs/xfs_qm_syscalls.c3
-rw-r--r--fs/xfs/xfs_xattr.c16
197 files changed, 5660 insertions, 2292 deletions
diff --git a/fs/9p/acl.c b/fs/9p/acl.c
index 929b618da43b..c30c6ceac2c4 100644
--- a/fs/9p/acl.c
+++ b/fs/9p/acl.c
@@ -283,6 +283,7 @@ static int v9fs_xattr_set_acl(const struct xattr_handler *handler,
283 case ACL_TYPE_ACCESS: 283 case ACL_TYPE_ACCESS:
284 if (acl) { 284 if (acl) {
285 struct iattr iattr; 285 struct iattr iattr;
286 struct posix_acl *old_acl = acl;
286 287
287 retval = posix_acl_update_mode(inode, &iattr.ia_mode, &acl); 288 retval = posix_acl_update_mode(inode, &iattr.ia_mode, &acl);
288 if (retval) 289 if (retval)
@@ -293,6 +294,7 @@ static int v9fs_xattr_set_acl(const struct xattr_handler *handler,
293 * by the mode bits. So don't 294 * by the mode bits. So don't
294 * update ACL. 295 * update ACL.
295 */ 296 */
297 posix_acl_release(old_acl);
296 value = NULL; 298 value = NULL;
297 size = 0; 299 size = 0;
298 } 300 }
diff --git a/fs/Makefile b/fs/Makefile
index 3b54070cd629..dee237540bc0 100644
--- a/fs/Makefile
+++ b/fs/Makefile
@@ -41,7 +41,7 @@ obj-$(CONFIG_COMPAT_BINFMT_ELF) += compat_binfmt_elf.o
41obj-$(CONFIG_BINFMT_ELF_FDPIC) += binfmt_elf_fdpic.o 41obj-$(CONFIG_BINFMT_ELF_FDPIC) += binfmt_elf_fdpic.o
42obj-$(CONFIG_BINFMT_FLAT) += binfmt_flat.o 42obj-$(CONFIG_BINFMT_FLAT) += binfmt_flat.o
43 43
44obj-$(CONFIG_FS_MBCACHE) += mbcache.o 44obj-$(CONFIG_FS_MBCACHE) += mbcache.o mbcache2.o
45obj-$(CONFIG_FS_POSIX_ACL) += posix_acl.o 45obj-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
46obj-$(CONFIG_NFS_COMMON) += nfs_common/ 46obj-$(CONFIG_NFS_COMMON) += nfs_common/
47obj-$(CONFIG_COREDUMP) += coredump.o 47obj-$(CONFIG_COREDUMP) += coredump.o
diff --git a/fs/attr.c b/fs/attr.c
index d62f674a605f..c86b37c38fb7 100644
--- a/fs/attr.c
+++ b/fs/attr.c
@@ -187,7 +187,7 @@ EXPORT_SYMBOL(setattr_copy);
187 * the file open for write, as there can be no conflicting delegation in 187 * the file open for write, as there can be no conflicting delegation in
188 * that case. 188 * that case.
189 */ 189 */
190int notify_change(struct dentry * dentry, struct iattr * attr, struct inode **delegated_inode) 190int notify_change2(struct vfsmount *mnt, struct dentry * dentry, struct iattr * attr, struct inode **delegated_inode)
191{ 191{
192 struct inode *inode = dentry->d_inode; 192 struct inode *inode = dentry->d_inode;
193 umode_t mode = inode->i_mode; 193 umode_t mode = inode->i_mode;
@@ -211,7 +211,7 @@ int notify_change(struct dentry * dentry, struct iattr * attr, struct inode **de
211 return -EPERM; 211 return -EPERM;
212 212
213 if (!inode_owner_or_capable(inode)) { 213 if (!inode_owner_or_capable(inode)) {
214 error = inode_permission(inode, MAY_WRITE); 214 error = inode_permission2(mnt, inode, MAY_WRITE);
215 if (error) 215 if (error)
216 return error; 216 return error;
217 } 217 }
@@ -277,7 +277,9 @@ int notify_change(struct dentry * dentry, struct iattr * attr, struct inode **de
277 if (error) 277 if (error)
278 return error; 278 return error;
279 279
280 if (inode->i_op->setattr) 280 if (mnt && inode->i_op->setattr2)
281 error = inode->i_op->setattr2(mnt, dentry, attr);
282 else if (inode->i_op->setattr)
281 error = inode->i_op->setattr(dentry, attr); 283 error = inode->i_op->setattr(dentry, attr);
282 else 284 else
283 error = simple_setattr(dentry, attr); 285 error = simple_setattr(dentry, attr);
@@ -290,4 +292,10 @@ int notify_change(struct dentry * dentry, struct iattr * attr, struct inode **de
290 292
291 return error; 293 return error;
292} 294}
295EXPORT_SYMBOL(notify_change2);
296
297int notify_change(struct dentry * dentry, struct iattr * attr, struct inode **delegated_inode)
298{
299 return notify_change2(NULL, dentry, attr, delegated_inode);
300}
293EXPORT_SYMBOL(notify_change); 301EXPORT_SYMBOL(notify_change);
diff --git a/fs/autofs4/dev-ioctl.c b/fs/autofs4/dev-ioctl.c
index ac7d921ed984..257425511d10 100644
--- a/fs/autofs4/dev-ioctl.c
+++ b/fs/autofs4/dev-ioctl.c
@@ -331,7 +331,7 @@ static int autofs_dev_ioctl_fail(struct file *fp,
331 int status; 331 int status;
332 332
333 token = (autofs_wqt_t) param->fail.token; 333 token = (autofs_wqt_t) param->fail.token;
334 status = param->fail.status ? param->fail.status : -ENOENT; 334 status = param->fail.status < 0 ? param->fail.status : -ENOENT;
335 return autofs4_wait_release(sbi, token, status); 335 return autofs4_wait_release(sbi, token, status);
336} 336}
337 337
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 0c52941dd62c..8a0243efd359 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -905,17 +905,60 @@ static int load_elf_binary(struct linux_binprm *bprm)
905 elf_flags = MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE; 905 elf_flags = MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE;
906 906
907 vaddr = elf_ppnt->p_vaddr; 907 vaddr = elf_ppnt->p_vaddr;
908 /*
909 * If we are loading ET_EXEC or we have already performed
910 * the ET_DYN load_addr calculations, proceed normally.
911 */
908 if (loc->elf_ex.e_type == ET_EXEC || load_addr_set) { 912 if (loc->elf_ex.e_type == ET_EXEC || load_addr_set) {
909 elf_flags |= MAP_FIXED; 913 elf_flags |= MAP_FIXED;
910 } else if (loc->elf_ex.e_type == ET_DYN) { 914 } else if (loc->elf_ex.e_type == ET_DYN) {
911 /* Try and get dynamic programs out of the way of the 915 /*
912 * default mmap base, as well as whatever program they 916 * This logic is run once for the first LOAD Program
913 * might try to exec. This is because the brk will 917 * Header for ET_DYN binaries to calculate the
914 * follow the loader, and is not movable. */ 918 * randomization (load_bias) for all the LOAD
915 load_bias = ELF_ET_DYN_BASE - vaddr; 919 * Program Headers, and to calculate the entire
916 if (current->flags & PF_RANDOMIZE) 920 * size of the ELF mapping (total_size). (Note that
917 load_bias += arch_mmap_rnd(); 921 * load_addr_set is set to true later once the
918 load_bias = ELF_PAGESTART(load_bias); 922 * initial mapping is performed.)
923 *
924 * There are effectively two types of ET_DYN
925 * binaries: programs (i.e. PIE: ET_DYN with INTERP)
926 * and loaders (ET_DYN without INTERP, since they
927 * _are_ the ELF interpreter). The loaders must
928 * be loaded away from programs since the program
929 * may otherwise collide with the loader (especially
930 * for ET_EXEC which does not have a randomized
931 * position). For example to handle invocations of
932 * "./ld.so someprog" to test out a new version of
933 * the loader, the subsequent program that the
934 * loader loads must avoid the loader itself, so
935 * they cannot share the same load range. Sufficient
936 * room for the brk must be allocated with the
937 * loader as well, since brk must be available with
938 * the loader.
939 *
940 * Therefore, programs are loaded offset from
941 * ELF_ET_DYN_BASE and loaders are loaded into the
942 * independently randomized mmap region (0 load_bias
943 * without MAP_FIXED).
944 */
945 if (elf_interpreter) {
946 load_bias = ELF_ET_DYN_BASE;
947 if (current->flags & PF_RANDOMIZE)
948 load_bias += arch_mmap_rnd();
949 elf_flags |= MAP_FIXED;
950 } else
951 load_bias = 0;
952
953 /*
954 * Since load_bias is used for all subsequent loading
955 * calculations, we must lower it by the first vaddr
956 * so that the remaining calculations based on the
957 * ELF vaddrs will be correctly offset. The result
958 * is then page aligned.
959 */
960 load_bias = ELF_PAGESTART(load_bias - vaddr);
961
919 total_size = total_mapping_size(elf_phdata, 962 total_size = total_mapping_size(elf_phdata,
920 loc->elf_ex.e_phnum); 963 loc->elf_ex.e_phnum);
921 if (!total_size) { 964 if (!total_size) {
@@ -2295,6 +2338,7 @@ static int elf_core_dump(struct coredump_params *cprm)
2295 goto end_coredump; 2338 goto end_coredump;
2296 } 2339 }
2297 } 2340 }
2341 dump_truncate(cprm);
2298 2342
2299 if (!elf_core_write_extra_data(cprm)) 2343 if (!elf_core_write_extra_data(cprm))
2300 goto end_coredump; 2344 goto end_coredump;
diff --git a/fs/block_dev.c b/fs/block_dev.c
index 198aea66fe71..26bbaaefdff4 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -88,12 +88,11 @@ void invalidate_bdev(struct block_device *bdev)
88{ 88{
89 struct address_space *mapping = bdev->bd_inode->i_mapping; 89 struct address_space *mapping = bdev->bd_inode->i_mapping;
90 90
91 if (mapping->nrpages == 0) 91 if (mapping->nrpages) {
92 return; 92 invalidate_bh_lrus();
93 93 lru_add_drain_all(); /* make sure all lru add caches are flushed */
94 invalidate_bh_lrus(); 94 invalidate_mapping_pages(mapping, 0, -1);
95 lru_add_drain_all(); /* make sure all lru add caches are flushed */ 95 }
96 invalidate_mapping_pages(mapping, 0, -1);
97 /* 99% of the time, we don't need to flush the cleancache on the bdev. 96 /* 99% of the time, we don't need to flush the cleancache on the bdev.
98 * But, for the strange corners, lets be cautious 97 * But, for the strange corners, lets be cautious
99 */ 98 */
@@ -1098,7 +1097,6 @@ int revalidate_disk(struct gendisk *disk)
1098 1097
1099 if (disk->fops->revalidate_disk) 1098 if (disk->fops->revalidate_disk)
1100 ret = disk->fops->revalidate_disk(disk); 1099 ret = disk->fops->revalidate_disk(disk);
1101 blk_integrity_revalidate(disk);
1102 bdev = bdget_disk(disk, 0); 1100 bdev = bdget_disk(disk, 0);
1103 if (!bdev) 1101 if (!bdev)
1104 return ret; 1102 return ret;
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 2a2e370399ba..c36a03fa7678 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -3854,6 +3854,7 @@ static int update_space_info(struct btrfs_fs_info *info, u64 flags,
3854 info->space_info_kobj, "%s", 3854 info->space_info_kobj, "%s",
3855 alloc_name(found->flags)); 3855 alloc_name(found->flags));
3856 if (ret) { 3856 if (ret) {
3857 percpu_counter_destroy(&found->total_bytes_pinned);
3857 kfree(found); 3858 kfree(found);
3858 return ret; 3859 return ret;
3859 } 3860 }
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 353f4bae658c..d4a6eef31854 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -2771,7 +2771,7 @@ static long btrfs_fallocate(struct file *file, int mode,
2771 if (!ret) 2771 if (!ret)
2772 ret = btrfs_prealloc_file_range(inode, mode, 2772 ret = btrfs_prealloc_file_range(inode, mode,
2773 range->start, 2773 range->start,
2774 range->len, 1 << inode->i_blkbits, 2774 range->len, i_blocksize(inode),
2775 offset + len, &alloc_hint); 2775 offset + len, &alloc_hint);
2776 list_del(&range->list); 2776 list_del(&range->list);
2777 kfree(range); 2777 kfree(range);
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 3cff6523f27d..bebd6517355d 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -4397,8 +4397,19 @@ search_again:
4397 if (found_type > min_type) { 4397 if (found_type > min_type) {
4398 del_item = 1; 4398 del_item = 1;
4399 } else { 4399 } else {
4400 if (item_end < new_size) 4400 if (item_end < new_size) {
4401 /*
4402 * With NO_HOLES mode, for the following mapping
4403 *
4404 * [0-4k][hole][8k-12k]
4405 *
4406 * if truncating isize down to 6k, it ends up
4407 * isize being 8k.
4408 */
4409 if (btrfs_fs_incompat(root->fs_info, NO_HOLES))
4410 last_size = new_size;
4401 break; 4411 break;
4412 }
4402 if (found_key.offset >= new_size) 4413 if (found_key.offset >= new_size)
4403 del_item = 1; 4414 del_item = 1;
4404 else 4415 else
@@ -7318,8 +7329,8 @@ bool btrfs_page_exists_in_range(struct inode *inode, loff_t start, loff_t end)
7318 int found = false; 7329 int found = false;
7319 void **pagep = NULL; 7330 void **pagep = NULL;
7320 struct page *page = NULL; 7331 struct page *page = NULL;
7321 int start_idx; 7332 unsigned long start_idx;
7322 int end_idx; 7333 unsigned long end_idx;
7323 7334
7324 start_idx = start >> PAGE_CACHE_SHIFT; 7335 start_idx = start >> PAGE_CACHE_SHIFT;
7325 7336
@@ -7510,11 +7521,18 @@ static void adjust_dio_outstanding_extents(struct inode *inode,
7510 * within our reservation, otherwise we need to adjust our inode 7521 * within our reservation, otherwise we need to adjust our inode
7511 * counter appropriately. 7522 * counter appropriately.
7512 */ 7523 */
7513 if (dio_data->outstanding_extents) { 7524 if (dio_data->outstanding_extents >= num_extents) {
7514 dio_data->outstanding_extents -= num_extents; 7525 dio_data->outstanding_extents -= num_extents;
7515 } else { 7526 } else {
7527 /*
7528 * If dio write length has been split due to no large enough
7529 * contiguous space, we need to compensate our inode counter
7530 * appropriately.
7531 */
7532 u64 num_needed = num_extents - dio_data->outstanding_extents;
7533
7516 spin_lock(&BTRFS_I(inode)->lock); 7534 spin_lock(&BTRFS_I(inode)->lock);
7517 BTRFS_I(inode)->outstanding_extents += num_extents; 7535 BTRFS_I(inode)->outstanding_extents += num_needed;
7518 spin_unlock(&BTRFS_I(inode)->lock); 7536 spin_unlock(&BTRFS_I(inode)->lock);
7519 } 7537 }
7520} 7538}
diff --git a/fs/buffer.c b/fs/buffer.c
index 4f4cd959da7c..6f7d519a093b 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -2298,7 +2298,7 @@ static int cont_expand_zero(struct file *file, struct address_space *mapping,
2298 loff_t pos, loff_t *bytes) 2298 loff_t pos, loff_t *bytes)
2299{ 2299{
2300 struct inode *inode = mapping->host; 2300 struct inode *inode = mapping->host;
2301 unsigned blocksize = 1 << inode->i_blkbits; 2301 unsigned int blocksize = i_blocksize(inode);
2302 struct page *page; 2302 struct page *page;
2303 void *fsdata; 2303 void *fsdata;
2304 pgoff_t index, curidx; 2304 pgoff_t index, curidx;
@@ -2378,8 +2378,8 @@ int cont_write_begin(struct file *file, struct address_space *mapping,
2378 get_block_t *get_block, loff_t *bytes) 2378 get_block_t *get_block, loff_t *bytes)
2379{ 2379{
2380 struct inode *inode = mapping->host; 2380 struct inode *inode = mapping->host;
2381 unsigned blocksize = 1 << inode->i_blkbits; 2381 unsigned int blocksize = i_blocksize(inode);
2382 unsigned zerofrom; 2382 unsigned int zerofrom;
2383 int err; 2383 int err;
2384 2384
2385 err = cont_expand_zero(file, mapping, pos, bytes); 2385 err = cont_expand_zero(file, mapping, pos, bytes);
@@ -2741,7 +2741,7 @@ int nobh_truncate_page(struct address_space *mapping,
2741 struct buffer_head map_bh; 2741 struct buffer_head map_bh;
2742 int err; 2742 int err;
2743 2743
2744 blocksize = 1 << inode->i_blkbits; 2744 blocksize = i_blocksize(inode);
2745 length = offset & (blocksize - 1); 2745 length = offset & (blocksize - 1);
2746 2746
2747 /* Block boundary? Nothing to do */ 2747 /* Block boundary? Nothing to do */
@@ -2819,7 +2819,7 @@ int block_truncate_page(struct address_space *mapping,
2819 struct buffer_head *bh; 2819 struct buffer_head *bh;
2820 int err; 2820 int err;
2821 2821
2822 blocksize = 1 << inode->i_blkbits; 2822 blocksize = i_blocksize(inode);
2823 length = offset & (blocksize - 1); 2823 length = offset & (blocksize - 1);
2824 2824
2825 /* Block boundary? Nothing to do */ 2825 /* Block boundary? Nothing to do */
@@ -2931,7 +2931,7 @@ sector_t generic_block_bmap(struct address_space *mapping, sector_t block,
2931 struct inode *inode = mapping->host; 2931 struct inode *inode = mapping->host;
2932 tmp.b_state = 0; 2932 tmp.b_state = 0;
2933 tmp.b_blocknr = 0; 2933 tmp.b_blocknr = 0;
2934 tmp.b_size = 1 << inode->i_blkbits; 2934 tmp.b_size = i_blocksize(inode);
2935 get_block(inode, block, &tmp, 0); 2935 get_block(inode, block, &tmp, 0);
2936 return tmp.b_blocknr; 2936 return tmp.b_blocknr;
2937} 2937}
diff --git a/fs/ceph/acl.c b/fs/ceph/acl.c
index 4d8caeb94a11..bdb9c94335f1 100644
--- a/fs/ceph/acl.c
+++ b/fs/ceph/acl.c
@@ -128,7 +128,7 @@ int ceph_set_acl(struct inode *inode, struct posix_acl *acl, int type)
128 if (new_mode != old_mode) { 128 if (new_mode != old_mode) {
129 newattrs.ia_mode = new_mode; 129 newattrs.ia_mode = new_mode;
130 newattrs.ia_valid = ATTR_MODE; 130 newattrs.ia_valid = ATTR_MODE;
131 ret = ceph_setattr(dentry, &newattrs); 131 ret = __ceph_setattr(dentry, &newattrs);
132 if (ret) 132 if (ret)
133 goto out_dput; 133 goto out_dput;
134 } 134 }
@@ -138,7 +138,7 @@ int ceph_set_acl(struct inode *inode, struct posix_acl *acl, int type)
138 if (new_mode != old_mode) { 138 if (new_mode != old_mode) {
139 newattrs.ia_mode = old_mode; 139 newattrs.ia_mode = old_mode;
140 newattrs.ia_valid = ATTR_MODE; 140 newattrs.ia_valid = ATTR_MODE;
141 ceph_setattr(dentry, &newattrs); 141 __ceph_setattr(dentry, &newattrs);
142 } 142 }
143 goto out_dput; 143 goto out_dput;
144 } 144 }
diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
index b7d218a168fb..c6a1ec110c01 100644
--- a/fs/ceph/addr.c
+++ b/fs/ceph/addr.c
@@ -697,7 +697,7 @@ static int ceph_writepages_start(struct address_space *mapping,
697 struct pagevec pvec; 697 struct pagevec pvec;
698 int done = 0; 698 int done = 0;
699 int rc = 0; 699 int rc = 0;
700 unsigned wsize = 1 << inode->i_blkbits; 700 unsigned int wsize = i_blocksize(inode);
701 struct ceph_osd_request *req = NULL; 701 struct ceph_osd_request *req = NULL;
702 int do_sync = 0; 702 int do_sync = 0;
703 loff_t snap_size, i_size; 703 loff_t snap_size, i_size;
diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
index 9314b4ea2375..be7d187d53fd 100644
--- a/fs/ceph/dir.c
+++ b/fs/ceph/dir.c
@@ -247,6 +247,11 @@ static int __dcache_readdir(struct file *file, struct dir_context *ctx,
247 if (ret < 0) 247 if (ret < 0)
248 err = ret; 248 err = ret;
249 dput(last); 249 dput(last);
250 /* last_name no longer match cache index */
251 if (fi->readdir_cache_idx >= 0) {
252 fi->readdir_cache_idx = -1;
253 fi->dir_release_count = 0;
254 }
250 } 255 }
251 return err; 256 return err;
252} 257}
diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c
index d98536c8abfc..9f0d99094cc1 100644
--- a/fs/ceph/inode.c
+++ b/fs/ceph/inode.c
@@ -1773,7 +1773,7 @@ static const struct inode_operations ceph_symlink_iops = {
1773/* 1773/*
1774 * setattr 1774 * setattr
1775 */ 1775 */
1776int ceph_setattr(struct dentry *dentry, struct iattr *attr) 1776int __ceph_setattr(struct dentry *dentry, struct iattr *attr)
1777{ 1777{
1778 struct inode *inode = d_inode(dentry); 1778 struct inode *inode = d_inode(dentry);
1779 struct ceph_inode_info *ci = ceph_inode(inode); 1779 struct ceph_inode_info *ci = ceph_inode(inode);
@@ -1975,11 +1975,6 @@ int ceph_setattr(struct dentry *dentry, struct iattr *attr)
1975 if (inode_dirty_flags) 1975 if (inode_dirty_flags)
1976 __mark_inode_dirty(inode, inode_dirty_flags); 1976 __mark_inode_dirty(inode, inode_dirty_flags);
1977 1977
1978 if (ia_valid & ATTR_MODE) {
1979 err = posix_acl_chmod(inode, attr->ia_mode);
1980 if (err)
1981 goto out_put;
1982 }
1983 1978
1984 if (mask) { 1979 if (mask) {
1985 req->r_inode = inode; 1980 req->r_inode = inode;
@@ -1993,13 +1988,23 @@ int ceph_setattr(struct dentry *dentry, struct iattr *attr)
1993 ceph_cap_string(dirtied), mask); 1988 ceph_cap_string(dirtied), mask);
1994 1989
1995 ceph_mdsc_put_request(req); 1990 ceph_mdsc_put_request(req);
1996 if (mask & CEPH_SETATTR_SIZE)
1997 __ceph_do_pending_vmtruncate(inode);
1998 ceph_free_cap_flush(prealloc_cf); 1991 ceph_free_cap_flush(prealloc_cf);
1992
1993 if (err >= 0 && (mask & CEPH_SETATTR_SIZE))
1994 __ceph_do_pending_vmtruncate(inode);
1995
1999 return err; 1996 return err;
2000out_put: 1997}
2001 ceph_mdsc_put_request(req); 1998
2002 ceph_free_cap_flush(prealloc_cf); 1999int ceph_setattr(struct dentry *dentry, struct iattr *attr)
2000{
2001 int err;
2002
2003 err = __ceph_setattr(dentry, attr);
2004
2005 if (err >= 0 && (attr->ia_valid & ATTR_MODE))
2006 err = posix_acl_chmod(d_inode(dentry), attr->ia_mode);
2007
2003 return err; 2008 return err;
2004} 2009}
2005 2010
diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index 239bc9cba28c..f54f77037d22 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -644,6 +644,9 @@ static void __unregister_request(struct ceph_mds_client *mdsc,
644{ 644{
645 dout("__unregister_request %p tid %lld\n", req, req->r_tid); 645 dout("__unregister_request %p tid %lld\n", req, req->r_tid);
646 646
647 /* Never leave an unregistered request on an unsafe list! */
648 list_del_init(&req->r_unsafe_item);
649
647 if (req->r_tid == mdsc->oldest_tid) { 650 if (req->r_tid == mdsc->oldest_tid) {
648 struct rb_node *p = rb_next(&req->r_node); 651 struct rb_node *p = rb_next(&req->r_node);
649 mdsc->oldest_tid = 0; 652 mdsc->oldest_tid = 0;
@@ -1051,7 +1054,6 @@ static void cleanup_session_requests(struct ceph_mds_client *mdsc,
1051 while (!list_empty(&session->s_unsafe)) { 1054 while (!list_empty(&session->s_unsafe)) {
1052 req = list_first_entry(&session->s_unsafe, 1055 req = list_first_entry(&session->s_unsafe,
1053 struct ceph_mds_request, r_unsafe_item); 1056 struct ceph_mds_request, r_unsafe_item);
1054 list_del_init(&req->r_unsafe_item);
1055 pr_warn_ratelimited(" dropping unsafe request %llu\n", 1057 pr_warn_ratelimited(" dropping unsafe request %llu\n",
1056 req->r_tid); 1058 req->r_tid);
1057 __unregister_request(mdsc, req); 1059 __unregister_request(mdsc, req);
@@ -2477,7 +2479,6 @@ static void handle_reply(struct ceph_mds_session *session, struct ceph_msg *msg)
2477 * useful we could do with a revised return value. 2479 * useful we could do with a revised return value.
2478 */ 2480 */
2479 dout("got safe reply %llu, mds%d\n", tid, mds); 2481 dout("got safe reply %llu, mds%d\n", tid, mds);
2480 list_del_init(&req->r_unsafe_item);
2481 2482
2482 /* last unsafe request during umount? */ 2483 /* last unsafe request during umount? */
2483 if (mdsc->stopping && !__get_oldest_req(mdsc)) 2484 if (mdsc->stopping && !__get_oldest_req(mdsc))
diff --git a/fs/ceph/super.h b/fs/ceph/super.h
index 75b7d125ce66..8c8cb8fe3d32 100644
--- a/fs/ceph/super.h
+++ b/fs/ceph/super.h
@@ -788,6 +788,7 @@ static inline int ceph_do_getattr(struct inode *inode, int mask, bool force)
788 return __ceph_do_getattr(inode, NULL, mask, force); 788 return __ceph_do_getattr(inode, NULL, mask, force);
789} 789}
790extern int ceph_permission(struct inode *inode, int mask); 790extern int ceph_permission(struct inode *inode, int mask);
791extern int __ceph_setattr(struct dentry *dentry, struct iattr *attr);
791extern int ceph_setattr(struct dentry *dentry, struct iattr *attr); 792extern int ceph_setattr(struct dentry *dentry, struct iattr *attr);
792extern int ceph_getattr(struct vfsmount *mnt, struct dentry *dentry, 793extern int ceph_getattr(struct vfsmount *mnt, struct dentry *dentry,
793 struct kstat *stat); 794 struct kstat *stat);
diff --git a/fs/ceph/xattr.c b/fs/ceph/xattr.c
index 819163d8313b..b24275ef97f7 100644
--- a/fs/ceph/xattr.c
+++ b/fs/ceph/xattr.c
@@ -369,6 +369,7 @@ static int __set_xattr(struct ceph_inode_info *ci,
369 369
370 if (update_xattr) { 370 if (update_xattr) {
371 int err = 0; 371 int err = 0;
372
372 if (xattr && (flags & XATTR_CREATE)) 373 if (xattr && (flags & XATTR_CREATE))
373 err = -EEXIST; 374 err = -EEXIST;
374 else if (!xattr && (flags & XATTR_REPLACE)) 375 else if (!xattr && (flags & XATTR_REPLACE))
@@ -376,12 +377,14 @@ static int __set_xattr(struct ceph_inode_info *ci,
376 if (err) { 377 if (err) {
377 kfree(name); 378 kfree(name);
378 kfree(val); 379 kfree(val);
380 kfree(*newxattr);
379 return err; 381 return err;
380 } 382 }
381 if (update_xattr < 0) { 383 if (update_xattr < 0) {
382 if (xattr) 384 if (xattr)
383 __remove_xattr(ci, xattr); 385 __remove_xattr(ci, xattr);
384 kfree(name); 386 kfree(name);
387 kfree(*newxattr);
385 return 0; 388 return 0;
386 } 389 }
387 } 390 }
diff --git a/fs/cifs/cifs_unicode.c b/fs/cifs/cifs_unicode.c
index 02b071bf3732..a0b3e7d1be48 100644
--- a/fs/cifs/cifs_unicode.c
+++ b/fs/cifs/cifs_unicode.c
@@ -83,6 +83,9 @@ convert_sfm_char(const __u16 src_char, char *target)
83 case SFM_COLON: 83 case SFM_COLON:
84 *target = ':'; 84 *target = ':';
85 break; 85 break;
86 case SFM_DOUBLEQUOTE:
87 *target = '"';
88 break;
86 case SFM_ASTERISK: 89 case SFM_ASTERISK:
87 *target = '*'; 90 *target = '*';
88 break; 91 break;
@@ -418,6 +421,9 @@ static __le16 convert_to_sfm_char(char src_char, bool end_of_string)
418 case ':': 421 case ':':
419 dest_char = cpu_to_le16(SFM_COLON); 422 dest_char = cpu_to_le16(SFM_COLON);
420 break; 423 break;
424 case '"':
425 dest_char = cpu_to_le16(SFM_DOUBLEQUOTE);
426 break;
421 case '*': 427 case '*':
422 dest_char = cpu_to_le16(SFM_ASTERISK); 428 dest_char = cpu_to_le16(SFM_ASTERISK);
423 break; 429 break;
diff --git a/fs/cifs/cifs_unicode.h b/fs/cifs/cifs_unicode.h
index 479bc0a941f3..07ade707fa60 100644
--- a/fs/cifs/cifs_unicode.h
+++ b/fs/cifs/cifs_unicode.h
@@ -57,6 +57,7 @@
57 * not conflict (although almost does) with the mapping above. 57 * not conflict (although almost does) with the mapping above.
58 */ 58 */
59 59
60#define SFM_DOUBLEQUOTE ((__u16) 0xF020)
60#define SFM_ASTERISK ((__u16) 0xF021) 61#define SFM_ASTERISK ((__u16) 0xF021)
61#define SFM_QUESTION ((__u16) 0xF025) 62#define SFM_QUESTION ((__u16) 0xF025)
62#define SFM_COLON ((__u16) 0xF022) 63#define SFM_COLON ((__u16) 0xF022)
@@ -64,8 +65,8 @@
64#define SFM_LESSTHAN ((__u16) 0xF023) 65#define SFM_LESSTHAN ((__u16) 0xF023)
65#define SFM_PIPE ((__u16) 0xF027) 66#define SFM_PIPE ((__u16) 0xF027)
66#define SFM_SLASH ((__u16) 0xF026) 67#define SFM_SLASH ((__u16) 0xF026)
67#define SFM_PERIOD ((__u16) 0xF028) 68#define SFM_SPACE ((__u16) 0xF028)
68#define SFM_SPACE ((__u16) 0xF029) 69#define SFM_PERIOD ((__u16) 0xF029)
69 70
70/* 71/*
71 * Mapping mechanism to use when one of the seven reserved characters is 72 * Mapping mechanism to use when one of the seven reserved characters is
diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
index b76883606e4b..e2f6a79e9b01 100644
--- a/fs/cifs/cifsglob.h
+++ b/fs/cifs/cifsglob.h
@@ -227,6 +227,7 @@ struct smb_version_operations {
227 /* verify the message */ 227 /* verify the message */
228 int (*check_message)(char *, unsigned int); 228 int (*check_message)(char *, unsigned int);
229 bool (*is_oplock_break)(char *, struct TCP_Server_Info *); 229 bool (*is_oplock_break)(char *, struct TCP_Server_Info *);
230 int (*handle_cancelled_mid)(char *, struct TCP_Server_Info *);
230 void (*downgrade_oplock)(struct TCP_Server_Info *, 231 void (*downgrade_oplock)(struct TCP_Server_Info *,
231 struct cifsInodeInfo *, bool); 232 struct cifsInodeInfo *, bool);
232 /* process transaction2 response */ 233 /* process transaction2 response */
@@ -906,7 +907,6 @@ struct cifs_tcon {
906 bool use_persistent:1; /* use persistent instead of durable handles */ 907 bool use_persistent:1; /* use persistent instead of durable handles */
907#ifdef CONFIG_CIFS_SMB2 908#ifdef CONFIG_CIFS_SMB2
908 bool print:1; /* set if connection to printer share */ 909 bool print:1; /* set if connection to printer share */
909 bool bad_network_name:1; /* set if ret status STATUS_BAD_NETWORK_NAME */
910 __le32 capabilities; 910 __le32 capabilities;
911 __u32 share_flags; 911 __u32 share_flags;
912 __u32 maximal_access; 912 __u32 maximal_access;
@@ -1290,12 +1290,19 @@ struct mid_q_entry {
1290 void *callback_data; /* general purpose pointer for callback */ 1290 void *callback_data; /* general purpose pointer for callback */
1291 void *resp_buf; /* pointer to received SMB header */ 1291 void *resp_buf; /* pointer to received SMB header */
1292 int mid_state; /* wish this were enum but can not pass to wait_event */ 1292 int mid_state; /* wish this were enum but can not pass to wait_event */
1293 unsigned int mid_flags;
1293 __le16 command; /* smb command code */ 1294 __le16 command; /* smb command code */
1294 bool large_buf:1; /* if valid response, is pointer to large buf */ 1295 bool large_buf:1; /* if valid response, is pointer to large buf */
1295 bool multiRsp:1; /* multiple trans2 responses for one request */ 1296 bool multiRsp:1; /* multiple trans2 responses for one request */
1296 bool multiEnd:1; /* both received */ 1297 bool multiEnd:1; /* both received */
1297}; 1298};
1298 1299
1300struct close_cancelled_open {
1301 struct cifs_fid fid;
1302 struct cifs_tcon *tcon;
1303 struct work_struct work;
1304};
1305
1299/* Make code in transport.c a little cleaner by moving 1306/* Make code in transport.c a little cleaner by moving
1300 update of optional stats into function below */ 1307 update of optional stats into function below */
1301#ifdef CONFIG_CIFS_STATS2 1308#ifdef CONFIG_CIFS_STATS2
@@ -1427,6 +1434,9 @@ static inline void free_dfs_info_array(struct dfs_info3_param *param,
1427#define MID_RESPONSE_MALFORMED 0x10 1434#define MID_RESPONSE_MALFORMED 0x10
1428#define MID_SHUTDOWN 0x20 1435#define MID_SHUTDOWN 0x20
1429 1436
1437/* Flags */
1438#define MID_WAIT_CANCELLED 1 /* Cancelled while waiting for response */
1439
1430/* Types of response buffer returned from SendReceive2 */ 1440/* Types of response buffer returned from SendReceive2 */
1431#define CIFS_NO_BUFFER 0 /* Response buffer not returned */ 1441#define CIFS_NO_BUFFER 0 /* Response buffer not returned */
1432#define CIFS_SMALL_BUFFER 1 1442#define CIFS_SMALL_BUFFER 1
diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
index b1104ed8f54c..b60150e5b5ce 100644
--- a/fs/cifs/cifssmb.c
+++ b/fs/cifs/cifssmb.c
@@ -717,6 +717,9 @@ CIFSSMBEcho(struct TCP_Server_Info *server)
717 if (rc) 717 if (rc)
718 return rc; 718 return rc;
719 719
720 if (server->capabilities & CAP_UNICODE)
721 smb->hdr.Flags2 |= SMBFLG2_UNICODE;
722
720 /* set up echo request */ 723 /* set up echo request */
721 smb->hdr.Tid = 0xffff; 724 smb->hdr.Tid = 0xffff;
722 smb->hdr.WordCount = 1; 725 smb->hdr.WordCount = 1;
@@ -1424,6 +1427,8 @@ cifs_readv_discard(struct TCP_Server_Info *server, struct mid_q_entry *mid)
1424 1427
1425 length = discard_remaining_data(server); 1428 length = discard_remaining_data(server);
1426 dequeue_mid(mid, rdata->result); 1429 dequeue_mid(mid, rdata->result);
1430 mid->resp_buf = server->smallbuf;
1431 server->smallbuf = NULL;
1427 return length; 1432 return length;
1428} 1433}
1429 1434
@@ -1538,6 +1543,8 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid)
1538 return cifs_readv_discard(server, mid); 1543 return cifs_readv_discard(server, mid);
1539 1544
1540 dequeue_mid(mid, false); 1545 dequeue_mid(mid, false);
1546 mid->resp_buf = server->smallbuf;
1547 server->smallbuf = NULL;
1541 return length; 1548 return length;
1542} 1549}
1543 1550
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index 5d59f25521ce..53a827c6d8b1 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -412,6 +412,9 @@ cifs_reconnect(struct TCP_Server_Info *server)
412 } 412 }
413 } while (server->tcpStatus == CifsNeedReconnect); 413 } while (server->tcpStatus == CifsNeedReconnect);
414 414
415 if (server->tcpStatus == CifsNeedNegotiate)
416 mod_delayed_work(cifsiod_wq, &server->echo, 0);
417
415 return rc; 418 return rc;
416} 419}
417 420
@@ -421,18 +424,27 @@ cifs_echo_request(struct work_struct *work)
421 int rc; 424 int rc;
422 struct TCP_Server_Info *server = container_of(work, 425 struct TCP_Server_Info *server = container_of(work,
423 struct TCP_Server_Info, echo.work); 426 struct TCP_Server_Info, echo.work);
427 unsigned long echo_interval;
424 428
425 /* 429 /*
426 * We cannot send an echo if it is disabled or until the 430 * If we need to renegotiate, set echo interval to zero to
427 * NEGOTIATE_PROTOCOL request is done, which is indicated by 431 * immediately call echo service where we can renegotiate.
428 * server->ops->need_neg() == true. Also, no need to ping if 432 */
429 * we got a response recently. 433 if (server->tcpStatus == CifsNeedNegotiate)
434 echo_interval = 0;
435 else
436 echo_interval = SMB_ECHO_INTERVAL;
437
438 /*
439 * We cannot send an echo if it is disabled.
440 * Also, no need to ping if we got a response recently.
430 */ 441 */
431 442
432 if (server->tcpStatus == CifsNeedReconnect || 443 if (server->tcpStatus == CifsNeedReconnect ||
433 server->tcpStatus == CifsExiting || server->tcpStatus == CifsNew || 444 server->tcpStatus == CifsExiting ||
445 server->tcpStatus == CifsNew ||
434 (server->ops->can_echo && !server->ops->can_echo(server)) || 446 (server->ops->can_echo && !server->ops->can_echo(server)) ||
435 time_before(jiffies, server->lstrp + SMB_ECHO_INTERVAL - HZ)) 447 time_before(jiffies, server->lstrp + echo_interval - HZ))
436 goto requeue_echo; 448 goto requeue_echo;
437 449
438 rc = server->ops->echo ? server->ops->echo(server) : -ENOSYS; 450 rc = server->ops->echo ? server->ops->echo(server) : -ENOSYS;
@@ -924,10 +936,19 @@ cifs_demultiplex_thread(void *p)
924 936
925 server->lstrp = jiffies; 937 server->lstrp = jiffies;
926 if (mid_entry != NULL) { 938 if (mid_entry != NULL) {
939 if ((mid_entry->mid_flags & MID_WAIT_CANCELLED) &&
940 mid_entry->mid_state == MID_RESPONSE_RECEIVED &&
941 server->ops->handle_cancelled_mid)
942 server->ops->handle_cancelled_mid(
943 mid_entry->resp_buf,
944 server);
945
927 if (!mid_entry->multiRsp || mid_entry->multiEnd) 946 if (!mid_entry->multiRsp || mid_entry->multiEnd)
928 mid_entry->callback(mid_entry); 947 mid_entry->callback(mid_entry);
929 } else if (!server->ops->is_oplock_break || 948 } else if (server->ops->is_oplock_break &&
930 !server->ops->is_oplock_break(buf, server)) { 949 server->ops->is_oplock_break(buf, server)) {
950 cifs_dbg(FYI, "Received oplock break\n");
951 } else {
931 cifs_dbg(VFS, "No task to wake, unknown frame received! NumMids %d\n", 952 cifs_dbg(VFS, "No task to wake, unknown frame received! NumMids %d\n",
932 atomic_read(&midCount)); 953 atomic_read(&midCount));
933 cifs_dump_mem("Received Data is: ", buf, 954 cifs_dump_mem("Received Data is: ", buf,
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index 72f270d4bd17..a0c0a49b6620 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -2545,7 +2545,7 @@ cifs_write_from_iter(loff_t offset, size_t len, struct iov_iter *from,
2545 wdata->credits = credits; 2545 wdata->credits = credits;
2546 2546
2547 if (!wdata->cfile->invalidHandle || 2547 if (!wdata->cfile->invalidHandle ||
2548 !cifs_reopen_file(wdata->cfile, false)) 2548 !(rc = cifs_reopen_file(wdata->cfile, false)))
2549 rc = server->ops->async_writev(wdata, 2549 rc = server->ops->async_writev(wdata,
2550 cifs_uncached_writedata_release); 2550 cifs_uncached_writedata_release);
2551 if (rc) { 2551 if (rc) {
@@ -2958,7 +2958,7 @@ cifs_send_async_read(loff_t offset, size_t len, struct cifsFileInfo *open_file,
2958 rdata->credits = credits; 2958 rdata->credits = credits;
2959 2959
2960 if (!rdata->cfile->invalidHandle || 2960 if (!rdata->cfile->invalidHandle ||
2961 !cifs_reopen_file(rdata->cfile, true)) 2961 !(rc = cifs_reopen_file(rdata->cfile, true)))
2962 rc = server->ops->async_readv(rdata); 2962 rc = server->ops->async_readv(rdata);
2963error: 2963error:
2964 if (rc) { 2964 if (rc) {
@@ -3544,7 +3544,7 @@ static int cifs_readpages(struct file *file, struct address_space *mapping,
3544 } 3544 }
3545 3545
3546 if (!rdata->cfile->invalidHandle || 3546 if (!rdata->cfile->invalidHandle ||
3547 !cifs_reopen_file(rdata->cfile, true)) 3547 !(rc = cifs_reopen_file(rdata->cfile, true)))
3548 rc = server->ops->async_readv(rdata); 3548 rc = server->ops->async_readv(rdata);
3549 if (rc) { 3549 if (rc) {
3550 add_credits_and_wake_if(server, rdata->credits, 0); 3550 add_credits_and_wake_if(server, rdata->credits, 0);
diff --git a/fs/cifs/ioctl.c b/fs/cifs/ioctl.c
index 35cf990f87d3..a8f5b31636dc 100644
--- a/fs/cifs/ioctl.c
+++ b/fs/cifs/ioctl.c
@@ -272,6 +272,8 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)
272 rc = -EOPNOTSUPP; 272 rc = -EOPNOTSUPP;
273 break; 273 break;
274 case CIFS_IOC_GET_MNT_INFO: 274 case CIFS_IOC_GET_MNT_INFO:
275 if (pSMBFile == NULL)
276 break;
275 tcon = tlink_tcon(pSMBFile->tlink); 277 tcon = tlink_tcon(pSMBFile->tlink);
276 rc = smb_mnt_get_fsinfo(xid, tcon, (void __user *)arg); 278 rc = smb_mnt_get_fsinfo(xid, tcon, (void __user *)arg);
277 break; 279 break;
diff --git a/fs/cifs/readdir.c b/fs/cifs/readdir.c
index 833e5844a2db..97d1a15873c5 100644
--- a/fs/cifs/readdir.c
+++ b/fs/cifs/readdir.c
@@ -282,6 +282,7 @@ initiate_cifs_search(const unsigned int xid, struct file *file)
282 rc = -ENOMEM; 282 rc = -ENOMEM;
283 goto error_exit; 283 goto error_exit;
284 } 284 }
285 spin_lock_init(&cifsFile->file_info_lock);
285 file->private_data = cifsFile; 286 file->private_data = cifsFile;
286 cifsFile->tlink = cifs_get_tlink(tlink); 287 cifsFile->tlink = cifs_get_tlink(tlink);
287 tcon = tlink_tcon(tlink); 288 tcon = tlink_tcon(tlink);
diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
index fc537c29044e..efd72e1fae74 100644
--- a/fs/cifs/smb1ops.c
+++ b/fs/cifs/smb1ops.c
@@ -849,8 +849,13 @@ cifs_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
849 struct cifs_fid *fid, __u16 search_flags, 849 struct cifs_fid *fid, __u16 search_flags,
850 struct cifs_search_info *srch_inf) 850 struct cifs_search_info *srch_inf)
851{ 851{
852 return CIFSFindFirst(xid, tcon, path, cifs_sb, 852 int rc;
853 &fid->netfid, search_flags, srch_inf, true); 853
854 rc = CIFSFindFirst(xid, tcon, path, cifs_sb,
855 &fid->netfid, search_flags, srch_inf, true);
856 if (rc)
857 cifs_dbg(FYI, "find first failed=%d\n", rc);
858 return rc;
854} 859}
855 860
856static int 861static int
@@ -1015,6 +1020,15 @@ cifs_dir_needs_close(struct cifsFileInfo *cfile)
1015 return !cfile->srch_inf.endOfSearch && !cfile->invalidHandle; 1020 return !cfile->srch_inf.endOfSearch && !cfile->invalidHandle;
1016} 1021}
1017 1022
1023static bool
1024cifs_can_echo(struct TCP_Server_Info *server)
1025{
1026 if (server->tcpStatus == CifsGood)
1027 return true;
1028
1029 return false;
1030}
1031
1018struct smb_version_operations smb1_operations = { 1032struct smb_version_operations smb1_operations = {
1019 .send_cancel = send_nt_cancel, 1033 .send_cancel = send_nt_cancel,
1020 .compare_fids = cifs_compare_fids, 1034 .compare_fids = cifs_compare_fids,
@@ -1049,6 +1063,7 @@ struct smb_version_operations smb1_operations = {
1049 .get_dfs_refer = CIFSGetDFSRefer, 1063 .get_dfs_refer = CIFSGetDFSRefer,
1050 .qfs_tcon = cifs_qfs_tcon, 1064 .qfs_tcon = cifs_qfs_tcon,
1051 .is_path_accessible = cifs_is_path_accessible, 1065 .is_path_accessible = cifs_is_path_accessible,
1066 .can_echo = cifs_can_echo,
1052 .query_path_info = cifs_query_path_info, 1067 .query_path_info = cifs_query_path_info,
1053 .query_file_info = cifs_query_file_info, 1068 .query_file_info = cifs_query_file_info,
1054 .get_srv_inum = cifs_get_srv_inum, 1069 .get_srv_inum = cifs_get_srv_inum,
diff --git a/fs/cifs/smb2misc.c b/fs/cifs/smb2misc.c
index e5bc85e49be7..76ccf20fbfb7 100644
--- a/fs/cifs/smb2misc.c
+++ b/fs/cifs/smb2misc.c
@@ -630,3 +630,47 @@ smb2_is_valid_oplock_break(char *buffer, struct TCP_Server_Info *server)
630 cifs_dbg(FYI, "Can not process oplock break for non-existent connection\n"); 630 cifs_dbg(FYI, "Can not process oplock break for non-existent connection\n");
631 return false; 631 return false;
632} 632}
633
634void
635smb2_cancelled_close_fid(struct work_struct *work)
636{
637 struct close_cancelled_open *cancelled = container_of(work,
638 struct close_cancelled_open, work);
639
640 cifs_dbg(VFS, "Close unmatched open\n");
641
642 SMB2_close(0, cancelled->tcon, cancelled->fid.persistent_fid,
643 cancelled->fid.volatile_fid);
644 cifs_put_tcon(cancelled->tcon);
645 kfree(cancelled);
646}
647
648int
649smb2_handle_cancelled_mid(char *buffer, struct TCP_Server_Info *server)
650{
651 struct smb2_hdr *hdr = (struct smb2_hdr *)buffer;
652 struct smb2_create_rsp *rsp = (struct smb2_create_rsp *)buffer;
653 struct cifs_tcon *tcon;
654 struct close_cancelled_open *cancelled;
655
656 if (hdr->Command != SMB2_CREATE || hdr->Status != STATUS_SUCCESS)
657 return 0;
658
659 cancelled = kzalloc(sizeof(*cancelled), GFP_KERNEL);
660 if (!cancelled)
661 return -ENOMEM;
662
663 tcon = smb2_find_smb_tcon(server, hdr->SessionId, hdr->TreeId);
664 if (!tcon) {
665 kfree(cancelled);
666 return -ENOENT;
667 }
668
669 cancelled->fid.persistent_fid = rsp->PersistentFileId;
670 cancelled->fid.volatile_fid = rsp->VolatileFileId;
671 cancelled->tcon = tcon;
672 INIT_WORK(&cancelled->work, smb2_cancelled_close_fid);
673 queue_work(cifsiod_wq, &cancelled->work);
674
675 return 0;
676}
diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
index be34b4860675..1d125d3d0d89 100644
--- a/fs/cifs/smb2ops.c
+++ b/fs/cifs/smb2ops.c
@@ -909,7 +909,7 @@ smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
909 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL); 909 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
910 kfree(utf16_path); 910 kfree(utf16_path);
911 if (rc) { 911 if (rc) {
912 cifs_dbg(VFS, "open dir failed\n"); 912 cifs_dbg(FYI, "open dir failed rc=%d\n", rc);
913 return rc; 913 return rc;
914 } 914 }
915 915
@@ -919,7 +919,7 @@ smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
919 rc = SMB2_query_directory(xid, tcon, fid->persistent_fid, 919 rc = SMB2_query_directory(xid, tcon, fid->persistent_fid,
920 fid->volatile_fid, 0, srch_inf); 920 fid->volatile_fid, 0, srch_inf);
921 if (rc) { 921 if (rc) {
922 cifs_dbg(VFS, "query directory failed\n"); 922 cifs_dbg(FYI, "query directory failed rc=%d\n", rc);
923 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); 923 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
924 } 924 }
925 return rc; 925 return rc;
@@ -1511,6 +1511,7 @@ struct smb_version_operations smb20_operations = {
1511 .clear_stats = smb2_clear_stats, 1511 .clear_stats = smb2_clear_stats,
1512 .print_stats = smb2_print_stats, 1512 .print_stats = smb2_print_stats,
1513 .is_oplock_break = smb2_is_valid_oplock_break, 1513 .is_oplock_break = smb2_is_valid_oplock_break,
1514 .handle_cancelled_mid = smb2_handle_cancelled_mid,
1514 .downgrade_oplock = smb2_downgrade_oplock, 1515 .downgrade_oplock = smb2_downgrade_oplock,
1515 .need_neg = smb2_need_neg, 1516 .need_neg = smb2_need_neg,
1516 .negotiate = smb2_negotiate, 1517 .negotiate = smb2_negotiate,
@@ -1589,6 +1590,7 @@ struct smb_version_operations smb21_operations = {
1589 .clear_stats = smb2_clear_stats, 1590 .clear_stats = smb2_clear_stats,
1590 .print_stats = smb2_print_stats, 1591 .print_stats = smb2_print_stats,
1591 .is_oplock_break = smb2_is_valid_oplock_break, 1592 .is_oplock_break = smb2_is_valid_oplock_break,
1593 .handle_cancelled_mid = smb2_handle_cancelled_mid,
1592 .downgrade_oplock = smb2_downgrade_oplock, 1594 .downgrade_oplock = smb2_downgrade_oplock,
1593 .need_neg = smb2_need_neg, 1595 .need_neg = smb2_need_neg,
1594 .negotiate = smb2_negotiate, 1596 .negotiate = smb2_negotiate,
@@ -1670,6 +1672,7 @@ struct smb_version_operations smb30_operations = {
1670 .print_stats = smb2_print_stats, 1672 .print_stats = smb2_print_stats,
1671 .dump_share_caps = smb2_dump_share_caps, 1673 .dump_share_caps = smb2_dump_share_caps,
1672 .is_oplock_break = smb2_is_valid_oplock_break, 1674 .is_oplock_break = smb2_is_valid_oplock_break,
1675 .handle_cancelled_mid = smb2_handle_cancelled_mid,
1673 .downgrade_oplock = smb2_downgrade_oplock, 1676 .downgrade_oplock = smb2_downgrade_oplock,
1674 .need_neg = smb2_need_neg, 1677 .need_neg = smb2_need_neg,
1675 .negotiate = smb2_negotiate, 1678 .negotiate = smb2_negotiate,
@@ -1757,6 +1760,7 @@ struct smb_version_operations smb311_operations = {
1757 .print_stats = smb2_print_stats, 1760 .print_stats = smb2_print_stats,
1758 .dump_share_caps = smb2_dump_share_caps, 1761 .dump_share_caps = smb2_dump_share_caps,
1759 .is_oplock_break = smb2_is_valid_oplock_break, 1762 .is_oplock_break = smb2_is_valid_oplock_break,
1763 .handle_cancelled_mid = smb2_handle_cancelled_mid,
1760 .downgrade_oplock = smb2_downgrade_oplock, 1764 .downgrade_oplock = smb2_downgrade_oplock,
1761 .need_neg = smb2_need_neg, 1765 .need_neg = smb2_need_neg,
1762 .negotiate = smb2_negotiate, 1766 .negotiate = smb2_negotiate,
diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
index 2fa754c5fd62..f4afa3b1cc56 100644
--- a/fs/cifs/smb2pdu.c
+++ b/fs/cifs/smb2pdu.c
@@ -564,8 +564,12 @@ int smb3_validate_negotiate(const unsigned int xid, struct cifs_tcon *tcon)
564 } 564 }
565 565
566 if (rsplen != sizeof(struct validate_negotiate_info_rsp)) { 566 if (rsplen != sizeof(struct validate_negotiate_info_rsp)) {
567 cifs_dbg(VFS, "invalid size of protocol negotiate response\n"); 567 cifs_dbg(VFS, "invalid protocol negotiate response size: %d\n",
568 return -EIO; 568 rsplen);
569
570 /* relax check since Mac returns max bufsize allowed on ioctl */
571 if (rsplen > CIFSMaxBufSize)
572 return -EIO;
569 } 573 }
570 574
571 /* check validate negotiate info response matches what we got earlier */ 575 /* check validate negotiate info response matches what we got earlier */
@@ -932,9 +936,6 @@ SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree,
932 else 936 else
933 return -EIO; 937 return -EIO;
934 938
935 if (tcon && tcon->bad_network_name)
936 return -ENOENT;
937
938 if ((tcon && tcon->seal) && 939 if ((tcon && tcon->seal) &&
939 ((ses->server->capabilities & SMB2_GLOBAL_CAP_ENCRYPTION) == 0)) { 940 ((ses->server->capabilities & SMB2_GLOBAL_CAP_ENCRYPTION) == 0)) {
940 cifs_dbg(VFS, "encryption requested but no server support"); 941 cifs_dbg(VFS, "encryption requested but no server support");
@@ -952,6 +953,10 @@ SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree,
952 return -EINVAL; 953 return -EINVAL;
953 } 954 }
954 955
956 /* SMB2 TREE_CONNECT request must be called with TreeId == 0 */
957 if (tcon)
958 tcon->tid = 0;
959
955 rc = small_smb2_init(SMB2_TREE_CONNECT, tcon, (void **) &req); 960 rc = small_smb2_init(SMB2_TREE_CONNECT, tcon, (void **) &req);
956 if (rc) { 961 if (rc) {
957 kfree(unc_path); 962 kfree(unc_path);
@@ -1032,8 +1037,6 @@ tcon_exit:
1032tcon_error_exit: 1037tcon_error_exit:
1033 if (rsp->hdr.Status == STATUS_BAD_NETWORK_NAME) { 1038 if (rsp->hdr.Status == STATUS_BAD_NETWORK_NAME) {
1034 cifs_dbg(VFS, "BAD_NETWORK_NAME: %s\n", tree); 1039 cifs_dbg(VFS, "BAD_NETWORK_NAME: %s\n", tree);
1035 if (tcon)
1036 tcon->bad_network_name = true;
1037 } 1040 }
1038 goto tcon_exit; 1041 goto tcon_exit;
1039} 1042}
@@ -1519,8 +1522,12 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
1519 * than one credit. Windows typically sets this smaller, but for some 1522 * than one credit. Windows typically sets this smaller, but for some
1520 * ioctls it may be useful to allow server to send more. No point 1523 * ioctls it may be useful to allow server to send more. No point
1521 * limiting what the server can send as long as fits in one credit 1524 * limiting what the server can send as long as fits in one credit
1525 * Unfortunately - we can not handle more than CIFS_MAX_MSG_SIZE
1526 * (by default, note that it can be overridden to make max larger)
1527 * in responses (except for read responses which can be bigger.
1528 * We may want to bump this limit up
1522 */ 1529 */
1523 req->MaxOutputResponse = cpu_to_le32(0xFF00); /* < 64K uses 1 credit */ 1530 req->MaxOutputResponse = cpu_to_le32(CIFSMaxBufSize);
1524 1531
1525 if (is_fsctl) 1532 if (is_fsctl)
1526 req->Flags = cpu_to_le32(SMB2_0_IOCTL_IS_FSCTL); 1533 req->Flags = cpu_to_le32(SMB2_0_IOCTL_IS_FSCTL);
diff --git a/fs/cifs/smb2proto.h b/fs/cifs/smb2proto.h
index 0a406ae78129..adc5234486c3 100644
--- a/fs/cifs/smb2proto.h
+++ b/fs/cifs/smb2proto.h
@@ -47,6 +47,10 @@ extern struct mid_q_entry *smb2_setup_request(struct cifs_ses *ses,
47 struct smb_rqst *rqst); 47 struct smb_rqst *rqst);
48extern struct mid_q_entry *smb2_setup_async_request( 48extern struct mid_q_entry *smb2_setup_async_request(
49 struct TCP_Server_Info *server, struct smb_rqst *rqst); 49 struct TCP_Server_Info *server, struct smb_rqst *rqst);
50extern struct cifs_ses *smb2_find_smb_ses(struct TCP_Server_Info *server,
51 __u64 ses_id);
52extern struct cifs_tcon *smb2_find_smb_tcon(struct TCP_Server_Info *server,
53 __u64 ses_id, __u32 tid);
50extern int smb2_calc_signature(struct smb_rqst *rqst, 54extern int smb2_calc_signature(struct smb_rqst *rqst,
51 struct TCP_Server_Info *server); 55 struct TCP_Server_Info *server);
52extern int smb3_calc_signature(struct smb_rqst *rqst, 56extern int smb3_calc_signature(struct smb_rqst *rqst,
@@ -157,6 +161,9 @@ extern int SMB2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
157extern int SMB2_oplock_break(const unsigned int xid, struct cifs_tcon *tcon, 161extern int SMB2_oplock_break(const unsigned int xid, struct cifs_tcon *tcon,
158 const u64 persistent_fid, const u64 volatile_fid, 162 const u64 persistent_fid, const u64 volatile_fid,
159 const __u8 oplock_level); 163 const __u8 oplock_level);
164extern int smb2_handle_cancelled_mid(char *buffer,
165 struct TCP_Server_Info *server);
166void smb2_cancelled_close_fid(struct work_struct *work);
160extern int SMB2_QFS_info(const unsigned int xid, struct cifs_tcon *tcon, 167extern int SMB2_QFS_info(const unsigned int xid, struct cifs_tcon *tcon,
161 u64 persistent_file_id, u64 volatile_file_id, 168 u64 persistent_file_id, u64 volatile_file_id,
162 struct kstatfs *FSData); 169 struct kstatfs *FSData);
diff --git a/fs/cifs/smb2transport.c b/fs/cifs/smb2transport.c
index d4c5b6f109a7..69e3b322bbfe 100644
--- a/fs/cifs/smb2transport.c
+++ b/fs/cifs/smb2transport.c
@@ -115,22 +115,68 @@ smb3_crypto_shash_allocate(struct TCP_Server_Info *server)
115} 115}
116 116
117static struct cifs_ses * 117static struct cifs_ses *
118smb2_find_smb_ses(struct smb2_hdr *smb2hdr, struct TCP_Server_Info *server) 118smb2_find_smb_ses_unlocked(struct TCP_Server_Info *server, __u64 ses_id)
119{ 119{
120 struct cifs_ses *ses; 120 struct cifs_ses *ses;
121 121
122 spin_lock(&cifs_tcp_ses_lock);
123 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) { 122 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
124 if (ses->Suid != smb2hdr->SessionId) 123 if (ses->Suid != ses_id)
125 continue; 124 continue;
126 spin_unlock(&cifs_tcp_ses_lock);
127 return ses; 125 return ses;
128 } 126 }
127
128 return NULL;
129}
130
131struct cifs_ses *
132smb2_find_smb_ses(struct TCP_Server_Info *server, __u64 ses_id)
133{
134 struct cifs_ses *ses;
135
136 spin_lock(&cifs_tcp_ses_lock);
137 ses = smb2_find_smb_ses_unlocked(server, ses_id);
129 spin_unlock(&cifs_tcp_ses_lock); 138 spin_unlock(&cifs_tcp_ses_lock);
130 139
140 return ses;
141}
142
143static struct cifs_tcon *
144smb2_find_smb_sess_tcon_unlocked(struct cifs_ses *ses, __u32 tid)
145{
146 struct cifs_tcon *tcon;
147
148 list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
149 if (tcon->tid != tid)
150 continue;
151 ++tcon->tc_count;
152 return tcon;
153 }
154
131 return NULL; 155 return NULL;
132} 156}
133 157
158/*
159 * Obtain tcon corresponding to the tid in the given
160 * cifs_ses
161 */
162
163struct cifs_tcon *
164smb2_find_smb_tcon(struct TCP_Server_Info *server, __u64 ses_id, __u32 tid)
165{
166 struct cifs_ses *ses;
167 struct cifs_tcon *tcon;
168
169 spin_lock(&cifs_tcp_ses_lock);
170 ses = smb2_find_smb_ses_unlocked(server, ses_id);
171 if (!ses) {
172 spin_unlock(&cifs_tcp_ses_lock);
173 return NULL;
174 }
175 tcon = smb2_find_smb_sess_tcon_unlocked(ses, tid);
176 spin_unlock(&cifs_tcp_ses_lock);
177
178 return tcon;
179}
134 180
135int 181int
136smb2_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server) 182smb2_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
@@ -143,7 +189,7 @@ smb2_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
143 struct smb2_hdr *smb2_pdu = (struct smb2_hdr *)iov[0].iov_base; 189 struct smb2_hdr *smb2_pdu = (struct smb2_hdr *)iov[0].iov_base;
144 struct cifs_ses *ses; 190 struct cifs_ses *ses;
145 191
146 ses = smb2_find_smb_ses(smb2_pdu, server); 192 ses = smb2_find_smb_ses(server, smb2_pdu->SessionId);
147 if (!ses) { 193 if (!ses) {
148 cifs_dbg(VFS, "%s: Could not find session\n", __func__); 194 cifs_dbg(VFS, "%s: Could not find session\n", __func__);
149 return 0; 195 return 0;
@@ -314,7 +360,7 @@ smb3_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
314 struct smb2_hdr *smb2_pdu = (struct smb2_hdr *)iov[0].iov_base; 360 struct smb2_hdr *smb2_pdu = (struct smb2_hdr *)iov[0].iov_base;
315 struct cifs_ses *ses; 361 struct cifs_ses *ses;
316 362
317 ses = smb2_find_smb_ses(smb2_pdu, server); 363 ses = smb2_find_smb_ses(server, smb2_pdu->SessionId);
318 if (!ses) { 364 if (!ses) {
319 cifs_dbg(VFS, "%s: Could not find session\n", __func__); 365 cifs_dbg(VFS, "%s: Could not find session\n", __func__);
320 return 0; 366 return 0;
diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c
index 87abe8ed074c..54af10204e83 100644
--- a/fs/cifs/transport.c
+++ b/fs/cifs/transport.c
@@ -786,9 +786,11 @@ SendReceive2(const unsigned int xid, struct cifs_ses *ses,
786 786
787 rc = wait_for_response(ses->server, midQ); 787 rc = wait_for_response(ses->server, midQ);
788 if (rc != 0) { 788 if (rc != 0) {
789 cifs_dbg(FYI, "Cancelling wait for mid %llu\n", midQ->mid);
789 send_cancel(ses->server, buf, midQ); 790 send_cancel(ses->server, buf, midQ);
790 spin_lock(&GlobalMid_Lock); 791 spin_lock(&GlobalMid_Lock);
791 if (midQ->mid_state == MID_REQUEST_SUBMITTED) { 792 if (midQ->mid_state == MID_REQUEST_SUBMITTED) {
793 midQ->mid_flags |= MID_WAIT_CANCELLED;
792 midQ->callback = DeleteMidQEntry; 794 midQ->callback = DeleteMidQEntry;
793 spin_unlock(&GlobalMid_Lock); 795 spin_unlock(&GlobalMid_Lock);
794 cifs_small_buf_release(buf); 796 cifs_small_buf_release(buf);
diff --git a/fs/configfs/symlink.c b/fs/configfs/symlink.c
index ec5c8325b503..0525ebc3aea2 100644
--- a/fs/configfs/symlink.c
+++ b/fs/configfs/symlink.c
@@ -83,14 +83,13 @@ static int create_link(struct config_item *parent_item,
83 ret = -ENOMEM; 83 ret = -ENOMEM;
84 sl = kmalloc(sizeof(struct configfs_symlink), GFP_KERNEL); 84 sl = kmalloc(sizeof(struct configfs_symlink), GFP_KERNEL);
85 if (sl) { 85 if (sl) {
86 sl->sl_target = config_item_get(item);
87 spin_lock(&configfs_dirent_lock); 86 spin_lock(&configfs_dirent_lock);
88 if (target_sd->s_type & CONFIGFS_USET_DROPPING) { 87 if (target_sd->s_type & CONFIGFS_USET_DROPPING) {
89 spin_unlock(&configfs_dirent_lock); 88 spin_unlock(&configfs_dirent_lock);
90 config_item_put(item);
91 kfree(sl); 89 kfree(sl);
92 return -ENOENT; 90 return -ENOENT;
93 } 91 }
92 sl->sl_target = config_item_get(item);
94 list_add(&sl->sl_list, &target_sd->s_links); 93 list_add(&sl->sl_list, &target_sd->s_links);
95 spin_unlock(&configfs_dirent_lock); 94 spin_unlock(&configfs_dirent_lock);
96 ret = configfs_create_link(sl, parent_item->ci_dentry, 95 ret = configfs_create_link(sl, parent_item->ci_dentry,
diff --git a/fs/coredump.c b/fs/coredump.c
index 5d15c4975ba1..2ce5ef429c48 100644
--- a/fs/coredump.c
+++ b/fs/coredump.c
@@ -720,7 +720,7 @@ void do_coredump(const siginfo_t *siginfo)
720 goto close_fail; 720 goto close_fail;
721 if (!(cprm.file->f_mode & FMODE_CAN_WRITE)) 721 if (!(cprm.file->f_mode & FMODE_CAN_WRITE))
722 goto close_fail; 722 goto close_fail;
723 if (do_truncate(cprm.file->f_path.dentry, 0, 0, cprm.file)) 723 if (do_truncate2(cprm.file->f_path.mnt, cprm.file->f_path.dentry, 0, 0, cprm.file))
724 goto close_fail; 724 goto close_fail;
725 } 725 }
726 726
@@ -810,3 +810,21 @@ int dump_align(struct coredump_params *cprm, int align)
810 return mod ? dump_skip(cprm, align - mod) : 1; 810 return mod ? dump_skip(cprm, align - mod) : 1;
811} 811}
812EXPORT_SYMBOL(dump_align); 812EXPORT_SYMBOL(dump_align);
813
814/*
815 * Ensures that file size is big enough to contain the current file
816 * postion. This prevents gdb from complaining about a truncated file
817 * if the last "write" to the file was dump_skip.
818 */
819void dump_truncate(struct coredump_params *cprm)
820{
821 struct file *file = cprm->file;
822 loff_t offset;
823
824 if (file->f_op->llseek && file->f_op->llseek != no_llseek) {
825 offset = file->f_op->llseek(file, 0, SEEK_CUR);
826 if (i_size_read(file->f_mapping->host) < offset)
827 do_truncate(file->f_path.dentry, offset, 0, file);
828 }
829}
830EXPORT_SYMBOL(dump_truncate);
diff --git a/fs/dcache.c b/fs/dcache.c
index 7b8feb6d60c8..5bf7b4a188e9 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -269,6 +269,33 @@ static inline int dname_external(const struct dentry *dentry)
269 return dentry->d_name.name != dentry->d_iname; 269 return dentry->d_name.name != dentry->d_iname;
270} 270}
271 271
272void take_dentry_name_snapshot(struct name_snapshot *name, struct dentry *dentry)
273{
274 spin_lock(&dentry->d_lock);
275 if (unlikely(dname_external(dentry))) {
276 struct external_name *p = external_name(dentry);
277 atomic_inc(&p->u.count);
278 spin_unlock(&dentry->d_lock);
279 name->name = p->name;
280 } else {
281 memcpy(name->inline_name, dentry->d_iname, DNAME_INLINE_LEN);
282 spin_unlock(&dentry->d_lock);
283 name->name = name->inline_name;
284 }
285}
286EXPORT_SYMBOL(take_dentry_name_snapshot);
287
288void release_dentry_name_snapshot(struct name_snapshot *name)
289{
290 if (unlikely(name->name != name->inline_name)) {
291 struct external_name *p;
292 p = container_of(name->name, struct external_name, name[0]);
293 if (unlikely(atomic_dec_and_test(&p->u.count)))
294 kfree_rcu(p, u.head);
295 }
296}
297EXPORT_SYMBOL(release_dentry_name_snapshot);
298
272static inline void __d_set_inode_and_type(struct dentry *dentry, 299static inline void __d_set_inode_and_type(struct dentry *dentry,
273 struct inode *inode, 300 struct inode *inode,
274 unsigned type_flags) 301 unsigned type_flags)
@@ -1128,11 +1155,12 @@ void shrink_dcache_sb(struct super_block *sb)
1128 LIST_HEAD(dispose); 1155 LIST_HEAD(dispose);
1129 1156
1130 freed = list_lru_walk(&sb->s_dentry_lru, 1157 freed = list_lru_walk(&sb->s_dentry_lru,
1131 dentry_lru_isolate_shrink, &dispose, UINT_MAX); 1158 dentry_lru_isolate_shrink, &dispose, 1024);
1132 1159
1133 this_cpu_sub(nr_dentry_unused, freed); 1160 this_cpu_sub(nr_dentry_unused, freed);
1134 shrink_dentry_list(&dispose); 1161 shrink_dentry_list(&dispose);
1135 } while (freed > 0); 1162 cond_resched();
1163 } while (list_lru_count(&sb->s_dentry_lru) > 0);
1136} 1164}
1137EXPORT_SYMBOL(shrink_dcache_sb); 1165EXPORT_SYMBOL(shrink_dcache_sb);
1138 1166
diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
index 0f5d05bf2131..e49ba072bd64 100644
--- a/fs/debugfs/inode.c
+++ b/fs/debugfs/inode.c
@@ -669,7 +669,7 @@ struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,
669{ 669{
670 int error; 670 int error;
671 struct dentry *dentry = NULL, *trap; 671 struct dentry *dentry = NULL, *trap;
672 const char *old_name; 672 struct name_snapshot old_name;
673 673
674 trap = lock_rename(new_dir, old_dir); 674 trap = lock_rename(new_dir, old_dir);
675 /* Source or destination directories don't exist? */ 675 /* Source or destination directories don't exist? */
@@ -684,19 +684,19 @@ struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,
684 if (IS_ERR(dentry) || dentry == trap || d_really_is_positive(dentry)) 684 if (IS_ERR(dentry) || dentry == trap || d_really_is_positive(dentry))
685 goto exit; 685 goto exit;
686 686
687 old_name = fsnotify_oldname_init(old_dentry->d_name.name); 687 take_dentry_name_snapshot(&old_name, old_dentry);
688 688
689 error = simple_rename(d_inode(old_dir), old_dentry, d_inode(new_dir), 689 error = simple_rename(d_inode(old_dir), old_dentry, d_inode(new_dir),
690 dentry); 690 dentry);
691 if (error) { 691 if (error) {
692 fsnotify_oldname_free(old_name); 692 release_dentry_name_snapshot(&old_name);
693 goto exit; 693 goto exit;
694 } 694 }
695 d_move(old_dentry, dentry); 695 d_move(old_dentry, dentry);
696 fsnotify_move(d_inode(old_dir), d_inode(new_dir), old_name, 696 fsnotify_move(d_inode(old_dir), d_inode(new_dir), old_name.name,
697 d_is_dir(old_dentry), 697 d_is_dir(old_dentry),
698 NULL, old_dentry); 698 NULL, old_dentry);
699 fsnotify_oldname_free(old_name); 699 release_dentry_name_snapshot(&old_name);
700 unlock_rename(new_dir, old_dir); 700 unlock_rename(new_dir, old_dir);
701 dput(dentry); 701 dput(dentry);
702 return old_dentry; 702 return old_dentry;
diff --git a/fs/direct-io.c b/fs/direct-io.c
index 01171d8a6ee9..c772fdf36cd9 100644
--- a/fs/direct-io.c
+++ b/fs/direct-io.c
@@ -575,7 +575,7 @@ static int dio_set_defer_completion(struct dio *dio)
575/* 575/*
576 * Call into the fs to map some more disk blocks. We record the current number 576 * Call into the fs to map some more disk blocks. We record the current number
577 * of available blocks at sdio->blocks_available. These are in units of the 577 * of available blocks at sdio->blocks_available. These are in units of the
578 * fs blocksize, (1 << inode->i_blkbits). 578 * fs blocksize, i_blocksize(inode).
579 * 579 *
580 * The fs is allowed to map lots of blocks at once. If it wants to do that, 580 * The fs is allowed to map lots of blocks at once. If it wants to do that,
581 * it uses the passed inode-relative block number as the file offset, as usual. 581 * it uses the passed inode-relative block number as the file offset, as usual.
diff --git a/fs/exec.c b/fs/exec.c
index 3a6de10d3891..dd3a59420506 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -206,7 +206,24 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
206 206
207 if (write) { 207 if (write) {
208 unsigned long size = bprm->vma->vm_end - bprm->vma->vm_start; 208 unsigned long size = bprm->vma->vm_end - bprm->vma->vm_start;
209 struct rlimit *rlim; 209 unsigned long ptr_size, limit;
210
211 /*
212 * Since the stack will hold pointers to the strings, we
213 * must account for them as well.
214 *
215 * The size calculation is the entire vma while each arg page is
216 * built, so each time we get here it's calculating how far it
217 * is currently (rather than each call being just the newly
218 * added size from the arg page). As a result, we need to
219 * always add the entire size of the pointers, so that on the
220 * last call to get_arg_page() we'll actually have the entire
221 * correct size.
222 */
223 ptr_size = (bprm->argc + bprm->envc) * sizeof(void *);
224 if (ptr_size > ULONG_MAX - size)
225 goto fail;
226 size += ptr_size;
210 227
211 acct_arg_size(bprm, size / PAGE_SIZE); 228 acct_arg_size(bprm, size / PAGE_SIZE);
212 229
@@ -218,20 +235,24 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
218 return page; 235 return page;
219 236
220 /* 237 /*
221 * Limit to 1/4-th the stack size for the argv+env strings. 238 * Limit to 1/4 of the max stack size or 3/4 of _STK_LIM
239 * (whichever is smaller) for the argv+env strings.
222 * This ensures that: 240 * This ensures that:
223 * - the remaining binfmt code will not run out of stack space, 241 * - the remaining binfmt code will not run out of stack space,
224 * - the program will have a reasonable amount of stack left 242 * - the program will have a reasonable amount of stack left
225 * to work from. 243 * to work from.
226 */ 244 */
227 rlim = current->signal->rlim; 245 limit = _STK_LIM / 4 * 3;
228 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur) / 4) { 246 limit = min(limit, rlimit(RLIMIT_STACK) / 4);
229 put_page(page); 247 if (size > limit)
230 return NULL; 248 goto fail;
231 }
232 } 249 }
233 250
234 return page; 251 return page;
252
253fail:
254 put_page(page);
255 return NULL;
235} 256}
236 257
237static void put_arg_page(struct page *page) 258static void put_arg_page(struct page *page)
@@ -1132,7 +1153,7 @@ EXPORT_SYMBOL(flush_old_exec);
1132void would_dump(struct linux_binprm *bprm, struct file *file) 1153void would_dump(struct linux_binprm *bprm, struct file *file)
1133{ 1154{
1134 struct inode *inode = file_inode(file); 1155 struct inode *inode = file_inode(file);
1135 if (inode_permission(inode, MAY_READ) < 0) { 1156 if (inode_permission2(file->f_path.mnt, inode, MAY_READ) < 0) {
1136 struct user_namespace *old, *user_ns; 1157 struct user_namespace *old, *user_ns;
1137 bprm->interp_flags |= BINPRM_FLAGS_ENFORCE_NONDUMP; 1158 bprm->interp_flags |= BINPRM_FLAGS_ENFORCE_NONDUMP;
1138 1159
diff --git a/fs/ext2/ext2.h b/fs/ext2/ext2.h
index 4c69c94cafd8..f98ce7e60a0f 100644
--- a/fs/ext2/ext2.h
+++ b/fs/ext2/ext2.h
@@ -61,6 +61,8 @@ struct ext2_block_alloc_info {
61#define rsv_start rsv_window._rsv_start 61#define rsv_start rsv_window._rsv_start
62#define rsv_end rsv_window._rsv_end 62#define rsv_end rsv_window._rsv_end
63 63
64struct mb2_cache;
65
64/* 66/*
65 * second extended-fs super-block data in memory 67 * second extended-fs super-block data in memory
66 */ 68 */
@@ -111,6 +113,7 @@ struct ext2_sb_info {
111 * of the mount options. 113 * of the mount options.
112 */ 114 */
113 spinlock_t s_lock; 115 spinlock_t s_lock;
116 struct mb2_cache *s_mb_cache;
114}; 117};
115 118
116static inline spinlock_t * 119static inline spinlock_t *
diff --git a/fs/ext2/super.c b/fs/ext2/super.c
index 748d35afc902..111a31761ffa 100644
--- a/fs/ext2/super.c
+++ b/fs/ext2/super.c
@@ -131,7 +131,10 @@ static void ext2_put_super (struct super_block * sb)
131 131
132 dquot_disable(sb, -1, DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED); 132 dquot_disable(sb, -1, DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED);
133 133
134 ext2_xattr_put_super(sb); 134 if (sbi->s_mb_cache) {
135 ext2_xattr_destroy_cache(sbi->s_mb_cache);
136 sbi->s_mb_cache = NULL;
137 }
135 if (!(sb->s_flags & MS_RDONLY)) { 138 if (!(sb->s_flags & MS_RDONLY)) {
136 struct ext2_super_block *es = sbi->s_es; 139 struct ext2_super_block *es = sbi->s_es;
137 140
@@ -1104,6 +1107,14 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
1104 ext2_msg(sb, KERN_ERR, "error: insufficient memory"); 1107 ext2_msg(sb, KERN_ERR, "error: insufficient memory");
1105 goto failed_mount3; 1108 goto failed_mount3;
1106 } 1109 }
1110
1111#ifdef CONFIG_EXT2_FS_XATTR
1112 sbi->s_mb_cache = ext2_xattr_create_cache();
1113 if (!sbi->s_mb_cache) {
1114 ext2_msg(sb, KERN_ERR, "Failed to create an mb_cache");
1115 goto failed_mount3;
1116 }
1117#endif
1107 /* 1118 /*
1108 * set up enough so that it can read an inode 1119 * set up enough so that it can read an inode
1109 */ 1120 */
@@ -1149,6 +1160,8 @@ cantfind_ext2:
1149 sb->s_id); 1160 sb->s_id);
1150 goto failed_mount; 1161 goto failed_mount;
1151failed_mount3: 1162failed_mount3:
1163 if (sbi->s_mb_cache)
1164 ext2_xattr_destroy_cache(sbi->s_mb_cache);
1152 percpu_counter_destroy(&sbi->s_freeblocks_counter); 1165 percpu_counter_destroy(&sbi->s_freeblocks_counter);
1153 percpu_counter_destroy(&sbi->s_freeinodes_counter); 1166 percpu_counter_destroy(&sbi->s_freeinodes_counter);
1154 percpu_counter_destroy(&sbi->s_dirs_counter); 1167 percpu_counter_destroy(&sbi->s_dirs_counter);
@@ -1555,20 +1568,17 @@ MODULE_ALIAS_FS("ext2");
1555 1568
1556static int __init init_ext2_fs(void) 1569static int __init init_ext2_fs(void)
1557{ 1570{
1558 int err = init_ext2_xattr(); 1571 int err;
1559 if (err) 1572
1560 return err;
1561 err = init_inodecache(); 1573 err = init_inodecache();
1562 if (err) 1574 if (err)
1563 goto out1; 1575 return err;
1564 err = register_filesystem(&ext2_fs_type); 1576 err = register_filesystem(&ext2_fs_type);
1565 if (err) 1577 if (err)
1566 goto out; 1578 goto out;
1567 return 0; 1579 return 0;
1568out: 1580out:
1569 destroy_inodecache(); 1581 destroy_inodecache();
1570out1:
1571 exit_ext2_xattr();
1572 return err; 1582 return err;
1573} 1583}
1574 1584
@@ -1576,7 +1586,6 @@ static void __exit exit_ext2_fs(void)
1576{ 1586{
1577 unregister_filesystem(&ext2_fs_type); 1587 unregister_filesystem(&ext2_fs_type);
1578 destroy_inodecache(); 1588 destroy_inodecache();
1579 exit_ext2_xattr();
1580} 1589}
1581 1590
1582MODULE_AUTHOR("Remy Card and others"); 1591MODULE_AUTHOR("Remy Card and others");
diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
index fa70848afa8f..24736c8b3d51 100644
--- a/fs/ext2/xattr.c
+++ b/fs/ext2/xattr.c
@@ -56,7 +56,7 @@
56#include <linux/buffer_head.h> 56#include <linux/buffer_head.h>
57#include <linux/init.h> 57#include <linux/init.h>
58#include <linux/slab.h> 58#include <linux/slab.h>
59#include <linux/mbcache.h> 59#include <linux/mbcache2.h>
60#include <linux/quotaops.h> 60#include <linux/quotaops.h>
61#include <linux/rwsem.h> 61#include <linux/rwsem.h>
62#include <linux/security.h> 62#include <linux/security.h>
@@ -92,14 +92,12 @@
92static int ext2_xattr_set2(struct inode *, struct buffer_head *, 92static int ext2_xattr_set2(struct inode *, struct buffer_head *,
93 struct ext2_xattr_header *); 93 struct ext2_xattr_header *);
94 94
95static int ext2_xattr_cache_insert(struct buffer_head *); 95static int ext2_xattr_cache_insert(struct mb2_cache *, struct buffer_head *);
96static struct buffer_head *ext2_xattr_cache_find(struct inode *, 96static struct buffer_head *ext2_xattr_cache_find(struct inode *,
97 struct ext2_xattr_header *); 97 struct ext2_xattr_header *);
98static void ext2_xattr_rehash(struct ext2_xattr_header *, 98static void ext2_xattr_rehash(struct ext2_xattr_header *,
99 struct ext2_xattr_entry *); 99 struct ext2_xattr_entry *);
100 100
101static struct mb_cache *ext2_xattr_cache;
102
103static const struct xattr_handler *ext2_xattr_handler_map[] = { 101static const struct xattr_handler *ext2_xattr_handler_map[] = {
104 [EXT2_XATTR_INDEX_USER] = &ext2_xattr_user_handler, 102 [EXT2_XATTR_INDEX_USER] = &ext2_xattr_user_handler,
105#ifdef CONFIG_EXT2_FS_POSIX_ACL 103#ifdef CONFIG_EXT2_FS_POSIX_ACL
@@ -154,6 +152,7 @@ ext2_xattr_get(struct inode *inode, int name_index, const char *name,
154 size_t name_len, size; 152 size_t name_len, size;
155 char *end; 153 char *end;
156 int error; 154 int error;
155 struct mb2_cache *ext2_mb_cache = EXT2_SB(inode->i_sb)->s_mb_cache;
157 156
158 ea_idebug(inode, "name=%d.%s, buffer=%p, buffer_size=%ld", 157 ea_idebug(inode, "name=%d.%s, buffer=%p, buffer_size=%ld",
159 name_index, name, buffer, (long)buffer_size); 158 name_index, name, buffer, (long)buffer_size);
@@ -198,7 +197,7 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_get",
198 goto found; 197 goto found;
199 entry = next; 198 entry = next;
200 } 199 }
201 if (ext2_xattr_cache_insert(bh)) 200 if (ext2_xattr_cache_insert(ext2_mb_cache, bh))
202 ea_idebug(inode, "cache insert failed"); 201 ea_idebug(inode, "cache insert failed");
203 error = -ENODATA; 202 error = -ENODATA;
204 goto cleanup; 203 goto cleanup;
@@ -211,7 +210,7 @@ found:
211 le16_to_cpu(entry->e_value_offs) + size > inode->i_sb->s_blocksize) 210 le16_to_cpu(entry->e_value_offs) + size > inode->i_sb->s_blocksize)
212 goto bad_block; 211 goto bad_block;
213 212
214 if (ext2_xattr_cache_insert(bh)) 213 if (ext2_xattr_cache_insert(ext2_mb_cache, bh))
215 ea_idebug(inode, "cache insert failed"); 214 ea_idebug(inode, "cache insert failed");
216 if (buffer) { 215 if (buffer) {
217 error = -ERANGE; 216 error = -ERANGE;
@@ -249,6 +248,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
249 char *end; 248 char *end;
250 size_t rest = buffer_size; 249 size_t rest = buffer_size;
251 int error; 250 int error;
251 struct mb2_cache *ext2_mb_cache = EXT2_SB(inode->i_sb)->s_mb_cache;
252 252
253 ea_idebug(inode, "buffer=%p, buffer_size=%ld", 253 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
254 buffer, (long)buffer_size); 254 buffer, (long)buffer_size);
@@ -283,7 +283,7 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
283 goto bad_block; 283 goto bad_block;
284 entry = next; 284 entry = next;
285 } 285 }
286 if (ext2_xattr_cache_insert(bh)) 286 if (ext2_xattr_cache_insert(ext2_mb_cache, bh))
287 ea_idebug(inode, "cache insert failed"); 287 ea_idebug(inode, "cache insert failed");
288 288
289 /* list the attribute names */ 289 /* list the attribute names */
@@ -480,22 +480,23 @@ bad_block: ext2_error(sb, "ext2_xattr_set",
480 /* Here we know that we can set the new attribute. */ 480 /* Here we know that we can set the new attribute. */
481 481
482 if (header) { 482 if (header) {
483 struct mb_cache_entry *ce;
484
485 /* assert(header == HDR(bh)); */ 483 /* assert(header == HDR(bh)); */
486 ce = mb_cache_entry_get(ext2_xattr_cache, bh->b_bdev,
487 bh->b_blocknr);
488 lock_buffer(bh); 484 lock_buffer(bh);
489 if (header->h_refcount == cpu_to_le32(1)) { 485 if (header->h_refcount == cpu_to_le32(1)) {
486 __u32 hash = le32_to_cpu(header->h_hash);
487
490 ea_bdebug(bh, "modifying in-place"); 488 ea_bdebug(bh, "modifying in-place");
491 if (ce) 489 /*
492 mb_cache_entry_free(ce); 490 * This must happen under buffer lock for
491 * ext2_xattr_set2() to reliably detect modified block
492 */
493 mb2_cache_entry_delete_block(EXT2_SB(sb)->s_mb_cache,
494 hash, bh->b_blocknr);
495
493 /* keep the buffer locked while modifying it. */ 496 /* keep the buffer locked while modifying it. */
494 } else { 497 } else {
495 int offset; 498 int offset;
496 499
497 if (ce)
498 mb_cache_entry_release(ce);
499 unlock_buffer(bh); 500 unlock_buffer(bh);
500 ea_bdebug(bh, "cloning"); 501 ea_bdebug(bh, "cloning");
501 header = kmalloc(bh->b_size, GFP_KERNEL); 502 header = kmalloc(bh->b_size, GFP_KERNEL);
@@ -623,6 +624,7 @@ ext2_xattr_set2(struct inode *inode, struct buffer_head *old_bh,
623 struct super_block *sb = inode->i_sb; 624 struct super_block *sb = inode->i_sb;
624 struct buffer_head *new_bh = NULL; 625 struct buffer_head *new_bh = NULL;
625 int error; 626 int error;
627 struct mb2_cache *ext2_mb_cache = EXT2_SB(sb)->s_mb_cache;
626 628
627 if (header) { 629 if (header) {
628 new_bh = ext2_xattr_cache_find(inode, header); 630 new_bh = ext2_xattr_cache_find(inode, header);
@@ -650,7 +652,7 @@ ext2_xattr_set2(struct inode *inode, struct buffer_head *old_bh,
650 don't need to change the reference count. */ 652 don't need to change the reference count. */
651 new_bh = old_bh; 653 new_bh = old_bh;
652 get_bh(new_bh); 654 get_bh(new_bh);
653 ext2_xattr_cache_insert(new_bh); 655 ext2_xattr_cache_insert(ext2_mb_cache, new_bh);
654 } else { 656 } else {
655 /* We need to allocate a new block */ 657 /* We need to allocate a new block */
656 ext2_fsblk_t goal = ext2_group_first_block_no(sb, 658 ext2_fsblk_t goal = ext2_group_first_block_no(sb,
@@ -671,7 +673,7 @@ ext2_xattr_set2(struct inode *inode, struct buffer_head *old_bh,
671 memcpy(new_bh->b_data, header, new_bh->b_size); 673 memcpy(new_bh->b_data, header, new_bh->b_size);
672 set_buffer_uptodate(new_bh); 674 set_buffer_uptodate(new_bh);
673 unlock_buffer(new_bh); 675 unlock_buffer(new_bh);
674 ext2_xattr_cache_insert(new_bh); 676 ext2_xattr_cache_insert(ext2_mb_cache, new_bh);
675 677
676 ext2_xattr_update_super_block(sb); 678 ext2_xattr_update_super_block(sb);
677 } 679 }
@@ -704,19 +706,21 @@ ext2_xattr_set2(struct inode *inode, struct buffer_head *old_bh,
704 706
705 error = 0; 707 error = 0;
706 if (old_bh && old_bh != new_bh) { 708 if (old_bh && old_bh != new_bh) {
707 struct mb_cache_entry *ce;
708
709 /* 709 /*
710 * If there was an old block and we are no longer using it, 710 * If there was an old block and we are no longer using it,
711 * release the old block. 711 * release the old block.
712 */ 712 */
713 ce = mb_cache_entry_get(ext2_xattr_cache, old_bh->b_bdev,
714 old_bh->b_blocknr);
715 lock_buffer(old_bh); 713 lock_buffer(old_bh);
716 if (HDR(old_bh)->h_refcount == cpu_to_le32(1)) { 714 if (HDR(old_bh)->h_refcount == cpu_to_le32(1)) {
715 __u32 hash = le32_to_cpu(HDR(old_bh)->h_hash);
716
717 /*
718 * This must happen under buffer lock for
719 * ext2_xattr_set2() to reliably detect freed block
720 */
721 mb2_cache_entry_delete_block(ext2_mb_cache,
722 hash, old_bh->b_blocknr);
717 /* Free the old block. */ 723 /* Free the old block. */
718 if (ce)
719 mb_cache_entry_free(ce);
720 ea_bdebug(old_bh, "freeing"); 724 ea_bdebug(old_bh, "freeing");
721 ext2_free_blocks(inode, old_bh->b_blocknr, 1); 725 ext2_free_blocks(inode, old_bh->b_blocknr, 1);
722 mark_inode_dirty(inode); 726 mark_inode_dirty(inode);
@@ -727,8 +731,6 @@ ext2_xattr_set2(struct inode *inode, struct buffer_head *old_bh,
727 } else { 731 } else {
728 /* Decrement the refcount only. */ 732 /* Decrement the refcount only. */
729 le32_add_cpu(&HDR(old_bh)->h_refcount, -1); 733 le32_add_cpu(&HDR(old_bh)->h_refcount, -1);
730 if (ce)
731 mb_cache_entry_release(ce);
732 dquot_free_block_nodirty(inode, 1); 734 dquot_free_block_nodirty(inode, 1);
733 mark_inode_dirty(inode); 735 mark_inode_dirty(inode);
734 mark_buffer_dirty(old_bh); 736 mark_buffer_dirty(old_bh);
@@ -754,7 +756,6 @@ void
754ext2_xattr_delete_inode(struct inode *inode) 756ext2_xattr_delete_inode(struct inode *inode)
755{ 757{
756 struct buffer_head *bh = NULL; 758 struct buffer_head *bh = NULL;
757 struct mb_cache_entry *ce;
758 759
759 down_write(&EXT2_I(inode)->xattr_sem); 760 down_write(&EXT2_I(inode)->xattr_sem);
760 if (!EXT2_I(inode)->i_file_acl) 761 if (!EXT2_I(inode)->i_file_acl)
@@ -774,19 +775,22 @@ ext2_xattr_delete_inode(struct inode *inode)
774 EXT2_I(inode)->i_file_acl); 775 EXT2_I(inode)->i_file_acl);
775 goto cleanup; 776 goto cleanup;
776 } 777 }
777 ce = mb_cache_entry_get(ext2_xattr_cache, bh->b_bdev, bh->b_blocknr);
778 lock_buffer(bh); 778 lock_buffer(bh);
779 if (HDR(bh)->h_refcount == cpu_to_le32(1)) { 779 if (HDR(bh)->h_refcount == cpu_to_le32(1)) {
780 if (ce) 780 __u32 hash = le32_to_cpu(HDR(bh)->h_hash);
781 mb_cache_entry_free(ce); 781
782 /*
783 * This must happen under buffer lock for ext2_xattr_set2() to
784 * reliably detect freed block
785 */
786 mb2_cache_entry_delete_block(EXT2_SB(inode->i_sb)->s_mb_cache,
787 hash, bh->b_blocknr);
782 ext2_free_blocks(inode, EXT2_I(inode)->i_file_acl, 1); 788 ext2_free_blocks(inode, EXT2_I(inode)->i_file_acl, 1);
783 get_bh(bh); 789 get_bh(bh);
784 bforget(bh); 790 bforget(bh);
785 unlock_buffer(bh); 791 unlock_buffer(bh);
786 } else { 792 } else {
787 le32_add_cpu(&HDR(bh)->h_refcount, -1); 793 le32_add_cpu(&HDR(bh)->h_refcount, -1);
788 if (ce)
789 mb_cache_entry_release(ce);
790 ea_bdebug(bh, "refcount now=%d", 794 ea_bdebug(bh, "refcount now=%d",
791 le32_to_cpu(HDR(bh)->h_refcount)); 795 le32_to_cpu(HDR(bh)->h_refcount));
792 unlock_buffer(bh); 796 unlock_buffer(bh);
@@ -803,18 +807,6 @@ cleanup:
803} 807}
804 808
805/* 809/*
806 * ext2_xattr_put_super()
807 *
808 * This is called when a file system is unmounted.
809 */
810void
811ext2_xattr_put_super(struct super_block *sb)
812{
813 mb_cache_shrink(sb->s_bdev);
814}
815
816
817/*
818 * ext2_xattr_cache_insert() 810 * ext2_xattr_cache_insert()
819 * 811 *
820 * Create a new entry in the extended attribute cache, and insert 812 * Create a new entry in the extended attribute cache, and insert
@@ -823,28 +815,20 @@ ext2_xattr_put_super(struct super_block *sb)
823 * Returns 0, or a negative error number on failure. 815 * Returns 0, or a negative error number on failure.
824 */ 816 */
825static int 817static int
826ext2_xattr_cache_insert(struct buffer_head *bh) 818ext2_xattr_cache_insert(struct mb2_cache *cache, struct buffer_head *bh)
827{ 819{
828 __u32 hash = le32_to_cpu(HDR(bh)->h_hash); 820 __u32 hash = le32_to_cpu(HDR(bh)->h_hash);
829 struct mb_cache_entry *ce;
830 int error; 821 int error;
831 822
832 ce = mb_cache_entry_alloc(ext2_xattr_cache, GFP_NOFS); 823 error = mb2_cache_entry_create(cache, GFP_NOFS, hash, bh->b_blocknr);
833 if (!ce)
834 return -ENOMEM;
835 error = mb_cache_entry_insert(ce, bh->b_bdev, bh->b_blocknr, hash);
836 if (error) { 824 if (error) {
837 mb_cache_entry_free(ce);
838 if (error == -EBUSY) { 825 if (error == -EBUSY) {
839 ea_bdebug(bh, "already in cache (%d cache entries)", 826 ea_bdebug(bh, "already in cache (%d cache entries)",
840 atomic_read(&ext2_xattr_cache->c_entry_count)); 827 atomic_read(&ext2_xattr_cache->c_entry_count));
841 error = 0; 828 error = 0;
842 } 829 }
843 } else { 830 } else
844 ea_bdebug(bh, "inserting [%x] (%d cache entries)", (int)hash, 831 ea_bdebug(bh, "inserting [%x]", (int)hash);
845 atomic_read(&ext2_xattr_cache->c_entry_count));
846 mb_cache_entry_release(ce);
847 }
848 return error; 832 return error;
849} 833}
850 834
@@ -900,23 +884,17 @@ static struct buffer_head *
900ext2_xattr_cache_find(struct inode *inode, struct ext2_xattr_header *header) 884ext2_xattr_cache_find(struct inode *inode, struct ext2_xattr_header *header)
901{ 885{
902 __u32 hash = le32_to_cpu(header->h_hash); 886 __u32 hash = le32_to_cpu(header->h_hash);
903 struct mb_cache_entry *ce; 887 struct mb2_cache_entry *ce;
888 struct mb2_cache *ext2_mb_cache = EXT2_SB(inode->i_sb)->s_mb_cache;
904 889
905 if (!header->h_hash) 890 if (!header->h_hash)
906 return NULL; /* never share */ 891 return NULL; /* never share */
907 ea_idebug(inode, "looking for cached blocks [%x]", (int)hash); 892 ea_idebug(inode, "looking for cached blocks [%x]", (int)hash);
908again: 893again:
909 ce = mb_cache_entry_find_first(ext2_xattr_cache, inode->i_sb->s_bdev, 894 ce = mb2_cache_entry_find_first(ext2_mb_cache, hash);
910 hash);
911 while (ce) { 895 while (ce) {
912 struct buffer_head *bh; 896 struct buffer_head *bh;
913 897
914 if (IS_ERR(ce)) {
915 if (PTR_ERR(ce) == -EAGAIN)
916 goto again;
917 break;
918 }
919
920 bh = sb_bread(inode->i_sb, ce->e_block); 898 bh = sb_bread(inode->i_sb, ce->e_block);
921 if (!bh) { 899 if (!bh) {
922 ext2_error(inode->i_sb, "ext2_xattr_cache_find", 900 ext2_error(inode->i_sb, "ext2_xattr_cache_find",
@@ -924,7 +902,21 @@ again:
924 inode->i_ino, (unsigned long) ce->e_block); 902 inode->i_ino, (unsigned long) ce->e_block);
925 } else { 903 } else {
926 lock_buffer(bh); 904 lock_buffer(bh);
927 if (le32_to_cpu(HDR(bh)->h_refcount) > 905 /*
906 * We have to be careful about races with freeing or
907 * rehashing of xattr block. Once we hold buffer lock
908 * xattr block's state is stable so we can check
909 * whether the block got freed / rehashed or not.
910 * Since we unhash mbcache entry under buffer lock when
911 * freeing / rehashing xattr block, checking whether
912 * entry is still hashed is reliable.
913 */
914 if (hlist_bl_unhashed(&ce->e_hash_list)) {
915 mb2_cache_entry_put(ext2_mb_cache, ce);
916 unlock_buffer(bh);
917 brelse(bh);
918 goto again;
919 } else if (le32_to_cpu(HDR(bh)->h_refcount) >
928 EXT2_XATTR_REFCOUNT_MAX) { 920 EXT2_XATTR_REFCOUNT_MAX) {
929 ea_idebug(inode, "block %ld refcount %d>%d", 921 ea_idebug(inode, "block %ld refcount %d>%d",
930 (unsigned long) ce->e_block, 922 (unsigned long) ce->e_block,
@@ -933,13 +925,14 @@ again:
933 } else if (!ext2_xattr_cmp(header, HDR(bh))) { 925 } else if (!ext2_xattr_cmp(header, HDR(bh))) {
934 ea_bdebug(bh, "b_count=%d", 926 ea_bdebug(bh, "b_count=%d",
935 atomic_read(&(bh->b_count))); 927 atomic_read(&(bh->b_count)));
936 mb_cache_entry_release(ce); 928 mb2_cache_entry_touch(ext2_mb_cache, ce);
929 mb2_cache_entry_put(ext2_mb_cache, ce);
937 return bh; 930 return bh;
938 } 931 }
939 unlock_buffer(bh); 932 unlock_buffer(bh);
940 brelse(bh); 933 brelse(bh);
941 } 934 }
942 ce = mb_cache_entry_find_next(ce, inode->i_sb->s_bdev, hash); 935 ce = mb2_cache_entry_find_next(ext2_mb_cache, ce);
943 } 936 }
944 return NULL; 937 return NULL;
945} 938}
@@ -1012,17 +1005,15 @@ static void ext2_xattr_rehash(struct ext2_xattr_header *header,
1012 1005
1013#undef BLOCK_HASH_SHIFT 1006#undef BLOCK_HASH_SHIFT
1014 1007
1015int __init 1008#define HASH_BUCKET_BITS 10
1016init_ext2_xattr(void) 1009
1010struct mb2_cache *ext2_xattr_create_cache(void)
1017{ 1011{
1018 ext2_xattr_cache = mb_cache_create("ext2_xattr", 6); 1012 return mb2_cache_create(HASH_BUCKET_BITS);
1019 if (!ext2_xattr_cache)
1020 return -ENOMEM;
1021 return 0;
1022} 1013}
1023 1014
1024void 1015void ext2_xattr_destroy_cache(struct mb2_cache *cache)
1025exit_ext2_xattr(void)
1026{ 1016{
1027 mb_cache_destroy(ext2_xattr_cache); 1017 if (cache)
1018 mb2_cache_destroy(cache);
1028} 1019}
diff --git a/fs/ext2/xattr.h b/fs/ext2/xattr.h
index 60edf298644e..6ea38aa9563a 100644
--- a/fs/ext2/xattr.h
+++ b/fs/ext2/xattr.h
@@ -53,6 +53,8 @@ struct ext2_xattr_entry {
53#define EXT2_XATTR_SIZE(size) \ 53#define EXT2_XATTR_SIZE(size) \
54 (((size) + EXT2_XATTR_ROUND) & ~EXT2_XATTR_ROUND) 54 (((size) + EXT2_XATTR_ROUND) & ~EXT2_XATTR_ROUND)
55 55
56struct mb2_cache;
57
56# ifdef CONFIG_EXT2_FS_XATTR 58# ifdef CONFIG_EXT2_FS_XATTR
57 59
58extern const struct xattr_handler ext2_xattr_user_handler; 60extern const struct xattr_handler ext2_xattr_user_handler;
@@ -65,10 +67,9 @@ extern int ext2_xattr_get(struct inode *, int, const char *, void *, size_t);
65extern int ext2_xattr_set(struct inode *, int, const char *, const void *, size_t, int); 67extern int ext2_xattr_set(struct inode *, int, const char *, const void *, size_t, int);
66 68
67extern void ext2_xattr_delete_inode(struct inode *); 69extern void ext2_xattr_delete_inode(struct inode *);
68extern void ext2_xattr_put_super(struct super_block *);
69 70
70extern int init_ext2_xattr(void); 71extern struct mb2_cache *ext2_xattr_create_cache(void);
71extern void exit_ext2_xattr(void); 72extern void ext2_xattr_destroy_cache(struct mb2_cache *cache);
72 73
73extern const struct xattr_handler *ext2_xattr_handlers[]; 74extern const struct xattr_handler *ext2_xattr_handlers[];
74 75
@@ -93,19 +94,7 @@ ext2_xattr_delete_inode(struct inode *inode)
93{ 94{
94} 95}
95 96
96static inline void 97static inline void ext2_xattr_destroy_cache(struct mb2_cache *cache)
97ext2_xattr_put_super(struct super_block *sb)
98{
99}
100
101static inline int
102init_ext2_xattr(void)
103{
104 return 0;
105}
106
107static inline void
108exit_ext2_xattr(void)
109{ 98{
110} 99}
111 100
diff --git a/fs/ext4/Kconfig b/fs/ext4/Kconfig
index b46e9fc64196..3c8293215603 100644
--- a/fs/ext4/Kconfig
+++ b/fs/ext4/Kconfig
@@ -106,6 +106,7 @@ config EXT4_ENCRYPTION
106 select CRYPTO_ECB 106 select CRYPTO_ECB
107 select CRYPTO_XTS 107 select CRYPTO_XTS
108 select CRYPTO_CTS 108 select CRYPTO_CTS
109 select CRYPTO_HEH
109 select CRYPTO_CTR 110 select CRYPTO_CTR
110 select CRYPTO_SHA256 111 select CRYPTO_SHA256
111 select KEYS 112 select KEYS
diff --git a/fs/ext4/crypto.c b/fs/ext4/crypto.c
index 1a0835073663..f240cef8b326 100644
--- a/fs/ext4/crypto.c
+++ b/fs/ext4/crypto.c
@@ -34,6 +34,7 @@
34#include <linux/random.h> 34#include <linux/random.h>
35#include <linux/scatterlist.h> 35#include <linux/scatterlist.h>
36#include <linux/spinlock_types.h> 36#include <linux/spinlock_types.h>
37#include <linux/namei.h>
37 38
38#include "ext4_extents.h" 39#include "ext4_extents.h"
39#include "xattr.h" 40#include "xattr.h"
@@ -93,7 +94,8 @@ void ext4_release_crypto_ctx(struct ext4_crypto_ctx *ctx)
93 * Return: An allocated and initialized encryption context on success; error 94 * Return: An allocated and initialized encryption context on success; error
94 * value or NULL otherwise. 95 * value or NULL otherwise.
95 */ 96 */
96struct ext4_crypto_ctx *ext4_get_crypto_ctx(struct inode *inode) 97struct ext4_crypto_ctx *ext4_get_crypto_ctx(struct inode *inode,
98 gfp_t gfp_flags)
97{ 99{
98 struct ext4_crypto_ctx *ctx = NULL; 100 struct ext4_crypto_ctx *ctx = NULL;
99 int res = 0; 101 int res = 0;
@@ -120,7 +122,7 @@ struct ext4_crypto_ctx *ext4_get_crypto_ctx(struct inode *inode)
120 list_del(&ctx->free_list); 122 list_del(&ctx->free_list);
121 spin_unlock_irqrestore(&ext4_crypto_ctx_lock, flags); 123 spin_unlock_irqrestore(&ext4_crypto_ctx_lock, flags);
122 if (!ctx) { 124 if (!ctx) {
123 ctx = kmem_cache_zalloc(ext4_crypto_ctx_cachep, GFP_NOFS); 125 ctx = kmem_cache_zalloc(ext4_crypto_ctx_cachep, gfp_flags);
124 if (!ctx) { 126 if (!ctx) {
125 res = -ENOMEM; 127 res = -ENOMEM;
126 goto out; 128 goto out;
@@ -257,7 +259,8 @@ static int ext4_page_crypto(struct inode *inode,
257 ext4_direction_t rw, 259 ext4_direction_t rw,
258 pgoff_t index, 260 pgoff_t index,
259 struct page *src_page, 261 struct page *src_page,
260 struct page *dest_page) 262 struct page *dest_page,
263 gfp_t gfp_flags)
261 264
262{ 265{
263 u8 xts_tweak[EXT4_XTS_TWEAK_SIZE]; 266 u8 xts_tweak[EXT4_XTS_TWEAK_SIZE];
@@ -268,7 +271,7 @@ static int ext4_page_crypto(struct inode *inode,
268 struct crypto_ablkcipher *tfm = ci->ci_ctfm; 271 struct crypto_ablkcipher *tfm = ci->ci_ctfm;
269 int res = 0; 272 int res = 0;
270 273
271 req = ablkcipher_request_alloc(tfm, GFP_NOFS); 274 req = ablkcipher_request_alloc(tfm, gfp_flags);
272 if (!req) { 275 if (!req) {
273 printk_ratelimited(KERN_ERR 276 printk_ratelimited(KERN_ERR
274 "%s: crypto_request_alloc() failed\n", 277 "%s: crypto_request_alloc() failed\n",
@@ -309,9 +312,10 @@ static int ext4_page_crypto(struct inode *inode,
309 return 0; 312 return 0;
310} 313}
311 314
312static struct page *alloc_bounce_page(struct ext4_crypto_ctx *ctx) 315static struct page *alloc_bounce_page(struct ext4_crypto_ctx *ctx,
316 gfp_t gfp_flags)
313{ 317{
314 ctx->w.bounce_page = mempool_alloc(ext4_bounce_page_pool, GFP_NOWAIT); 318 ctx->w.bounce_page = mempool_alloc(ext4_bounce_page_pool, gfp_flags);
315 if (ctx->w.bounce_page == NULL) 319 if (ctx->w.bounce_page == NULL)
316 return ERR_PTR(-ENOMEM); 320 return ERR_PTR(-ENOMEM);
317 ctx->flags |= EXT4_WRITE_PATH_FL; 321 ctx->flags |= EXT4_WRITE_PATH_FL;
@@ -334,7 +338,8 @@ static struct page *alloc_bounce_page(struct ext4_crypto_ctx *ctx)
334 * error value or NULL. 338 * error value or NULL.
335 */ 339 */
336struct page *ext4_encrypt(struct inode *inode, 340struct page *ext4_encrypt(struct inode *inode,
337 struct page *plaintext_page) 341 struct page *plaintext_page,
342 gfp_t gfp_flags)
338{ 343{
339 struct ext4_crypto_ctx *ctx; 344 struct ext4_crypto_ctx *ctx;
340 struct page *ciphertext_page = NULL; 345 struct page *ciphertext_page = NULL;
@@ -342,17 +347,17 @@ struct page *ext4_encrypt(struct inode *inode,
342 347
343 BUG_ON(!PageLocked(plaintext_page)); 348 BUG_ON(!PageLocked(plaintext_page));
344 349
345 ctx = ext4_get_crypto_ctx(inode); 350 ctx = ext4_get_crypto_ctx(inode, gfp_flags);
346 if (IS_ERR(ctx)) 351 if (IS_ERR(ctx))
347 return (struct page *) ctx; 352 return (struct page *) ctx;
348 353
349 /* The encryption operation will require a bounce page. */ 354 /* The encryption operation will require a bounce page. */
350 ciphertext_page = alloc_bounce_page(ctx); 355 ciphertext_page = alloc_bounce_page(ctx, gfp_flags);
351 if (IS_ERR(ciphertext_page)) 356 if (IS_ERR(ciphertext_page))
352 goto errout; 357 goto errout;
353 ctx->w.control_page = plaintext_page; 358 ctx->w.control_page = plaintext_page;
354 err = ext4_page_crypto(inode, EXT4_ENCRYPT, plaintext_page->index, 359 err = ext4_page_crypto(inode, EXT4_ENCRYPT, plaintext_page->index,
355 plaintext_page, ciphertext_page); 360 plaintext_page, ciphertext_page, gfp_flags);
356 if (err) { 361 if (err) {
357 ciphertext_page = ERR_PTR(err); 362 ciphertext_page = ERR_PTR(err);
358 errout: 363 errout:
@@ -380,8 +385,8 @@ int ext4_decrypt(struct page *page)
380{ 385{
381 BUG_ON(!PageLocked(page)); 386 BUG_ON(!PageLocked(page));
382 387
383 return ext4_page_crypto(page->mapping->host, 388 return ext4_page_crypto(page->mapping->host, EXT4_DECRYPT,
384 EXT4_DECRYPT, page->index, page, page); 389 page->index, page, page, GFP_NOFS);
385} 390}
386 391
387int ext4_encrypted_zeroout(struct inode *inode, struct ext4_extent *ex) 392int ext4_encrypted_zeroout(struct inode *inode, struct ext4_extent *ex)
@@ -402,11 +407,11 @@ int ext4_encrypted_zeroout(struct inode *inode, struct ext4_extent *ex)
402 407
403 BUG_ON(inode->i_sb->s_blocksize != PAGE_CACHE_SIZE); 408 BUG_ON(inode->i_sb->s_blocksize != PAGE_CACHE_SIZE);
404 409
405 ctx = ext4_get_crypto_ctx(inode); 410 ctx = ext4_get_crypto_ctx(inode, GFP_NOFS);
406 if (IS_ERR(ctx)) 411 if (IS_ERR(ctx))
407 return PTR_ERR(ctx); 412 return PTR_ERR(ctx);
408 413
409 ciphertext_page = alloc_bounce_page(ctx); 414 ciphertext_page = alloc_bounce_page(ctx, GFP_NOWAIT);
410 if (IS_ERR(ciphertext_page)) { 415 if (IS_ERR(ciphertext_page)) {
411 err = PTR_ERR(ciphertext_page); 416 err = PTR_ERR(ciphertext_page);
412 goto errout; 417 goto errout;
@@ -414,11 +419,12 @@ int ext4_encrypted_zeroout(struct inode *inode, struct ext4_extent *ex)
414 419
415 while (len--) { 420 while (len--) {
416 err = ext4_page_crypto(inode, EXT4_ENCRYPT, lblk, 421 err = ext4_page_crypto(inode, EXT4_ENCRYPT, lblk,
417 ZERO_PAGE(0), ciphertext_page); 422 ZERO_PAGE(0), ciphertext_page,
423 GFP_NOFS);
418 if (err) 424 if (err)
419 goto errout; 425 goto errout;
420 426
421 bio = bio_alloc(GFP_KERNEL, 1); 427 bio = bio_alloc(GFP_NOWAIT, 1);
422 if (!bio) { 428 if (!bio) {
423 err = -ENOMEM; 429 err = -ENOMEM;
424 goto errout; 430 goto errout;
@@ -469,3 +475,61 @@ uint32_t ext4_validate_encryption_key_size(uint32_t mode, uint32_t size)
469 return size; 475 return size;
470 return 0; 476 return 0;
471} 477}
478
479/*
480 * Validate dentries for encrypted directories to make sure we aren't
481 * potentially caching stale data after a key has been added or
482 * removed.
483 */
484static int ext4_d_revalidate(struct dentry *dentry, unsigned int flags)
485{
486 struct dentry *dir;
487 struct ext4_crypt_info *ci;
488 int dir_has_key, cached_with_key;
489
490 if (flags & LOOKUP_RCU)
491 return -ECHILD;
492
493 dir = dget_parent(dentry);
494 if (!ext4_encrypted_inode(d_inode(dir))) {
495 dput(dir);
496 return 0;
497 }
498 ci = EXT4_I(d_inode(dir))->i_crypt_info;
499
500 /* this should eventually be an flag in d_flags */
501 cached_with_key = dentry->d_fsdata != NULL;
502 dir_has_key = (ci != NULL);
503 dput(dir);
504
505 /*
506 * If the dentry was cached without the key, and it is a
507 * negative dentry, it might be a valid name. We can't check
508 * if the key has since been made available due to locking
509 * reasons, so we fail the validation so ext4_lookup() can do
510 * this check.
511 *
512 * We also fail the validation if the dentry was created with
513 * the key present, but we no longer have the key, or vice versa.
514 */
515 if ((!cached_with_key && d_is_negative(dentry)) ||
516 (!cached_with_key && dir_has_key) ||
517 (cached_with_key && !dir_has_key)) {
518#if 0 /* Revalidation debug */
519 char buf[80];
520 char *cp = simple_dname(dentry, buf, sizeof(buf));
521
522 if (IS_ERR(cp))
523 cp = (char *) "???";
524 pr_err("revalidate: %s %p %d %d %d\n", cp, dentry->d_fsdata,
525 cached_with_key, d_is_negative(dentry),
526 dir_has_key);
527#endif
528 return 0;
529 }
530 return 1;
531}
532
533const struct dentry_operations ext4_encrypted_d_ops = {
534 .d_revalidate = ext4_d_revalidate,
535};
diff --git a/fs/ext4/crypto_fname.c b/fs/ext4/crypto_fname.c
index 2fbef8a14760..026716bdbbfc 100644
--- a/fs/ext4/crypto_fname.c
+++ b/fs/ext4/crypto_fname.c
@@ -44,7 +44,8 @@ static void ext4_dir_crypt_complete(struct crypto_async_request *req, int res)
44 44
45bool ext4_valid_filenames_enc_mode(uint32_t mode) 45bool ext4_valid_filenames_enc_mode(uint32_t mode)
46{ 46{
47 return (mode == EXT4_ENCRYPTION_MODE_AES_256_CTS); 47 return (mode == EXT4_ENCRYPTION_MODE_AES_256_CTS ||
48 mode == EXT4_ENCRYPTION_MODE_AES_256_HEH);
48} 49}
49 50
50static unsigned max_name_len(struct inode *inode) 51static unsigned max_name_len(struct inode *inode)
@@ -343,7 +344,7 @@ int _ext4_fname_disk_to_usr(struct inode *inode,
343 memcpy(buf+4, &hinfo->minor_hash, 4); 344 memcpy(buf+4, &hinfo->minor_hash, 4);
344 } else 345 } else
345 memset(buf, 0, 8); 346 memset(buf, 0, 8);
346 memcpy(buf + 8, iname->name + iname->len - 16, 16); 347 memcpy(buf + 8, iname->name + ((iname->len - 17) & ~15), 16);
347 oname->name[0] = '_'; 348 oname->name[0] = '_';
348 ret = digest_encode(buf, 24, oname->name+1); 349 ret = digest_encode(buf, 24, oname->name+1);
349 oname->len = ret + 1; 350 oname->len = ret + 1;
diff --git a/fs/ext4/crypto_key.c b/fs/ext4/crypto_key.c
index 9a16d1e75a49..22096e31a720 100644
--- a/fs/ext4/crypto_key.c
+++ b/fs/ext4/crypto_key.c
@@ -29,16 +29,16 @@ static void derive_crypt_complete(struct crypto_async_request *req, int rc)
29} 29}
30 30
31/** 31/**
32 * ext4_derive_key_aes() - Derive a key using AES-128-ECB 32 * ext4_derive_key_v1() - Derive a key using AES-128-ECB
33 * @deriving_key: Encryption key used for derivation. 33 * @deriving_key: Encryption key used for derivation.
34 * @source_key: Source key to which to apply derivation. 34 * @source_key: Source key to which to apply derivation.
35 * @derived_key: Derived key. 35 * @derived_key: Derived key.
36 * 36 *
37 * Return: Zero on success; non-zero otherwise. 37 * Return: 0 on success, -errno on failure
38 */ 38 */
39static int ext4_derive_key_aes(char deriving_key[EXT4_AES_128_ECB_KEY_SIZE], 39static int ext4_derive_key_v1(const char deriving_key[EXT4_AES_128_ECB_KEY_SIZE],
40 char source_key[EXT4_AES_256_XTS_KEY_SIZE], 40 const char source_key[EXT4_AES_256_XTS_KEY_SIZE],
41 char derived_key[EXT4_AES_256_XTS_KEY_SIZE]) 41 char derived_key[EXT4_AES_256_XTS_KEY_SIZE])
42{ 42{
43 int res = 0; 43 int res = 0;
44 struct ablkcipher_request *req = NULL; 44 struct ablkcipher_request *req = NULL;
@@ -83,13 +83,96 @@ out:
83 return res; 83 return res;
84} 84}
85 85
86/**
87 * ext4_derive_key_v2() - Derive a key non-reversibly
88 * @nonce: the nonce associated with the file
89 * @master_key: the master key referenced by the file
90 * @derived_key: (output) the resulting derived key
91 *
92 * This function computes the following:
93 * derived_key[0:127] = AES-256-ENCRYPT(master_key[0:255], nonce)
94 * derived_key[128:255] = AES-256-ENCRYPT(master_key[0:255], nonce ^ 0x01)
95 * derived_key[256:383] = AES-256-ENCRYPT(master_key[256:511], nonce)
96 * derived_key[384:511] = AES-256-ENCRYPT(master_key[256:511], nonce ^ 0x01)
97 *
98 * 'nonce ^ 0x01' denotes flipping the low order bit of the last byte.
99 *
100 * Unlike the v1 algorithm, the v2 algorithm is "non-reversible", meaning that
101 * compromising a derived key does not also compromise the master key.
102 *
103 * Return: 0 on success, -errno on failure
104 */
105static int ext4_derive_key_v2(const char nonce[EXT4_KEY_DERIVATION_NONCE_SIZE],
106 const char master_key[EXT4_MAX_KEY_SIZE],
107 char derived_key[EXT4_MAX_KEY_SIZE])
108{
109 const int noncelen = EXT4_KEY_DERIVATION_NONCE_SIZE;
110 struct crypto_cipher *tfm;
111 int err;
112 int i;
113
114 /*
115 * Since we only use each transform for a small number of encryptions,
116 * requesting just "aes" turns out to be significantly faster than
117 * "ecb(aes)", by about a factor of two.
118 */
119 tfm = crypto_alloc_cipher("aes", 0, 0);
120 if (IS_ERR(tfm))
121 return PTR_ERR(tfm);
122
123 BUILD_BUG_ON(4 * EXT4_KEY_DERIVATION_NONCE_SIZE != EXT4_MAX_KEY_SIZE);
124 BUILD_BUG_ON(2 * EXT4_AES_256_ECB_KEY_SIZE != EXT4_MAX_KEY_SIZE);
125 for (i = 0; i < 2; i++) {
126 memcpy(derived_key, nonce, noncelen);
127 memcpy(derived_key + noncelen, nonce, noncelen);
128 derived_key[2 * noncelen - 1] ^= 0x01;
129 err = crypto_cipher_setkey(tfm, master_key,
130 EXT4_AES_256_ECB_KEY_SIZE);
131 if (err)
132 break;
133 crypto_cipher_encrypt_one(tfm, derived_key, derived_key);
134 crypto_cipher_encrypt_one(tfm, derived_key + noncelen,
135 derived_key + noncelen);
136 master_key += EXT4_AES_256_ECB_KEY_SIZE;
137 derived_key += 2 * noncelen;
138 }
139 crypto_free_cipher(tfm);
140 return err;
141}
142
143/**
144 * ext4_derive_key() - Derive a per-file key from a nonce and master key
145 * @ctx: the encryption context associated with the file
146 * @master_key: the master key referenced by the file
147 * @derived_key: (output) the resulting derived key
148 *
149 * Return: 0 on success, -errno on failure
150 */
151static int ext4_derive_key(const struct ext4_encryption_context *ctx,
152 const char master_key[EXT4_MAX_KEY_SIZE],
153 char derived_key[EXT4_MAX_KEY_SIZE])
154{
155 BUILD_BUG_ON(EXT4_AES_128_ECB_KEY_SIZE != EXT4_KEY_DERIVATION_NONCE_SIZE);
156 BUILD_BUG_ON(EXT4_AES_256_XTS_KEY_SIZE != EXT4_MAX_KEY_SIZE);
157
158 /*
159 * Although the key derivation algorithm is logically independent of the
160 * choice of encryption modes, in this kernel it is bundled with HEH
161 * encryption of filenames, which is another crypto improvement that
162 * requires an on-disk format change and requires userspace to specify
163 * different encryption policies.
164 */
165 if (ctx->filenames_encryption_mode == EXT4_ENCRYPTION_MODE_AES_256_HEH)
166 return ext4_derive_key_v2(ctx->nonce, master_key, derived_key);
167 else
168 return ext4_derive_key_v1(ctx->nonce, master_key, derived_key);
169}
170
86void ext4_free_crypt_info(struct ext4_crypt_info *ci) 171void ext4_free_crypt_info(struct ext4_crypt_info *ci)
87{ 172{
88 if (!ci) 173 if (!ci)
89 return; 174 return;
90 175
91 if (ci->ci_keyring_key)
92 key_put(ci->ci_keyring_key);
93 crypto_free_ablkcipher(ci->ci_ctfm); 176 crypto_free_ablkcipher(ci->ci_ctfm);
94 kmem_cache_free(ext4_crypt_info_cachep, ci); 177 kmem_cache_free(ext4_crypt_info_cachep, ci);
95} 178}
@@ -111,7 +194,7 @@ void ext4_free_encryption_info(struct inode *inode,
111 ext4_free_crypt_info(ci); 194 ext4_free_crypt_info(ci);
112} 195}
113 196
114int _ext4_get_encryption_info(struct inode *inode) 197int ext4_get_encryption_info(struct inode *inode)
115{ 198{
116 struct ext4_inode_info *ei = EXT4_I(inode); 199 struct ext4_inode_info *ei = EXT4_I(inode);
117 struct ext4_crypt_info *crypt_info; 200 struct ext4_crypt_info *crypt_info;
@@ -128,22 +211,15 @@ int _ext4_get_encryption_info(struct inode *inode)
128 char mode; 211 char mode;
129 int res; 212 int res;
130 213
214 if (ei->i_crypt_info)
215 return 0;
216
131 if (!ext4_read_workqueue) { 217 if (!ext4_read_workqueue) {
132 res = ext4_init_crypto(); 218 res = ext4_init_crypto();
133 if (res) 219 if (res)
134 return res; 220 return res;
135 } 221 }
136 222
137retry:
138 crypt_info = ACCESS_ONCE(ei->i_crypt_info);
139 if (crypt_info) {
140 if (!crypt_info->ci_keyring_key ||
141 key_validate(crypt_info->ci_keyring_key) == 0)
142 return 0;
143 ext4_free_encryption_info(inode, crypt_info);
144 goto retry;
145 }
146
147 res = ext4_xattr_get(inode, EXT4_XATTR_INDEX_ENCRYPTION, 223 res = ext4_xattr_get(inode, EXT4_XATTR_INDEX_ENCRYPTION,
148 EXT4_XATTR_NAME_ENCRYPTION_CONTEXT, 224 EXT4_XATTR_NAME_ENCRYPTION_CONTEXT,
149 &ctx, sizeof(ctx)); 225 &ctx, sizeof(ctx));
@@ -166,7 +242,6 @@ retry:
166 crypt_info->ci_data_mode = ctx.contents_encryption_mode; 242 crypt_info->ci_data_mode = ctx.contents_encryption_mode;
167 crypt_info->ci_filename_mode = ctx.filenames_encryption_mode; 243 crypt_info->ci_filename_mode = ctx.filenames_encryption_mode;
168 crypt_info->ci_ctfm = NULL; 244 crypt_info->ci_ctfm = NULL;
169 crypt_info->ci_keyring_key = NULL;
170 memcpy(crypt_info->ci_master_key, ctx.master_key_descriptor, 245 memcpy(crypt_info->ci_master_key, ctx.master_key_descriptor,
171 sizeof(crypt_info->ci_master_key)); 246 sizeof(crypt_info->ci_master_key));
172 if (S_ISREG(inode->i_mode)) 247 if (S_ISREG(inode->i_mode))
@@ -182,6 +257,9 @@ retry:
182 case EXT4_ENCRYPTION_MODE_AES_256_CTS: 257 case EXT4_ENCRYPTION_MODE_AES_256_CTS:
183 cipher_str = "cts(cbc(aes))"; 258 cipher_str = "cts(cbc(aes))";
184 break; 259 break;
260 case EXT4_ENCRYPTION_MODE_AES_256_HEH:
261 cipher_str = "heh(aes)";
262 break;
185 default: 263 default:
186 printk_once(KERN_WARNING 264 printk_once(KERN_WARNING
187 "ext4: unsupported key mode %d (ino %u)\n", 265 "ext4: unsupported key mode %d (ino %u)\n",
@@ -206,7 +284,6 @@ retry:
206 keyring_key = NULL; 284 keyring_key = NULL;
207 goto out; 285 goto out;
208 } 286 }
209 crypt_info->ci_keyring_key = keyring_key;
210 if (keyring_key->type != &key_type_logon) { 287 if (keyring_key->type != &key_type_logon) {
211 printk_once(KERN_WARNING 288 printk_once(KERN_WARNING
212 "ext4: key type must be logon\n"); 289 "ext4: key type must be logon\n");
@@ -231,8 +308,7 @@ retry:
231 up_read(&keyring_key->sem); 308 up_read(&keyring_key->sem);
232 goto out; 309 goto out;
233 } 310 }
234 res = ext4_derive_key_aes(ctx.nonce, master_key->raw, 311 res = ext4_derive_key(&ctx, master_key->raw, raw_key);
235 raw_key);
236 up_read(&keyring_key->sem); 312 up_read(&keyring_key->sem);
237 if (res) 313 if (res)
238 goto out; 314 goto out;
@@ -253,16 +329,13 @@ got_key:
253 ext4_encryption_key_size(mode)); 329 ext4_encryption_key_size(mode));
254 if (res) 330 if (res)
255 goto out; 331 goto out;
256 memzero_explicit(raw_key, sizeof(raw_key));
257 if (cmpxchg(&ei->i_crypt_info, NULL, crypt_info) != NULL) {
258 ext4_free_crypt_info(crypt_info);
259 goto retry;
260 }
261 return 0;
262 332
333 if (cmpxchg(&ei->i_crypt_info, NULL, crypt_info) == NULL)
334 crypt_info = NULL;
263out: 335out:
264 if (res == -ENOKEY) 336 if (res == -ENOKEY)
265 res = 0; 337 res = 0;
338 key_put(keyring_key);
266 ext4_free_crypt_info(crypt_info); 339 ext4_free_crypt_info(crypt_info);
267 memzero_explicit(raw_key, sizeof(raw_key)); 340 memzero_explicit(raw_key, sizeof(raw_key));
268 return res; 341 return res;
diff --git a/fs/ext4/crypto_policy.c b/fs/ext4/crypto_policy.c
index 8a9feb341f31..e4f4fc4e56ab 100644
--- a/fs/ext4/crypto_policy.c
+++ b/fs/ext4/crypto_policy.c
@@ -148,20 +148,38 @@ int ext4_get_policy(struct inode *inode, struct ext4_encryption_policy *policy)
148int ext4_is_child_context_consistent_with_parent(struct inode *parent, 148int ext4_is_child_context_consistent_with_parent(struct inode *parent,
149 struct inode *child) 149 struct inode *child)
150{ 150{
151 struct ext4_crypt_info *parent_ci, *child_ci; 151 const struct ext4_crypt_info *parent_ci, *child_ci;
152 struct ext4_encryption_context parent_ctx, child_ctx;
152 int res; 153 int res;
153 154
154 if ((parent == NULL) || (child == NULL)) { 155 /* No restrictions on file types which are never encrypted */
155 pr_err("parent %p child %p\n", parent, child); 156 if (!S_ISREG(child->i_mode) && !S_ISDIR(child->i_mode) &&
156 WARN_ON(1); /* Should never happen */ 157 !S_ISLNK(child->i_mode))
157 return 0; 158 return 1;
158 } 159
159 /* no restrictions if the parent directory is not encrypted */ 160 /* No restrictions if the parent directory is unencrypted */
160 if (!ext4_encrypted_inode(parent)) 161 if (!ext4_encrypted_inode(parent))
161 return 1; 162 return 1;
162 /* if the child directory is not encrypted, this is always a problem */ 163
164 /* Encrypted directories must not contain unencrypted files */
163 if (!ext4_encrypted_inode(child)) 165 if (!ext4_encrypted_inode(child))
164 return 0; 166 return 0;
167
168 /*
169 * Both parent and child are encrypted, so verify they use the same
170 * encryption policy. Compare the fscrypt_info structs if the keys are
171 * available, otherwise retrieve and compare the fscrypt_contexts.
172 *
173 * Note that the fscrypt_context retrieval will be required frequently
174 * when accessing an encrypted directory tree without the key.
175 * Performance-wise this is not a big deal because we already don't
176 * really optimize for file access without the key (to the extent that
177 * such access is even possible), given that any attempted access
178 * already causes a fscrypt_context retrieval and keyring search.
179 *
180 * In any case, if an unexpected error occurs, fall back to "forbidden".
181 */
182
165 res = ext4_get_encryption_info(parent); 183 res = ext4_get_encryption_info(parent);
166 if (res) 184 if (res)
167 return 0; 185 return 0;
@@ -170,17 +188,35 @@ int ext4_is_child_context_consistent_with_parent(struct inode *parent,
170 return 0; 188 return 0;
171 parent_ci = EXT4_I(parent)->i_crypt_info; 189 parent_ci = EXT4_I(parent)->i_crypt_info;
172 child_ci = EXT4_I(child)->i_crypt_info; 190 child_ci = EXT4_I(child)->i_crypt_info;
173 if (!parent_ci && !child_ci) 191 if (parent_ci && child_ci) {
174 return 1; 192 return memcmp(parent_ci->ci_master_key, child_ci->ci_master_key,
175 if (!parent_ci || !child_ci) 193 EXT4_KEY_DESCRIPTOR_SIZE) == 0 &&
194 (parent_ci->ci_data_mode == child_ci->ci_data_mode) &&
195 (parent_ci->ci_filename_mode ==
196 child_ci->ci_filename_mode) &&
197 (parent_ci->ci_flags == child_ci->ci_flags);
198 }
199
200 res = ext4_xattr_get(parent, EXT4_XATTR_INDEX_ENCRYPTION,
201 EXT4_XATTR_NAME_ENCRYPTION_CONTEXT,
202 &parent_ctx, sizeof(parent_ctx));
203 if (res != sizeof(parent_ctx))
204 return 0;
205
206 res = ext4_xattr_get(child, EXT4_XATTR_INDEX_ENCRYPTION,
207 EXT4_XATTR_NAME_ENCRYPTION_CONTEXT,
208 &child_ctx, sizeof(child_ctx));
209 if (res != sizeof(child_ctx))
176 return 0; 210 return 0;
177 211
178 return (memcmp(parent_ci->ci_master_key, 212 return memcmp(parent_ctx.master_key_descriptor,
179 child_ci->ci_master_key, 213 child_ctx.master_key_descriptor,
180 EXT4_KEY_DESCRIPTOR_SIZE) == 0 && 214 EXT4_KEY_DESCRIPTOR_SIZE) == 0 &&
181 (parent_ci->ci_data_mode == child_ci->ci_data_mode) && 215 (parent_ctx.contents_encryption_mode ==
182 (parent_ci->ci_filename_mode == child_ci->ci_filename_mode) && 216 child_ctx.contents_encryption_mode) &&
183 (parent_ci->ci_flags == child_ci->ci_flags)); 217 (parent_ctx.filenames_encryption_mode ==
218 child_ctx.filenames_encryption_mode) &&
219 (parent_ctx.flags == child_ctx.flags);
184} 220}
185 221
186/** 222/**
diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
index 1d1bca74f844..6d17f31a31d7 100644
--- a/fs/ext4/dir.c
+++ b/fs/ext4/dir.c
@@ -111,6 +111,12 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx)
111 int dir_has_error = 0; 111 int dir_has_error = 0;
112 struct ext4_str fname_crypto_str = {.name = NULL, .len = 0}; 112 struct ext4_str fname_crypto_str = {.name = NULL, .len = 0};
113 113
114 if (ext4_encrypted_inode(inode)) {
115 err = ext4_get_encryption_info(inode);
116 if (err && err != -ENOKEY)
117 return err;
118 }
119
114 if (is_dx_dir(inode)) { 120 if (is_dx_dir(inode)) {
115 err = ext4_dx_readdir(file, ctx); 121 err = ext4_dx_readdir(file, ctx);
116 if (err != ERR_BAD_DX_DIR) { 122 if (err != ERR_BAD_DX_DIR) {
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 9f31991a5e05..6edacb849e48 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -589,6 +589,7 @@ enum {
589#define EXT4_ENCRYPTION_MODE_AES_256_GCM 2 589#define EXT4_ENCRYPTION_MODE_AES_256_GCM 2
590#define EXT4_ENCRYPTION_MODE_AES_256_CBC 3 590#define EXT4_ENCRYPTION_MODE_AES_256_CBC 3
591#define EXT4_ENCRYPTION_MODE_AES_256_CTS 4 591#define EXT4_ENCRYPTION_MODE_AES_256_CTS 4
592#define EXT4_ENCRYPTION_MODE_AES_256_HEH 126
592 593
593#include "ext4_crypto.h" 594#include "ext4_crypto.h"
594 595
@@ -1441,7 +1442,7 @@ struct ext4_sb_info {
1441 struct list_head s_es_list; /* List of inodes with reclaimable extents */ 1442 struct list_head s_es_list; /* List of inodes with reclaimable extents */
1442 long s_es_nr_inode; 1443 long s_es_nr_inode;
1443 struct ext4_es_stats s_es_stats; 1444 struct ext4_es_stats s_es_stats;
1444 struct mb_cache *s_mb_cache; 1445 struct mb2_cache *s_mb_cache;
1445 spinlock_t s_es_lock ____cacheline_aligned_in_smp; 1446 spinlock_t s_es_lock ____cacheline_aligned_in_smp;
1446 1447
1447 /* Ratelimit ext4 messages. */ 1448 /* Ratelimit ext4 messages. */
@@ -2261,13 +2262,16 @@ extern struct kmem_cache *ext4_crypt_info_cachep;
2261bool ext4_valid_contents_enc_mode(uint32_t mode); 2262bool ext4_valid_contents_enc_mode(uint32_t mode);
2262uint32_t ext4_validate_encryption_key_size(uint32_t mode, uint32_t size); 2263uint32_t ext4_validate_encryption_key_size(uint32_t mode, uint32_t size);
2263extern struct workqueue_struct *ext4_read_workqueue; 2264extern struct workqueue_struct *ext4_read_workqueue;
2264struct ext4_crypto_ctx *ext4_get_crypto_ctx(struct inode *inode); 2265struct ext4_crypto_ctx *ext4_get_crypto_ctx(struct inode *inode,
2266 gfp_t gfp_flags);
2265void ext4_release_crypto_ctx(struct ext4_crypto_ctx *ctx); 2267void ext4_release_crypto_ctx(struct ext4_crypto_ctx *ctx);
2266void ext4_restore_control_page(struct page *data_page); 2268void ext4_restore_control_page(struct page *data_page);
2267struct page *ext4_encrypt(struct inode *inode, 2269struct page *ext4_encrypt(struct inode *inode,
2268 struct page *plaintext_page); 2270 struct page *plaintext_page,
2271 gfp_t gfp_flags);
2269int ext4_decrypt(struct page *page); 2272int ext4_decrypt(struct page *page);
2270int ext4_encrypted_zeroout(struct inode *inode, struct ext4_extent *ex); 2273int ext4_encrypted_zeroout(struct inode *inode, struct ext4_extent *ex);
2274extern const struct dentry_operations ext4_encrypted_d_ops;
2271 2275
2272#ifdef CONFIG_EXT4_FS_ENCRYPTION 2276#ifdef CONFIG_EXT4_FS_ENCRYPTION
2273int ext4_init_crypto(void); 2277int ext4_init_crypto(void);
@@ -2330,23 +2334,11 @@ static inline void ext4_fname_free_filename(struct ext4_filename *fname) { }
2330/* crypto_key.c */ 2334/* crypto_key.c */
2331void ext4_free_crypt_info(struct ext4_crypt_info *ci); 2335void ext4_free_crypt_info(struct ext4_crypt_info *ci);
2332void ext4_free_encryption_info(struct inode *inode, struct ext4_crypt_info *ci); 2336void ext4_free_encryption_info(struct inode *inode, struct ext4_crypt_info *ci);
2333int _ext4_get_encryption_info(struct inode *inode);
2334 2337
2335#ifdef CONFIG_EXT4_FS_ENCRYPTION 2338#ifdef CONFIG_EXT4_FS_ENCRYPTION
2336int ext4_has_encryption_key(struct inode *inode); 2339int ext4_has_encryption_key(struct inode *inode);
2337 2340
2338static inline int ext4_get_encryption_info(struct inode *inode) 2341int ext4_get_encryption_info(struct inode *inode);
2339{
2340 struct ext4_crypt_info *ci = EXT4_I(inode)->i_crypt_info;
2341
2342 if (!ci ||
2343 (ci->ci_keyring_key &&
2344 (ci->ci_keyring_key->flags & ((1 << KEY_FLAG_INVALIDATED) |
2345 (1 << KEY_FLAG_REVOKED) |
2346 (1 << KEY_FLAG_DEAD)))))
2347 return _ext4_get_encryption_info(inode);
2348 return 0;
2349}
2350 2342
2351static inline struct ext4_crypt_info *ext4_encryption_info(struct inode *inode) 2343static inline struct ext4_crypt_info *ext4_encryption_info(struct inode *inode)
2352{ 2344{
diff --git a/fs/ext4/ext4_crypto.h b/fs/ext4/ext4_crypto.h
index ac7d4e813796..e52637d969db 100644
--- a/fs/ext4/ext4_crypto.h
+++ b/fs/ext4/ext4_crypto.h
@@ -58,8 +58,10 @@ struct ext4_encryption_context {
58#define EXT4_XTS_TWEAK_SIZE 16 58#define EXT4_XTS_TWEAK_SIZE 16
59#define EXT4_AES_128_ECB_KEY_SIZE 16 59#define EXT4_AES_128_ECB_KEY_SIZE 16
60#define EXT4_AES_256_GCM_KEY_SIZE 32 60#define EXT4_AES_256_GCM_KEY_SIZE 32
61#define EXT4_AES_256_ECB_KEY_SIZE 32
61#define EXT4_AES_256_CBC_KEY_SIZE 32 62#define EXT4_AES_256_CBC_KEY_SIZE 32
62#define EXT4_AES_256_CTS_KEY_SIZE 32 63#define EXT4_AES_256_CTS_KEY_SIZE 32
64#define EXT4_AES_256_HEH_KEY_SIZE 32
63#define EXT4_AES_256_XTS_KEY_SIZE 64 65#define EXT4_AES_256_XTS_KEY_SIZE 64
64#define EXT4_MAX_KEY_SIZE 64 66#define EXT4_MAX_KEY_SIZE 64
65 67
@@ -78,7 +80,6 @@ struct ext4_crypt_info {
78 char ci_filename_mode; 80 char ci_filename_mode;
79 char ci_flags; 81 char ci_flags;
80 struct crypto_ablkcipher *ci_ctfm; 82 struct crypto_ablkcipher *ci_ctfm;
81 struct key *ci_keyring_key;
82 char ci_master_key[EXT4_KEY_DESCRIPTOR_SIZE]; 83 char ci_master_key[EXT4_KEY_DESCRIPTOR_SIZE];
83}; 84};
84 85
@@ -121,6 +122,8 @@ static inline int ext4_encryption_key_size(int mode)
121 return EXT4_AES_256_CBC_KEY_SIZE; 122 return EXT4_AES_256_CBC_KEY_SIZE;
122 case EXT4_ENCRYPTION_MODE_AES_256_CTS: 123 case EXT4_ENCRYPTION_MODE_AES_256_CTS:
123 return EXT4_AES_256_CTS_KEY_SIZE; 124 return EXT4_AES_256_CTS_KEY_SIZE;
125 case EXT4_ENCRYPTION_MODE_AES_256_HEH:
126 return EXT4_AES_256_HEH_KEY_SIZE;
124 default: 127 default:
125 BUG(); 128 BUG();
126 } 129 }
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index 9da42ace762a..61d5bfc7318c 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -4902,6 +4902,8 @@ static long ext4_zero_range(struct file *file, loff_t offset,
4902 4902
4903 /* Zero out partial block at the edges of the range */ 4903 /* Zero out partial block at the edges of the range */
4904 ret = ext4_zero_partial_blocks(handle, inode, offset, len); 4904 ret = ext4_zero_partial_blocks(handle, inode, offset, len);
4905 if (ret >= 0)
4906 ext4_update_inode_fsync_trans(handle, inode, 1);
4905 4907
4906 if (file->f_flags & O_SYNC) 4908 if (file->f_flags & O_SYNC)
4907 ext4_handle_sync(handle); 4909 ext4_handle_sync(handle);
@@ -5362,7 +5364,8 @@ ext4_ext_shift_extents(struct inode *inode, handle_t *handle,
5362 ext4_lblk_t stop, *iterator, ex_start, ex_end; 5364 ext4_lblk_t stop, *iterator, ex_start, ex_end;
5363 5365
5364 /* Let path point to the last extent */ 5366 /* Let path point to the last extent */
5365 path = ext4_find_extent(inode, EXT_MAX_BLOCKS - 1, NULL, 0); 5367 path = ext4_find_extent(inode, EXT_MAX_BLOCKS - 1, NULL,
5368 EXT4_EX_NOCACHE);
5366 if (IS_ERR(path)) 5369 if (IS_ERR(path))
5367 return PTR_ERR(path); 5370 return PTR_ERR(path);
5368 5371
@@ -5371,15 +5374,15 @@ ext4_ext_shift_extents(struct inode *inode, handle_t *handle,
5371 if (!extent) 5374 if (!extent)
5372 goto out; 5375 goto out;
5373 5376
5374 stop = le32_to_cpu(extent->ee_block) + 5377 stop = le32_to_cpu(extent->ee_block);
5375 ext4_ext_get_actual_len(extent);
5376 5378
5377 /* 5379 /*
5378 * In case of left shift, Don't start shifting extents until we make 5380 * In case of left shift, Don't start shifting extents until we make
5379 * sure the hole is big enough to accommodate the shift. 5381 * sure the hole is big enough to accommodate the shift.
5380 */ 5382 */
5381 if (SHIFT == SHIFT_LEFT) { 5383 if (SHIFT == SHIFT_LEFT) {
5382 path = ext4_find_extent(inode, start - 1, &path, 0); 5384 path = ext4_find_extent(inode, start - 1, &path,
5385 EXT4_EX_NOCACHE);
5383 if (IS_ERR(path)) 5386 if (IS_ERR(path))
5384 return PTR_ERR(path); 5387 return PTR_ERR(path);
5385 depth = path->p_depth; 5388 depth = path->p_depth;
@@ -5411,9 +5414,14 @@ ext4_ext_shift_extents(struct inode *inode, handle_t *handle,
5411 else 5414 else
5412 iterator = &stop; 5415 iterator = &stop;
5413 5416
5414 /* Its safe to start updating extents */ 5417 /*
5415 while (start < stop) { 5418 * Its safe to start updating extents. Start and stop are unsigned, so
5416 path = ext4_find_extent(inode, *iterator, &path, 0); 5419 * in case of right shift if extent with 0 block is reached, iterator
5420 * becomes NULL to indicate the end of the loop.
5421 */
5422 while (iterator && start <= stop) {
5423 path = ext4_find_extent(inode, *iterator, &path,
5424 EXT4_EX_NOCACHE);
5417 if (IS_ERR(path)) 5425 if (IS_ERR(path))
5418 return PTR_ERR(path); 5426 return PTR_ERR(path);
5419 depth = path->p_depth; 5427 depth = path->p_depth;
@@ -5440,8 +5448,11 @@ ext4_ext_shift_extents(struct inode *inode, handle_t *handle,
5440 ext4_ext_get_actual_len(extent); 5448 ext4_ext_get_actual_len(extent);
5441 } else { 5449 } else {
5442 extent = EXT_FIRST_EXTENT(path[depth].p_hdr); 5450 extent = EXT_FIRST_EXTENT(path[depth].p_hdr);
5443 *iterator = le32_to_cpu(extent->ee_block) > 0 ? 5451 if (le32_to_cpu(extent->ee_block) > 0)
5444 le32_to_cpu(extent->ee_block) - 1 : 0; 5452 *iterator = le32_to_cpu(extent->ee_block) - 1;
5453 else
5454 /* Beginning is reached, end of the loop */
5455 iterator = NULL;
5445 /* Update path extent in case we need to stop */ 5456 /* Update path extent in case we need to stop */
5446 while (le32_to_cpu(extent->ee_block) < start) 5457 while (le32_to_cpu(extent->ee_block) < start)
5447 extent++; 5458 extent++;
@@ -5588,6 +5599,7 @@ int ext4_collapse_range(struct inode *inode, loff_t offset, loff_t len)
5588 ext4_handle_sync(handle); 5599 ext4_handle_sync(handle);
5589 inode->i_mtime = inode->i_ctime = ext4_current_time(inode); 5600 inode->i_mtime = inode->i_ctime = ext4_current_time(inode);
5590 ext4_mark_inode_dirty(handle, inode); 5601 ext4_mark_inode_dirty(handle, inode);
5602 ext4_update_inode_fsync_trans(handle, inode, 1);
5591 5603
5592out_stop: 5604out_stop:
5593 ext4_journal_stop(handle); 5605 ext4_journal_stop(handle);
@@ -5761,6 +5773,8 @@ int ext4_insert_range(struct inode *inode, loff_t offset, loff_t len)
5761 up_write(&EXT4_I(inode)->i_data_sem); 5773 up_write(&EXT4_I(inode)->i_data_sem);
5762 if (IS_SYNC(inode)) 5774 if (IS_SYNC(inode))
5763 ext4_handle_sync(handle); 5775 ext4_handle_sync(handle);
5776 if (ret >= 0)
5777 ext4_update_inode_fsync_trans(handle, inode, 1);
5764 5778
5765out_stop: 5779out_stop:
5766 ext4_journal_stop(handle); 5780 ext4_journal_stop(handle);
diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index 0d24ebcd7c9e..45ef9975caec 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -463,47 +463,27 @@ static int ext4_find_unwritten_pgoff(struct inode *inode,
463 num = min_t(pgoff_t, end - index, PAGEVEC_SIZE); 463 num = min_t(pgoff_t, end - index, PAGEVEC_SIZE);
464 nr_pages = pagevec_lookup(&pvec, inode->i_mapping, index, 464 nr_pages = pagevec_lookup(&pvec, inode->i_mapping, index,
465 (pgoff_t)num); 465 (pgoff_t)num);
466 if (nr_pages == 0) { 466 if (nr_pages == 0)
467 if (whence == SEEK_DATA)
468 break;
469
470 BUG_ON(whence != SEEK_HOLE);
471 /*
472 * If this is the first time to go into the loop and
473 * offset is not beyond the end offset, it will be a
474 * hole at this offset
475 */
476 if (lastoff == startoff || lastoff < endoff)
477 found = 1;
478 break; 467 break;
479 }
480
481 /*
482 * If this is the first time to go into the loop and
483 * offset is smaller than the first page offset, it will be a
484 * hole at this offset.
485 */
486 if (lastoff == startoff && whence == SEEK_HOLE &&
487 lastoff < page_offset(pvec.pages[0])) {
488 found = 1;
489 break;
490 }
491 468
492 for (i = 0; i < nr_pages; i++) { 469 for (i = 0; i < nr_pages; i++) {
493 struct page *page = pvec.pages[i]; 470 struct page *page = pvec.pages[i];
494 struct buffer_head *bh, *head; 471 struct buffer_head *bh, *head;
495 472
496 /* 473 /*
497 * If the current offset is not beyond the end of given 474 * If current offset is smaller than the page offset,
498 * range, it will be a hole. 475 * there is a hole at this offset.
499 */ 476 */
500 if (lastoff < endoff && whence == SEEK_HOLE && 477 if (whence == SEEK_HOLE && lastoff < endoff &&
501 page->index > end) { 478 lastoff < page_offset(pvec.pages[i])) {
502 found = 1; 479 found = 1;
503 *offset = lastoff; 480 *offset = lastoff;
504 goto out; 481 goto out;
505 } 482 }
506 483
484 if (page->index > end)
485 goto out;
486
507 lock_page(page); 487 lock_page(page);
508 488
509 if (unlikely(page->mapping != inode->i_mapping)) { 489 if (unlikely(page->mapping != inode->i_mapping)) {
@@ -520,6 +500,8 @@ static int ext4_find_unwritten_pgoff(struct inode *inode,
520 lastoff = page_offset(page); 500 lastoff = page_offset(page);
521 bh = head = page_buffers(page); 501 bh = head = page_buffers(page);
522 do { 502 do {
503 if (lastoff + bh->b_size <= startoff)
504 goto next;
523 if (buffer_uptodate(bh) || 505 if (buffer_uptodate(bh) ||
524 buffer_unwritten(bh)) { 506 buffer_unwritten(bh)) {
525 if (whence == SEEK_DATA) 507 if (whence == SEEK_DATA)
@@ -534,6 +516,7 @@ static int ext4_find_unwritten_pgoff(struct inode *inode,
534 unlock_page(page); 516 unlock_page(page);
535 goto out; 517 goto out;
536 } 518 }
519next:
537 lastoff += bh->b_size; 520 lastoff += bh->b_size;
538 bh = bh->b_this_page; 521 bh = bh->b_this_page;
539 } while (bh != head); 522 } while (bh != head);
@@ -543,20 +526,18 @@ static int ext4_find_unwritten_pgoff(struct inode *inode,
543 unlock_page(page); 526 unlock_page(page);
544 } 527 }
545 528
546 /* 529 /* The no. of pages is less than our desired, we are done. */
547 * The no. of pages is less than our desired, that would be a 530 if (nr_pages < num)
548 * hole in there.
549 */
550 if (nr_pages < num && whence == SEEK_HOLE) {
551 found = 1;
552 *offset = lastoff;
553 break; 531 break;
554 }
555 532
556 index = pvec.pages[i - 1]->index + 1; 533 index = pvec.pages[i - 1]->index + 1;
557 pagevec_release(&pvec); 534 pagevec_release(&pvec);
558 } while (index <= end); 535 } while (index <= end);
559 536
537 if (whence == SEEK_HOLE && lastoff < endoff) {
538 found = 1;
539 *offset = lastoff;
540 }
560out: 541out:
561 pagevec_release(&pvec); 542 pagevec_release(&pvec);
562 return found; 543 return found;
diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c
index 43dcaab85201..bc7c082b7913 100644
--- a/fs/ext4/inline.c
+++ b/fs/ext4/inline.c
@@ -503,8 +503,16 @@ int ext4_readpage_inline(struct inode *inode, struct page *page)
503 return -EAGAIN; 503 return -EAGAIN;
504 } 504 }
505 505
506 trace_android_fs_dataread_start(inode, page_offset(page), PAGE_SIZE, 506 if (trace_android_fs_dataread_start_enabled()) {
507 current->pid, current->comm); 507 char *path, pathbuf[MAX_TRACE_PATHBUF_LEN];
508
509 path = android_fstrace_get_pathname(pathbuf,
510 MAX_TRACE_PATHBUF_LEN,
511 inode);
512 trace_android_fs_dataread_start(inode, page_offset(page),
513 PAGE_SIZE, current->pid,
514 path, current->comm);
515 }
508 516
509 /* 517 /*
510 * Current inline data can only exist in the 1st page, 518 * Current inline data can only exist in the 1st page,
@@ -939,8 +947,15 @@ int ext4_da_write_inline_data_end(struct inode *inode, loff_t pos,
939 struct page *page) 947 struct page *page)
940{ 948{
941 int i_size_changed = 0; 949 int i_size_changed = 0;
950 int ret;
942 951
943 copied = ext4_write_inline_data_end(inode, pos, len, copied, page); 952 ret = ext4_write_inline_data_end(inode, pos, len, copied, page);
953 if (ret < 0) {
954 unlock_page(page);
955 put_page(page);
956 return ret;
957 }
958 copied = ret;
944 959
945 /* 960 /*
946 * No need to use i_size_read() here, the i_size 961 * No need to use i_size_read() here, the i_size
@@ -1157,10 +1172,9 @@ static int ext4_finish_convert_inline_dir(handle_t *handle,
1157 set_buffer_uptodate(dir_block); 1172 set_buffer_uptodate(dir_block);
1158 err = ext4_handle_dirty_dirent_node(handle, inode, dir_block); 1173 err = ext4_handle_dirty_dirent_node(handle, inode, dir_block);
1159 if (err) 1174 if (err)
1160 goto out; 1175 return err;
1161 set_buffer_verified(dir_block); 1176 set_buffer_verified(dir_block);
1162out: 1177 return ext4_mark_inode_dirty(handle, inode);
1163 return err;
1164} 1178}
1165 1179
1166static int ext4_convert_inline_data_nolock(handle_t *handle, 1180static int ext4_convert_inline_data_nolock(handle_t *handle,
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index c33fcb4f8533..e3d425eeab4a 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -72,10 +72,9 @@ static __u32 ext4_inode_csum(struct inode *inode, struct ext4_inode *raw,
72 csum = ext4_chksum(sbi, csum, (__u8 *)&dummy_csum, 72 csum = ext4_chksum(sbi, csum, (__u8 *)&dummy_csum,
73 csum_size); 73 csum_size);
74 offset += csum_size; 74 offset += csum_size;
75 csum = ext4_chksum(sbi, csum, (__u8 *)raw + offset,
76 EXT4_INODE_SIZE(inode->i_sb) -
77 offset);
78 } 75 }
76 csum = ext4_chksum(sbi, csum, (__u8 *)raw + offset,
77 EXT4_INODE_SIZE(inode->i_sb) - offset);
79 } 78 }
80 79
81 return csum; 80 return csum;
@@ -1017,8 +1016,16 @@ static int ext4_write_begin(struct file *file, struct address_space *mapping,
1017 pgoff_t index; 1016 pgoff_t index;
1018 unsigned from, to; 1017 unsigned from, to;
1019 1018
1020 trace_android_fs_datawrite_start(inode, pos, len, 1019 if (trace_android_fs_datawrite_start_enabled()) {
1021 current->pid, current->comm); 1020 char *path, pathbuf[MAX_TRACE_PATHBUF_LEN];
1021
1022 path = android_fstrace_get_pathname(pathbuf,
1023 MAX_TRACE_PATHBUF_LEN,
1024 inode);
1025 trace_android_fs_datawrite_start(inode, pos, len,
1026 current->pid, path,
1027 current->comm);
1028 }
1022 trace_ext4_write_begin(inode, pos, len, flags); 1029 trace_ext4_write_begin(inode, pos, len, flags);
1023 /* 1030 /*
1024 * Reserve one block more for addition to orphan list in case 1031 * Reserve one block more for addition to orphan list in case
@@ -1169,8 +1176,11 @@ static int ext4_write_end(struct file *file,
1169 if (ext4_has_inline_data(inode)) { 1176 if (ext4_has_inline_data(inode)) {
1170 ret = ext4_write_inline_data_end(inode, pos, len, 1177 ret = ext4_write_inline_data_end(inode, pos, len,
1171 copied, page); 1178 copied, page);
1172 if (ret < 0) 1179 if (ret < 0) {
1180 unlock_page(page);
1181 put_page(page);
1173 goto errout; 1182 goto errout;
1183 }
1174 copied = ret; 1184 copied = ret;
1175 } else 1185 } else
1176 copied = block_write_end(file, mapping, pos, 1186 copied = block_write_end(file, mapping, pos,
@@ -1224,7 +1234,9 @@ errout:
1224 * set the buffer to be dirty, since in data=journalled mode we need 1234 * set the buffer to be dirty, since in data=journalled mode we need
1225 * to call ext4_handle_dirty_metadata() instead. 1235 * to call ext4_handle_dirty_metadata() instead.
1226 */ 1236 */
1227static void zero_new_buffers(struct page *page, unsigned from, unsigned to) 1237static void ext4_journalled_zero_new_buffers(handle_t *handle,
1238 struct page *page,
1239 unsigned from, unsigned to)
1228{ 1240{
1229 unsigned int block_start = 0, block_end; 1241 unsigned int block_start = 0, block_end;
1230 struct buffer_head *head, *bh; 1242 struct buffer_head *head, *bh;
@@ -1241,7 +1253,7 @@ static void zero_new_buffers(struct page *page, unsigned from, unsigned to)
1241 size = min(to, block_end) - start; 1253 size = min(to, block_end) - start;
1242 1254
1243 zero_user(page, start, size); 1255 zero_user(page, start, size);
1244 set_buffer_uptodate(bh); 1256 write_end_fn(handle, bh);
1245 } 1257 }
1246 clear_buffer_new(bh); 1258 clear_buffer_new(bh);
1247 } 1259 }
@@ -1271,18 +1283,25 @@ static int ext4_journalled_write_end(struct file *file,
1271 1283
1272 BUG_ON(!ext4_handle_valid(handle)); 1284 BUG_ON(!ext4_handle_valid(handle));
1273 1285
1274 if (ext4_has_inline_data(inode)) 1286 if (ext4_has_inline_data(inode)) {
1275 copied = ext4_write_inline_data_end(inode, pos, len, 1287 ret = ext4_write_inline_data_end(inode, pos, len,
1276 copied, page); 1288 copied, page);
1277 else { 1289 if (ret < 0) {
1278 if (copied < len) { 1290 unlock_page(page);
1279 if (!PageUptodate(page)) 1291 put_page(page);
1280 copied = 0; 1292 goto errout;
1281 zero_new_buffers(page, from+copied, to);
1282 } 1293 }
1283 1294 copied = ret;
1295 } else if (unlikely(copied < len) && !PageUptodate(page)) {
1296 copied = 0;
1297 ext4_journalled_zero_new_buffers(handle, page, from, to);
1298 } else {
1299 if (unlikely(copied < len))
1300 ext4_journalled_zero_new_buffers(handle, page,
1301 from + copied, to);
1284 ret = ext4_walk_page_buffers(handle, page_buffers(page), from, 1302 ret = ext4_walk_page_buffers(handle, page_buffers(page), from,
1285 to, &partial, write_end_fn); 1303 from + copied, &partial,
1304 write_end_fn);
1286 if (!partial) 1305 if (!partial)
1287 SetPageUptodate(page); 1306 SetPageUptodate(page);
1288 } 1307 }
@@ -1308,6 +1327,7 @@ static int ext4_journalled_write_end(struct file *file,
1308 */ 1327 */
1309 ext4_orphan_add(handle, inode); 1328 ext4_orphan_add(handle, inode);
1310 1329
1330errout:
1311 ret2 = ext4_journal_stop(handle); 1331 ret2 = ext4_journal_stop(handle);
1312 if (!ret) 1332 if (!ret)
1313 ret = ret2; 1333 ret = ret2;
@@ -2037,7 +2057,7 @@ static int mpage_process_page_bufs(struct mpage_da_data *mpd,
2037{ 2057{
2038 struct inode *inode = mpd->inode; 2058 struct inode *inode = mpd->inode;
2039 int err; 2059 int err;
2040 ext4_lblk_t blocks = (i_size_read(inode) + (1 << inode->i_blkbits) - 1) 2060 ext4_lblk_t blocks = (i_size_read(inode) + i_blocksize(inode) - 1)
2041 >> inode->i_blkbits; 2061 >> inode->i_blkbits;
2042 2062
2043 do { 2063 do {
@@ -2732,8 +2752,16 @@ static int ext4_da_write_begin(struct file *file, struct address_space *mapping,
2732 len, flags, pagep, fsdata); 2752 len, flags, pagep, fsdata);
2733 } 2753 }
2734 *fsdata = (void *)0; 2754 *fsdata = (void *)0;
2735 trace_android_fs_datawrite_start(inode, pos, len, 2755 if (trace_android_fs_datawrite_start_enabled()) {
2736 current->pid, current->comm); 2756 char *path, pathbuf[MAX_TRACE_PATHBUF_LEN];
2757
2758 path = android_fstrace_get_pathname(pathbuf,
2759 MAX_TRACE_PATHBUF_LEN,
2760 inode);
2761 trace_android_fs_datawrite_start(inode, pos, len,
2762 current->pid,
2763 path, current->comm);
2764 }
2737 trace_ext4_da_write_begin(inode, pos, len, flags); 2765 trace_ext4_da_write_begin(inode, pos, len, flags);
2738 2766
2739 if (ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA)) { 2767 if (ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA)) {
@@ -3342,16 +3370,27 @@ static ssize_t ext4_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
3342 return 0; 3370 return 0;
3343 3371
3344 if (trace_android_fs_dataread_start_enabled() && 3372 if (trace_android_fs_dataread_start_enabled() &&
3345 (iov_iter_rw(iter) == READ)) 3373 (iov_iter_rw(iter) == READ)) {
3374 char *path, pathbuf[MAX_TRACE_PATHBUF_LEN];
3375
3376 path = android_fstrace_get_pathname(pathbuf,
3377 MAX_TRACE_PATHBUF_LEN,
3378 inode);
3346 trace_android_fs_dataread_start(inode, offset, count, 3379 trace_android_fs_dataread_start(inode, offset, count,
3347 current->pid, 3380 current->pid, path,
3348 current->comm); 3381 current->comm);
3382 }
3349 if (trace_android_fs_datawrite_start_enabled() && 3383 if (trace_android_fs_datawrite_start_enabled() &&
3350 (iov_iter_rw(iter) == WRITE)) 3384 (iov_iter_rw(iter) == WRITE)) {
3385 char *path, pathbuf[MAX_TRACE_PATHBUF_LEN];
3386
3387 path = android_fstrace_get_pathname(pathbuf,
3388 MAX_TRACE_PATHBUF_LEN,
3389 inode);
3351 trace_android_fs_datawrite_start(inode, offset, count, 3390 trace_android_fs_datawrite_start(inode, offset, count,
3352 current->pid, 3391 current->pid, path,
3353 current->comm); 3392 current->comm);
3354 3393 }
3355 trace_ext4_direct_IO_enter(inode, offset, count, iov_iter_rw(iter)); 3394 trace_ext4_direct_IO_enter(inode, offset, count, iov_iter_rw(iter));
3356 if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) 3395 if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
3357 ret = ext4_ext_direct_IO(iocb, iter, offset); 3396 ret = ext4_ext_direct_IO(iocb, iter, offset);
@@ -3587,6 +3626,10 @@ static int ext4_block_truncate_page(handle_t *handle,
3587 unsigned blocksize; 3626 unsigned blocksize;
3588 struct inode *inode = mapping->host; 3627 struct inode *inode = mapping->host;
3589 3628
3629 /* If we are processing an encrypted inode during orphan list handling */
3630 if (ext4_encrypted_inode(inode) && !ext4_has_encryption_key(inode))
3631 return 0;
3632
3590 blocksize = inode->i_sb->s_blocksize; 3633 blocksize = inode->i_sb->s_blocksize;
3591 length = blocksize - (offset & (blocksize - 1)); 3634 length = blocksize - (offset & (blocksize - 1));
3592 3635
@@ -3804,6 +3847,8 @@ int ext4_punch_hole(struct inode *inode, loff_t offset, loff_t length)
3804 3847
3805 inode->i_mtime = inode->i_ctime = ext4_current_time(inode); 3848 inode->i_mtime = inode->i_ctime = ext4_current_time(inode);
3806 ext4_mark_inode_dirty(handle, inode); 3849 ext4_mark_inode_dirty(handle, inode);
3850 if (ret >= 0)
3851 ext4_update_inode_fsync_trans(handle, inode, 1);
3807out_stop: 3852out_stop:
3808 ext4_journal_stop(handle); 3853 ext4_journal_stop(handle);
3809out_dio: 3854out_dio:
@@ -5173,8 +5218,9 @@ static int ext4_expand_extra_isize(struct inode *inode,
5173 /* No extended attributes present */ 5218 /* No extended attributes present */
5174 if (!ext4_test_inode_state(inode, EXT4_STATE_XATTR) || 5219 if (!ext4_test_inode_state(inode, EXT4_STATE_XATTR) ||
5175 header->h_magic != cpu_to_le32(EXT4_XATTR_MAGIC)) { 5220 header->h_magic != cpu_to_le32(EXT4_XATTR_MAGIC)) {
5176 memset((void *)raw_inode + EXT4_GOOD_OLD_INODE_SIZE, 0, 5221 memset((void *)raw_inode + EXT4_GOOD_OLD_INODE_SIZE +
5177 new_extra_isize); 5222 EXT4_I(inode)->i_extra_isize, 0,
5223 new_extra_isize - EXT4_I(inode)->i_extra_isize);
5178 EXT4_I(inode)->i_extra_isize = new_extra_isize; 5224 EXT4_I(inode)->i_extra_isize = new_extra_isize;
5179 return 0; 5225 return 0;
5180 } 5226 }
@@ -5404,6 +5450,11 @@ int ext4_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
5404 file_update_time(vma->vm_file); 5450 file_update_time(vma->vm_file);
5405 5451
5406 down_read(&EXT4_I(inode)->i_mmap_sem); 5452 down_read(&EXT4_I(inode)->i_mmap_sem);
5453
5454 ret = ext4_convert_inline_data(inode);
5455 if (ret)
5456 goto out_ret;
5457
5407 /* Delalloc case is easy... */ 5458 /* Delalloc case is easy... */
5408 if (test_opt(inode->i_sb, DELALLOC) && 5459 if (test_opt(inode->i_sb, DELALLOC) &&
5409 !ext4_should_journal_data(inode) && 5460 !ext4_should_journal_data(inode) &&
diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
index 7e974878d9a9..c21826be1cb3 100644
--- a/fs/ext4/ioctl.c
+++ b/fs/ext4/ioctl.c
@@ -626,6 +626,9 @@ resizefs_out:
626 struct ext4_encryption_policy policy; 626 struct ext4_encryption_policy policy;
627 int err = 0; 627 int err = 0;
628 628
629 if (!ext4_has_feature_encrypt(sb))
630 return -EOPNOTSUPP;
631
629 if (copy_from_user(&policy, 632 if (copy_from_user(&policy,
630 (struct ext4_encryption_policy __user *)arg, 633 (struct ext4_encryption_policy __user *)arg,
631 sizeof(policy))) { 634 sizeof(policy))) {
@@ -637,8 +640,12 @@ resizefs_out:
637 if (err) 640 if (err)
638 goto encryption_policy_out; 641 goto encryption_policy_out;
639 642
643 mutex_lock(&inode->i_mutex);
644
640 err = ext4_process_policy(&policy, inode); 645 err = ext4_process_policy(&policy, inode);
641 646
647 mutex_unlock(&inode->i_mutex);
648
642 mnt_drop_write_file(filp); 649 mnt_drop_write_file(filp);
643encryption_policy_out: 650encryption_policy_out:
644 return err; 651 return err;
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index be1227c196d8..c2810503eb50 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -3121,6 +3121,13 @@ ext4_mb_normalize_request(struct ext4_allocation_context *ac,
3121 if (ar->pright && start + size - 1 >= ar->lright) 3121 if (ar->pright && start + size - 1 >= ar->lright)
3122 size -= start + size - ar->lright; 3122 size -= start + size - ar->lright;
3123 3123
3124 /*
3125 * Trim allocation request for filesystems with artificially small
3126 * groups.
3127 */
3128 if (size > EXT4_BLOCKS_PER_GROUP(ac->ac_sb))
3129 size = EXT4_BLOCKS_PER_GROUP(ac->ac_sb);
3130
3124 end = start + size; 3131 end = start + size;
3125 3132
3126 /* check we don't cross already preallocated blocks */ 3133 /* check we don't cross already preallocated blocks */
diff --git a/fs/ext4/move_extent.c b/fs/ext4/move_extent.c
index 7861d801b048..05048fcfd602 100644
--- a/fs/ext4/move_extent.c
+++ b/fs/ext4/move_extent.c
@@ -187,7 +187,7 @@ mext_page_mkuptodate(struct page *page, unsigned from, unsigned to)
187 if (PageUptodate(page)) 187 if (PageUptodate(page))
188 return 0; 188 return 0;
189 189
190 blocksize = 1 << inode->i_blkbits; 190 blocksize = i_blocksize(inode);
191 if (!page_has_buffers(page)) 191 if (!page_has_buffers(page))
192 create_empty_buffers(page, blocksize, 0); 192 create_empty_buffers(page, blocksize, 0);
193 193
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index 573b4cbb0cb9..1d007e853f5c 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -1243,9 +1243,9 @@ static inline int ext4_match(struct ext4_filename *fname,
1243 if (unlikely(!name)) { 1243 if (unlikely(!name)) {
1244 if (fname->usr_fname->name[0] == '_') { 1244 if (fname->usr_fname->name[0] == '_') {
1245 int ret; 1245 int ret;
1246 if (de->name_len < 16) 1246 if (de->name_len <= 32)
1247 return 0; 1247 return 0;
1248 ret = memcmp(de->name + de->name_len - 16, 1248 ret = memcmp(de->name + ((de->name_len - 17) & ~15),
1249 fname->crypto_buf.name + 8, 16); 1249 fname->crypto_buf.name + 8, 16);
1250 return (ret == 0) ? 1 : 0; 1250 return (ret == 0) ? 1 : 0;
1251 } 1251 }
@@ -1557,6 +1557,24 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, unsi
1557 struct ext4_dir_entry_2 *de; 1557 struct ext4_dir_entry_2 *de;
1558 struct buffer_head *bh; 1558 struct buffer_head *bh;
1559 1559
1560 if (ext4_encrypted_inode(dir)) {
1561 int res = ext4_get_encryption_info(dir);
1562
1563 /*
1564 * This should be a properly defined flag for
1565 * dentry->d_flags when we uplift this to the VFS.
1566 * d_fsdata is set to (void *) 1 if if the dentry is
1567 * created while the directory was encrypted and we
1568 * don't have access to the key.
1569 */
1570 dentry->d_fsdata = NULL;
1571 if (ext4_encryption_info(dir))
1572 dentry->d_fsdata = (void *) 1;
1573 d_set_d_op(dentry, &ext4_encrypted_d_ops);
1574 if (res && res != -ENOKEY)
1575 return ERR_PTR(res);
1576 }
1577
1560 if (dentry->d_name.len > EXT4_NAME_LEN) 1578 if (dentry->d_name.len > EXT4_NAME_LEN)
1561 return ERR_PTR(-ENAMETOOLONG); 1579 return ERR_PTR(-ENAMETOOLONG);
1562 1580
diff --git a/fs/ext4/page-io.c b/fs/ext4/page-io.c
index 17fbe3882b8e..6ca56f5f72b5 100644
--- a/fs/ext4/page-io.c
+++ b/fs/ext4/page-io.c
@@ -23,6 +23,7 @@
23#include <linux/kernel.h> 23#include <linux/kernel.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/mm.h> 25#include <linux/mm.h>
26#include <linux/backing-dev.h>
26 27
27#include "ext4_jbd2.h" 28#include "ext4_jbd2.h"
28#include "xattr.h" 29#include "xattr.h"
@@ -485,9 +486,20 @@ int ext4_bio_write_page(struct ext4_io_submit *io,
485 486
486 if (ext4_encrypted_inode(inode) && S_ISREG(inode->i_mode) && 487 if (ext4_encrypted_inode(inode) && S_ISREG(inode->i_mode) &&
487 nr_to_submit) { 488 nr_to_submit) {
488 data_page = ext4_encrypt(inode, page); 489 gfp_t gfp_flags = GFP_NOFS;
490
491 retry_encrypt:
492 data_page = ext4_encrypt(inode, page, gfp_flags);
489 if (IS_ERR(data_page)) { 493 if (IS_ERR(data_page)) {
490 ret = PTR_ERR(data_page); 494 ret = PTR_ERR(data_page);
495 if (ret == -ENOMEM && wbc->sync_mode == WB_SYNC_ALL) {
496 if (io->io_bio) {
497 ext4_io_submit(io);
498 congestion_wait(BLK_RW_ASYNC, HZ/50);
499 }
500 gfp_flags |= __GFP_NOFAIL;
501 goto retry_encrypt;
502 }
491 data_page = NULL; 503 data_page = NULL;
492 goto out; 504 goto out;
493 } 505 }
diff --git a/fs/ext4/readpage.c b/fs/ext4/readpage.c
index 1ce24a6759a0..783e33d839cf 100644
--- a/fs/ext4/readpage.c
+++ b/fs/ext4/readpage.c
@@ -152,11 +152,17 @@ ext4_submit_bio_read(struct bio *bio)
152 struct page *first_page = bio->bi_io_vec[0].bv_page; 152 struct page *first_page = bio->bi_io_vec[0].bv_page;
153 153
154 if (first_page != NULL) { 154 if (first_page != NULL) {
155 char *path, pathbuf[MAX_TRACE_PATHBUF_LEN];
156
157 path = android_fstrace_get_pathname(pathbuf,
158 MAX_TRACE_PATHBUF_LEN,
159 first_page->mapping->host);
155 trace_android_fs_dataread_start( 160 trace_android_fs_dataread_start(
156 first_page->mapping->host, 161 first_page->mapping->host,
157 page_offset(first_page), 162 page_offset(first_page),
158 bio->bi_iter.bi_size, 163 bio->bi_iter.bi_size,
159 current->pid, 164 current->pid,
165 path,
160 current->comm); 166 current->comm);
161 } 167 }
162 } 168 }
@@ -312,7 +318,7 @@ int ext4_mpage_readpages(struct address_space *mapping,
312 318
313 if (ext4_encrypted_inode(inode) && 319 if (ext4_encrypted_inode(inode) &&
314 S_ISREG(inode->i_mode)) { 320 S_ISREG(inode->i_mode)) {
315 ctx = ext4_get_crypto_ctx(inode); 321 ctx = ext4_get_crypto_ctx(inode, GFP_NOFS);
316 if (IS_ERR(ctx)) 322 if (IS_ERR(ctx))
317 goto set_error_page; 323 goto set_error_page;
318 } 324 }
diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
index 34038e3598d5..74516efd874c 100644
--- a/fs/ext4/resize.c
+++ b/fs/ext4/resize.c
@@ -1926,7 +1926,8 @@ retry:
1926 n_desc_blocks = o_desc_blocks + 1926 n_desc_blocks = o_desc_blocks +