[f2fs-dev] [PATCH] fsck.f2fs: check only max extra_isize

2019-08-16 Thread Jaegeuk Kim
If we use later kernel having larger extra_isize, old fsck will delete
entire old files.

Signed-off-by: Jaegeuk Kim 
---
 fsck/fsck.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fsck/fsck.c b/fsck/fsck.c
index 1708abe..b4e53db 100644
--- a/fsck/fsck.c
+++ b/fsck/fsck.c
@@ -731,7 +731,7 @@ void fsck_chk_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
if (f2fs_has_extra_isize(_blk->i)) {
if (c.feature & cpu_to_le32(F2FS_FEATURE_EXTRA_ATTR)) {
if (node_blk->i.i_extra_isize >
-   cpu_to_le16(F2FS_TOTAL_EXTRA_ATTR_SIZE)) {
+   4 * DEF_ADDRS_PER_INODE) {
FIX_MSG("ino[0x%x] recover i_extra_isize "
"from %u to %u",
nid,
-- 
2.19.0.605.g01d371f741-goog



___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


[f2fs-dev] Tinder for Adults: The 5 Best Senior Dating Sites

2019-08-16 Thread Digytag
Votre message :
Sexy girls for the night in your town: 
http://pizchimapa.gq/k32sx?=sNyKlxnzuSVj

--
Ceci est la copie de votre message, envoyé via le formulaire de contact de 
Digytag (http://www.digytag.eu)

Nous vous en remercions d'avance et nous reviendrons vers vous très rapidement.

Equipe DIGYTAG


___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


Re: [f2fs-dev] f2fs: dirty memory increasing during gc_urgent

2019-08-16 Thread Ju Hyung Park
Hi Chao,

On Thu, Aug 15, 2019 at 3:49 PM Chao Yu  wrote:
> I doubt that before triggering urgent GC, system has dirty datas in memory, 
> then
> when you trigger `sync`, GCed data and dirty data were flushed to devices
> together, if we write dirty data with out-place-update model, it may make 
> fragment.
>
> So we can try
> - sync
> - trigger urgent GC
> - sync
> - cat /sys/kernel/debug/f2fs/status to check 'Dirty' field, the value should
> close to zero

It's actually not zero.

Before triggering gc_urgent: 601
After gc_urgent ends and doing a `sync`: 400

And after another 2nd gc_urgent run, it finally becomes 0.

So I'm guessing this wasn't intentional? :P

Thanks,


___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


Re: [f2fs-dev] [PATCH] Add flags option to get xattr method paired to __vfs_getxattr

2019-08-16 Thread Mark Salyzyn via Linux-f2fs-devel

On 8/15/19 3:27 PM, James Morris wrote:

On Thu, 15 Aug 2019, Mark Salyzyn wrote:


Good Idea, but using the same argument structure for set and get I would be
concerned about the loss of compiler protection for the buffer argument;

Agreed, I missed that.


Sadly, the pattern of

struct getxattr_args args;

memset(, 0, sizeof(args));

args. = ...

__vfs_getxattr(};

...

__vfs_setxattr();

would be nice, so maybe we need to cool our jets and instead:

struct xattr_gs_args {
struct dentry *dentry;
struct inode *inode;
const char *name;
union {
void *buffer;
const void *value;
};
size_t size;
int flags;
};

value _must_ be referenced for all setxattr operations, buffer for getxattr 
operations (how can we enforce that?).


struct getxattr_args {
struct dentry *dentry;
struct inode *inode;
const char *name;
void *buffer;
size_t size;
int flags;

Does 'get' need flags?

:-) That was the _whole_ point of the patch, flags is how we pass in the 
recursion so that a security/internal getxattr call has the rights to 
acquire the data in the lower layer(s).


-- Mark



___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


Re: [f2fs-dev] [PATCH v4] Add flags option to get xattr method paired to __vfs_getxattr

2019-08-16 Thread Jan Kara
On Thu 15-08-19 08:49:58, Mark Salyzyn wrote:
> Add a flag option to get xattr method that could have a bit flag of
> XATTR_NOSECURITY passed to it.  XATTR_NOSECURITY is generally then
> set in the __vfs_getxattr path.
> 
> This handles the case of a union filesystem driver that is being
> requested by the security layer to report back the xattr data.
> 
> For the use case where access is to be blocked by the security layer.
> 
> The path then could be security(dentry) ->
> __vfs_getxattr(dentry...XATTR_NOSECUIRTY) ->
> handler->get(dentry...XATTR_NOSECURITY) ->
> __vfs_getxattr(lower_dentry...XATTR_NOSECUIRTY) ->
> lower_handler->get(lower_dentry...XATTR_NOSECUIRTY)
> which would report back through the chain data and success as
> expected, the logging security layer at the top would have the
> data to determine the access permissions and report back the target
> context that was blocked.
> 
> Without the get handler flag, the path on a union filesystem would be
> the errant security(dentry) -> __vfs_getxattr(dentry) ->
> handler->get(dentry) -> vfs_getxattr(lower_dentry) -> nested ->
> security(lower_dentry, log off) -> lower_handler->get(lower_dentry)
> which would report back through the chain no data, and -EACCES.
> 
> For selinux for both cases, this would translate to a correctly
> determined blocked access. In the first case with this change a correct avc
> log would be reported, in the second legacy case an incorrect avc log
> would be reported against an uninitialized u:object_r:unlabeled:s0
> context making the logs cosmetically useless for audit2allow.
> 
> This patch series is inert and is the wide-spread addition of the
> flags option for xattr functions, and a replacement of _vfs_getxattr
> with __vfs_getxattr(...XATTR_NOSECURITY).
> 
> Signed-off-by: Mark Salyzyn 
> Cc: Stephen Smalley 
> Cc: linux-ker...@vger.kernel.org
> Cc: kernel-t...@android.com
> Cc: linux-security-mod...@vger.kernel.org
> Cc: Jan Kara 
> Cc: sta...@vger.kernel.org # 4.4, 4.9, 4.14 & 4.19

The patch looks good to me. I can see you've missed conversion of one place
in ext2 which 0-day spotted so that will need fixing. Otherwise feel free
to add:

Acked-by: Jan Kara 

Honza
> ---
> v4:
> - ifdef __KERNEL__ around XATTR_NOSECURITY to
>   keep it colocated in uapi headers.
> 
> v3:
> - poor aim on ubifs not ubifs_xattr_get, but static xattr_get
> 
> v2:
> - Missed a spot: ubifs, erofs and afs.
> 
> v1:
> - Removed from an overlayfs patch set, and made independent.
>   Expect this to be the basis of some security improvements.
> ---
>  drivers/staging/erofs/xattr.c |  3 ++-
>  fs/9p/acl.c   |  3 ++-
>  fs/9p/xattr.c |  3 ++-
>  fs/afs/xattr.c|  8 +++
>  fs/btrfs/xattr.c  |  3 ++-
>  fs/ceph/xattr.c   |  3 ++-
>  fs/cifs/xattr.c   |  2 +-
>  fs/ecryptfs/inode.c   |  6 --
>  fs/ecryptfs/mmap.c|  2 +-
>  fs/ext2/xattr_trusted.c   |  2 +-
>  fs/ext2/xattr_user.c  |  2 +-
>  fs/ext4/xattr_security.c  |  2 +-
>  fs/ext4/xattr_trusted.c   |  2 +-
>  fs/ext4/xattr_user.c  |  2 +-
>  fs/f2fs/xattr.c   |  4 ++--
>  fs/fuse/xattr.c   |  4 ++--
>  fs/gfs2/xattr.c   |  3 ++-
>  fs/hfs/attr.c |  2 +-
>  fs/hfsplus/xattr.c|  3 ++-
>  fs/hfsplus/xattr_trusted.c|  3 ++-
>  fs/hfsplus/xattr_user.c   |  3 ++-
>  fs/jffs2/security.c   |  3 ++-
>  fs/jffs2/xattr_trusted.c  |  3 ++-
>  fs/jffs2/xattr_user.c |  3 ++-
>  fs/jfs/xattr.c|  5 +++--
>  fs/kernfs/inode.c |  3 ++-
>  fs/nfs/nfs4proc.c |  6 --
>  fs/ocfs2/xattr.c  |  9 +---
>  fs/orangefs/xattr.c   |  3 ++-
>  fs/overlayfs/super.c  |  8 ---
>  fs/posix_acl.c|  2 +-
>  fs/reiserfs/xattr_security.c  |  3 ++-
>  fs/reiserfs/xattr_trusted.c   |  3 ++-
>  fs/reiserfs/xattr_user.c  |  3 ++-
>  fs/squashfs/xattr.c   |  2 +-
>  fs/ubifs/xattr.c  |  3 ++-
>  fs/xattr.c| 36 +++
>  fs/xfs/xfs_xattr.c|  3 ++-
>  include/linux/xattr.h |  9 
>  include/uapi/linux/xattr.h|  7 --
>  mm/shmem.c|  3 ++-
>  net/socket.c  |  3 ++-
>  security/commoncap.c  |  6 --
>  security/integrity/evm/evm_main.c |  3 ++-
>  security/selinux/hooks.c  | 11 ++
>  security/smack/smack_lsm.c|  5 +++--
>  46 files changed, 126 insertions(+), 84 deletions(-)
> 
> diff --git a/drivers/staging/erofs/xattr.c b/drivers/staging/erofs/xattr.c
> index df40654b9fbb..69440065432c 100644
> --- 

Re: [f2fs-dev] kernel BUG at fs/f2fs/segment.c:2391 during xfstest generic/204

2019-08-16 Thread Chao Yu
Hi Eric,

Sorry for late reply...

I only hit ENOSPC error:

QA output created by 204
line 82: echo: write error: No space left on device

What is your mkfs/mount option?

On 2019/7/30 1:41, Eric Biggers wrote:
> On xfstest generic/204 on f2fs, I'm getting a kernel BUG.
> 
> It bisects to:
> 
>   commit 1cb50f87e10696e8cc61fb62d0d948e11b0e6dc1
>   Author: Jaegeuk Kim 
>   Date:   Fri Jul 6 16:47:34 2018 -0700
> 
>   f2fs: do checkpoint in kill_sb
> 
> Here is the BUG, on v5.3-rc2:
> 
> generic/204 1s ...[10:34:22][6.005271] run fstests generic/204 at 
> 2019-07-29 10:34:22
> [ cut here ]
> kernel BUG at fs/f2fs/segment.c:2391!
> invalid opcode:  [#1] SMP
> CPU: 1 PID: 111 Comm: kworker/u4:2 Not tainted 5.3.0-rc2 #4
> Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.12.0-1 
> 04/01/2014
> Workqueue: writeback wb_workfn (flush-254:32)
> RIP: 0010:get_new_segment fs/f2fs/segment.c:2382 [inline]
> RIP: 0010:new_curseg+0x350/0x360 fs/f2fs/segment.c:2512
> Code: 8b 7b 48 44 89 ea 41 0f af f6 e8 5b cb 06 00 41 8b 97 18 0b 00 00 41 89 
> c2 41 0f af d6 39 d0 0f 82 97 fe ff ff e9 a7 fd ff ff <0f> 0b 45 31 e4 45 31 
> ed e9 47 f2
> RSP: 0018:c945f5c8 EFLAGS: 00010246
> RAX: 0031 RBX: 88807b533800 RCX: 0040
> RDX: 0031 RSI:  RDI: 88807af35b60
> RBP: c945f618 R08: 000a R09: 0001
> R10: 88807b533828 R11: 0001 R12: 
> R13: 0001 R14:  R15: 888078d3c000
> FS:  () GS:88807fd0() knlGS:
> CS:  0010 DS:  ES:  CR0: 80050033
> CR2: 55db93c6b2d8 CR3: 78c43005 CR4: 00760ee0
> DR0:  DR1:  DR2: 
> DR3:  DR6: fffe0ff0 DR7: 0400
> PKRU: 5554
> Call Trace:
>  allocate_segment_by_default+0x9c/0x100 fs/f2fs/segment.c:2651
>  f2fs_allocate_data_block+0x1f3/0x600 fs/f2fs/segment.c:3101
>  do_write_page+0x9d/0x110 fs/f2fs/segment.c:3165
>  f2fs_do_write_node_page+0x35/0xb0 fs/f2fs/segment.c:3216
>  __write_node_page+0x290/0x660 fs/f2fs/node.c:1574
>  f2fs_sync_node_pages+0x6e1/0x790 fs/f2fs/node.c:1843
>  block_operations fs/f2fs/checkpoint.c:1225 [inline]
>  f2fs_write_checkpoint+0x282/0x920 fs/f2fs/checkpoint.c:1576
>  f2fs_sync_fs+0xc6/0x1b0 fs/f2fs/super.c:1116
>  f2fs_balance_fs_bg+0x107/0x300 fs/f2fs/segment.c:557
>  f2fs_write_node_pages+0x55/0x310 fs/f2fs/node.c:1931
>  do_writepages+0x43/0xf0 mm/page-writeback.c:2342
>  __writeback_single_inode+0x56/0x5b0 fs/fs-writeback.c:1364
>  writeback_sb_inodes+0x253/0x580 fs/fs-writeback.c:1628
>  wb_writeback+0x10f/0x480 fs/fs-writeback.c:1804
>  wb_do_writeback fs/fs-writeback.c:1949 [inline]
>  wb_workfn+0xa9/0x570 fs/fs-writeback.c:1990
>  process_one_work+0x21c/0x5c0 kernel/workqueue.c:2269
>  worker_thread+0x3a/0x3b0 kernel/workqueue.c:2415
>  kthread+0x124/0x140 kernel/kthread.c:255
>  ret_from_fork+0x24/0x30 arch/x86/entry/entry_64.S:352
> ---[ end trace 63bbe1af16f6dd61 ]---
> RIP: 0010:get_new_segment fs/f2fs/segment.c:2382 [inline]
> RIP: 0010:new_curseg+0x350/0x360 fs/f2fs/segment.c:2512
> Code: 8b 7b 48 44 89 ea 41 0f af f6 e8 5b cb 06 00 41 8b 97 18 0b 00 00 41 89 
> c2 41 0f af d6 39 d0 0f 82 97 fe ff ff e9 a7 fd ff ff <0f> 0b 45 31 e4 45 31 
> ed e9 47 f2
> RSP: 0018:c945f5c8 EFLAGS: 00010246
> RAX: 0031 RBX: 88807b533800 RCX: 0040
> RDX: 0031 RSI:  RDI: 88807af35b60
> RBP: c945f618 R08: 000a R09: 0001
> R10: 88807b533828 R11: 0001 R12: 
> R13: 0001 R14:  R15: 888078d3c000
> FS:  () GS:88807fd0() knlGS:
> CS:  0010 DS:  ES:  CR0: 80050033
> CR2: 55db93c6b2d8 CR3: 78c43005 CR4: 00760ee0
> DR0:  DR1:  DR2: 
> DR3:  DR6: fffe0ff0 DR7: 0400
> PKRU: 5554
> 
> 
> ___
> Linux-f2fs-devel mailing list
> Linux-f2fs-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
> .
> 


___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


Re: [f2fs-dev] [PATCH 2/3] f2fs: fix copying too many bytes in FS_IOC_SETFSLABEL

2019-08-16 Thread Chao Yu
On 2019/8/16 13:55, Eric Biggers wrote:
> From: Eric Biggers 
> 
> Userspace provides a null-terminated string, so don't assume that the
> full FSLABEL_MAX bytes can always be copied.>
> Fixes: 61a3da4d5ef8 ("f2fs: support FS_IOC_{GET,SET}FSLABEL")

It may only copy redundant zero bytes, and will not hit security issue, it
doesn't look like a bug fix?

> Signed-off-by: Eric Biggers 

Anyway, it makes sense to me.

Reviewed-by: Chao Yu 

Thanks,


___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


Re: [f2fs-dev] [PATCH 3/3] f2fs: add missing authorization check in FS_IOC_SETFSLABEL

2019-08-16 Thread Chao Yu
On 2019/8/16 13:55, Eric Biggers wrote:
> From: Eric Biggers 
> 
> FS_IOC_SETFSLABEL modifies the filesystem superblock, so it shouldn't be
> allowed to regular users.  Require CAP_SYS_ADMIN, like xfs and btrfs do.
> 
> Fixes: 61a3da4d5ef8 ("f2fs: support FS_IOC_{GET,SET}FSLABEL")
> Signed-off-by: Eric Biggers 

Reviewed-by: Chao Yu 

Thanks,


___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


[f2fs-dev] [PATCH V4 0/8] Consolidate FS read I/O callbacks code

2019-08-16 Thread Chandan Rajendra
This patchset moves the "FS read I/O callbacks" code into a file of its
own (i.e. fs/read_callbacks.c) and modifies the generic
do_mpage_readpge() to make use of the functionality provided.

"FS read I/O callbacks" code implements the state machine that needs
to be executed after reading data from files that are encrypted and/or
have verity metadata associated with them.

With these changes in place, the patchset changes Ext4 to use
mpage_readpage[s] instead of its own custom ext4_readpage[s]()
functions. This is done to reduce duplication of code across
filesystems. Also, "FS read I/O callbacks" source files will be built
only if CONFIG_FS_ENCRYPTION is enabled.

The patchset also modifies fs/buffer.c to get file
encryption/decryption to work with subpage-sized blocks.

The patches can also be obtained from
https://github.com/chandanr/linux.git at branch subpage-encryption-v4.

Changelog:
V3 -> V4:
   1. A new buffer_head flag (i.e. BH_Read_Cb) is introduced to reliably
  check if a buffer head's content has to be decrypted.
   2. Fix layering violation. Now the code flow for decryption happens as shown 
below,
  FS => read callbacks => fscrypt
   3. Select FS_READ_CALLBACKS from FS specific kconfig file if FS_ENCRYPTION
  is enabled.
   4. Make 'struct read_callbacks_ctx' an opaque structure.
   5. Make use of FS' endio function rather than implementing one in read
  callbacks.
   6. Make read_callbacks.h self-contained.
   7. Split patchset to separate out ext4 and f2fs changes.
   
V2 -> V3:
1. Split the V2 patch "Consolidate 'read callbacks' into a new file" into
   three patches,
   - Introduce the read_callbacks functionality.
   - Convert encryption to use read_callbacks.
   - Remove union from struct fscrypt_context.
2. fs/Kconfig
   Do not explicitly set the default value of 'n' for FS_READ_CALLBACKS.
3. fs/crypto/Kconfig
   Select CONFIG_FS_READ_CALLBACKS only if CONFIG_BLOCK is selected.
4. Remove verity associated code in read_callbacks code.
5. Introduce a callback argument to read_callbacks_setup() function
   which gets invoked for each page for bio. F2FS uses this to perform
   custom operations like decrementing the value of f2fs_sb_info->nr_pages[].
6. Encapsulate the details of "read callbacks" (e.g. Usage of "struct
   read_callbacks *ctx") within its own functions. When CONFIG_FS_READ_CALLBACKS
   is set to 'n', the corresponding stub functions return approriate error
   values.
7. Split fscrypt_decrypt() function into fscrypt_decrypt_bio() and
   fscrypt_decrypt_bh().
8. Split end_read_callbacks() function into end_read_callbacks_bio() and
   end_read_callbacks_bh().

V1 -> V2:
1. Removed the phrase "post_read_process" from file names and
   functions. Instead we now use the phrase "read_callbacks" in its
   place.
2. When performing changes associated with (1), the changes made by
   the patch "Remove the term 'bio' from post read processing" are
   made in the earlier patch "Consolidate 'read callbacks' into a new
   file". Hence the patch "Remove the term 'bio' from post read
   processing" is removed from the patchset.

RFC V2 -> V1:
1. Test and verify FS_CFLG_OWN_PAGES subset of fscrypt_encrypt_page()
   code by executing fstests on UBIFS.
2. Implement F2fs function call back to check if the contents of a
   page holding a verity file's data needs to be verified.

RFC V1 -> RFC V2:
1. Describe the purpose of "Post processing code" in the cover letter.
2. Fix build errors when CONFIG_FS_VERITY is enabled.

Chandan Rajendra (8):
  buffer_head: Introduce BH_Read_Cb flag
  FS: Introduce read callbacks
  fs/mpage.c: Integrate read callbacks
  fs/buffer.c: add decryption support via read_callbacks
  f2fs: Use read_callbacks for decrypting file data
  ext4: Wire up ext4_readpage[s] to use mpage_readpage[s]
  ext4: Enable encryption for subpage-sized blocks
  fscrypt: remove struct fscrypt_ctx

 Documentation/filesystems/fscrypt.rst |   4 +-
 fs/Kconfig|   3 +
 fs/Makefile   |   1 +
 fs/buffer.c   |  33 ++-
 fs/crypto/bio.c   |  43 
 fs/crypto/crypto.c|  89 +---
 fs/crypto/fscrypt_private.h   |   3 -
 fs/ext4/Kconfig   |   1 +
 fs/ext4/Makefile  |   2 +-
 fs/ext4/inode.c   |   5 +-
 fs/ext4/readpage.c| 295 --
 fs/ext4/super.c   |   7 -
 fs/f2fs/Kconfig   |   1 +
 fs/f2fs/data.c| 109 +-
 fs/f2fs/f2fs.h|   2 -
 fs/f2fs/super.c   |   9 +-
 fs/mpage.c|  24 ++-
 fs/read_callbacks.c   | 285 +
 include/linux/buffer_head.h   |   2 +
 include/linux/fscrypt.h   |  38 
 include/linux/read_callbacks.h|  48 +
 21 files changed, 402 

Re: [f2fs-dev] [PATCH 0/3] f2fs: fixes for FS_IOC_{GET,SET}FSLABEL

2019-08-16 Thread Chao Yu
Eric, thanks for all the fixes.

Thanks,

On 2019/8/16 13:55, Eric Biggers wrote:
> Fix some bugs in the f2fs implementation of the FS_IOC_GETFSLABEL and
> FS_IOC_SETFSLABEL ioctls.
> 
> Eric Biggers (3):
>   f2fs: fix buffer overruns in FS_IOC_{GET,SET}FSLABEL
>   f2fs: fix copying too many bytes in FS_IOC_SETFSLABEL
>   f2fs: add missing authorization check in FS_IOC_SETFSLABEL
> 
>  fs/f2fs/file.c | 27 +--
>  1 file changed, 9 insertions(+), 18 deletions(-)
> 


___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


Re: [f2fs-dev] [PATCH 1/3] f2fs: fix buffer overruns in FS_IOC_{GET, SET}FSLABEL

2019-08-16 Thread Chao Yu
On 2019/8/16 13:55, Eric Biggers wrote:
> From: Eric Biggers 
> 
> utf16s_to_utf8s() and utf8s_to_utf16s() take the number of characters,
> not the number of bytes.
> 
> Fixes: 61a3da4d5ef8 ("f2fs: support FS_IOC_{GET,SET}FSLABEL")
> Signed-off-by: Eric Biggers 

Reviewed-by: Chao Yu 

Thanks,


___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


[f2fs-dev] [PATCH V4 4/8] fs/buffer.c: add decryption support via read_callbacks

2019-08-16 Thread Chandan Rajendra
This commit sets up read_callbacks context for buffer heads whose
contents need to be decrypted on endio.

Signed-off-by: Chandan Rajendra 
---
 fs/buffer.c | 33 ++---
 1 file changed, 22 insertions(+), 11 deletions(-)

diff --git a/fs/buffer.c b/fs/buffer.c
index ce357602f471..96c4c9840746 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -45,6 +45,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 static int fsync_buffers_list(spinlock_t *lock, struct list_head *list);
@@ -245,11 +246,7 @@ __find_get_block_slow(struct block_device *bdev, sector_t 
block)
return ret;
 }
 
-/*
- * I/O completion handler for block_read_full_page() - pages
- * which come unlocked at the end of I/O.
- */
-static void end_buffer_async_read(struct buffer_head *bh, int uptodate)
+void end_buffer_async_read(struct buffer_head *bh, int uptodate)
 {
unsigned long flags;
struct buffer_head *first;
@@ -257,8 +254,6 @@ static void end_buffer_async_read(struct buffer_head *bh, 
int uptodate)
struct page *page;
int page_uptodate = 1;
 
-   BUG_ON(!buffer_async_read(bh));
-
page = bh->b_page;
if (uptodate) {
set_buffer_uptodate(bh);
@@ -306,6 +301,17 @@ static void end_buffer_async_read(struct buffer_head *bh, 
int uptodate)
return;
 }
 
+/*
+ * I/O completion handler for block_read_full_page().  Pages are unlocked
+ * after the I/O completes and the read callbacks (if any) have executed.
+ */
+static void __end_buffer_async_read(struct buffer_head *bh, int uptodate)
+{
+   BUG_ON(!buffer_async_read(bh));
+
+   read_callbacks_endio_bh(bh, uptodate, end_buffer_async_read);
+}
+
 /*
  * Completion handler for block_write_full_page() - pages which are unlocked
  * during I/O, and which have PageWriteback cleared upon I/O completion.
@@ -378,7 +384,7 @@ EXPORT_SYMBOL(end_buffer_async_write);
  */
 static void mark_buffer_async_read(struct buffer_head *bh)
 {
-   bh->b_end_io = end_buffer_async_read;
+   bh->b_end_io = __end_buffer_async_read;
set_buffer_async_read(bh);
 }
 
@@ -2293,10 +2299,15 @@ int block_read_full_page(struct page *page, get_block_t 
*get_block)
 */
for (i = 0; i < nr; i++) {
bh = arr[i];
-   if (buffer_uptodate(bh))
-   end_buffer_async_read(bh, 1);
-   else
+   if (buffer_uptodate(bh)) {
+   __end_buffer_async_read(bh, 1);
+   } else {
+   if (WARN_ON(read_callbacks_setup_bh(inode, bh))) {
+   __end_buffer_async_read(bh, 0);
+   continue;
+   }
submit_bh(REQ_OP_READ, 0, bh);
+   }
}
return 0;
 }
-- 
2.19.1



___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


[f2fs-dev] [PATCH V4 6/8] ext4: Wire up ext4_readpage[s] to use mpage_readpage[s]

2019-08-16 Thread Chandan Rajendra
Now that do_mpage_readpage() is "post read process" aware, this commit
gets ext4_readpage[s] to use mpage_readpage[s] and deletes ext4's
readpage.c since the associated functionality is not required anymore.
---
 fs/ext4/Makefile   |   2 +-
 fs/ext4/inode.c|   5 +-
 fs/ext4/readpage.c | 295 -
 3 files changed, 3 insertions(+), 299 deletions(-)
 delete mode 100644 fs/ext4/readpage.c

diff --git a/fs/ext4/Makefile b/fs/ext4/Makefile
index 8fdfcd3c3e04..7c38803a808d 100644
--- a/fs/ext4/Makefile
+++ b/fs/ext4/Makefile
@@ -8,7 +8,7 @@ obj-$(CONFIG_EXT4_FS) += ext4.o
 ext4-y := balloc.o bitmap.o block_validity.o dir.o ext4_jbd2.o extents.o \
extents_status.o file.o fsmap.o fsync.o hash.o ialloc.o \
indirect.o inline.o inode.o ioctl.o mballoc.o migrate.o \
-   mmp.o move_extent.o namei.o page-io.o readpage.o resize.o \
+   mmp.o move_extent.o namei.o page-io.o resize.o \
super.o symlink.o sysfs.o xattr.o xattr_trusted.o xattr_user.o
 
 ext4-$(CONFIG_EXT4_FS_POSIX_ACL)   += acl.o
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 58597db621e1..a1136faed9d3 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -3361,8 +3361,7 @@ static int ext4_readpage(struct file *file, struct page 
*page)
ret = ext4_readpage_inline(inode, page);
 
if (ret == -EAGAIN)
-   return ext4_mpage_readpages(page->mapping, NULL, page, 1,
-   false);
+   return mpage_readpage(page, ext4_get_block);
 
return ret;
 }
@@ -3377,7 +3376,7 @@ ext4_readpages(struct file *file, struct address_space 
*mapping,
if (ext4_has_inline_data(inode))
return 0;
 
-   return ext4_mpage_readpages(mapping, pages, NULL, nr_pages, true);
+   return mpage_readpages(mapping, pages, nr_pages, ext4_get_block);
 }
 
 static void ext4_invalidatepage(struct page *page, unsigned int offset,
diff --git a/fs/ext4/readpage.c b/fs/ext4/readpage.c
deleted file mode 100644
index 75cef6af6080..
--- a/fs/ext4/readpage.c
+++ /dev/null
@@ -1,295 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- * linux/fs/ext4/readpage.c
- *
- * Copyright (C) 2002, Linus Torvalds.
- * Copyright (C) 2015, Google, Inc.
- *
- * This was originally taken from fs/mpage.c
- *
- * The intent is the ext4_mpage_readpages() function here is intended
- * to replace mpage_readpages() in the general case, not just for
- * encrypted files.  It has some limitations (see below), where it
- * will fall back to read_block_full_page(), but these limitations
- * should only be hit when page_size != block_size.
- *
- * This will allow us to attach a callback function to support ext4
- * encryption.
- *
- * If anything unusual happens, such as:
- *
- * - encountering a page which has buffers
- * - encountering a page which has a non-hole after a hole
- * - encountering a page with non-contiguous blocks
- *
- * then this code just gives up and calls the buffer_head-based read function.
- * It does handle a page which has holes at the end - that is a common case:
- * the end-of-file on blocksize < PAGE_SIZE setups.
- *
- */
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include "ext4.h"
-
-static inline bool ext4_bio_encrypted(struct bio *bio)
-{
-#ifdef CONFIG_FS_ENCRYPTION
-   return unlikely(bio->bi_private != NULL);
-#else
-   return false;
-#endif
-}
-
-/*
- * I/O completion handler for multipage BIOs.
- *
- * The mpage code never puts partial pages into a BIO (except for end-of-file).
- * If a page does not map to a contiguous run of blocks then it simply falls
- * back to block_read_full_page().
- *
- * Why is this?  If a page's completion depends on a number of different BIOs
- * which can complete in any order (or at the same time) then determining the
- * status of that page is hard.  See end_buffer_async_read() for the details.
- * There is no point in duplicating all that complexity.
- */
-static void mpage_end_io(struct bio *bio)
-{
-   struct bio_vec *bv;
-   int i;
-   struct bvec_iter_all iter_all;
-
-   if (ext4_bio_encrypted(bio)) {
-   if (bio->bi_status) {
-   fscrypt_release_ctx(bio->bi_private);
-   } else {
-   fscrypt_enqueue_decrypt_bio(bio->bi_private, bio);
-   return;
-   }
-   }
-   bio_for_each_segment_all(bv, bio, i, iter_all) {
-   struct page *page = bv->bv_page;
-
-   if (!bio->bi_status) {
-   SetPageUptodate(page);
-   } else {
-   ClearPageUptodate(page);
-   SetPageError(page);
-   }
-   unlock_page(page);
-   }
-
-   bio_put(bio);

[f2fs-dev] [PATCH V4 2/8] FS: Introduce read callbacks

2019-08-16 Thread Chandan Rajendra
Read callbacks implements a state machine to be executed after a
buffered read I/O is completed. They help in further processing the file
data read from the backing store. Currently, decryption is the only post
processing step to be supported.

The execution of the state machine is to be initiated by the endio
function associated with the read operation.

Signed-off-by: Chandan Rajendra 
---
 fs/Kconfig |   3 +
 fs/Makefile|   1 +
 fs/ext4/Kconfig|   1 +
 fs/f2fs/Kconfig|   1 +
 fs/read_callbacks.c| 285 +
 include/linux/read_callbacks.h |  48 ++
 6 files changed, 339 insertions(+)
 create mode 100644 fs/read_callbacks.c
 create mode 100644 include/linux/read_callbacks.h

diff --git a/fs/Kconfig b/fs/Kconfig
index 3e6d3101f3ff..2d96a58d7418 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -20,6 +20,9 @@ if BLOCK
 config FS_IOMAP
bool
 
+config FS_READ_CALLBACKS
+   bool
+
 source "fs/ext2/Kconfig"
 source "fs/ext4/Kconfig"
 source "fs/jbd2/Kconfig"
diff --git a/fs/Makefile b/fs/Makefile
index 427fec226fae..942808f83472 100644
--- a/fs/Makefile
+++ b/fs/Makefile
@@ -53,6 +53,7 @@ obj-$(CONFIG_SYSCTL)  += drop_caches.o
 
 obj-$(CONFIG_FHANDLE)  += fhandle.o
 obj-$(CONFIG_FS_IOMAP) += iomap.o
+obj-$(CONFIG_FS_READ_CALLBACKS) += read_callbacks.o
 
 obj-y  += quota/
 
diff --git a/fs/ext4/Kconfig b/fs/ext4/Kconfig
index 06f77ca7f36e..2e24df67f085 100644
--- a/fs/ext4/Kconfig
+++ b/fs/ext4/Kconfig
@@ -38,6 +38,7 @@ config EXT4_FS
select CRYPTO
select CRYPTO_CRC32C
select FS_IOMAP
+   select FS_READ_CALLBACKS if FS_ENCRYPTION
help
  This is the next generation of the ext3 filesystem.
 
diff --git a/fs/f2fs/Kconfig b/fs/f2fs/Kconfig
index e57cc754d543..1e1424940d1b 100644
--- a/fs/f2fs/Kconfig
+++ b/fs/f2fs/Kconfig
@@ -4,6 +4,7 @@ config F2FS_FS
select CRYPTO
select CRYPTO_CRC32
select F2FS_FS_XATTR if FS_ENCRYPTION
+   select FS_READ_CALLBACKS if FS_ENCRYPTION
help
  F2FS is based on Log-structured File System (LFS), which supports
  versatile "flash-friendly" features. The design has been focused on
diff --git a/fs/read_callbacks.c b/fs/read_callbacks.c
new file mode 100644
index ..32d9b8d17964
--- /dev/null
+++ b/fs/read_callbacks.c
@@ -0,0 +1,285 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * This file tracks the state machine that needs to be executed after reading
+ * data from files that are encrypted and/or have verity metadata associated
+ * with them.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define NUM_PREALLOC_READ_CALLBACK_CTXS128
+
+static struct kmem_cache *read_callbacks_ctx_cache;
+static mempool_t *read_callbacks_ctx_pool;
+
+/* Read callback state machine steps */
+enum read_callbacks_step {
+   STEP_INITIAL = 0,
+   STEP_DECRYPT,
+};
+
+struct read_callbacks_ctx {
+   struct inode *inode;
+   struct bio *bio;
+   struct buffer_head *bh;
+   union {
+   end_bio_func_t end_bio;
+
+   struct {
+   end_bh_func_t end_bh;
+   int bh_uptodate;
+   };
+   };
+   struct work_struct work;
+   unsigned int enabled_steps;
+   enum read_callbacks_step cur_step;
+};
+
+static void read_callbacks(struct read_callbacks_ctx *ctx);
+
+static void free_read_callbacks_ctx(struct read_callbacks_ctx *ctx)
+{
+   mempool_free(ctx, read_callbacks_ctx_pool);
+}
+
+static struct read_callbacks_ctx *get_read_callbacks_ctx(struct inode *inode)
+{
+   struct read_callbacks_ctx *ctx = NULL;
+   unsigned int enabled_steps = 0;
+
+   if (IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode))
+   enabled_steps |= 1 << STEP_DECRYPT;
+
+   if (enabled_steps) {
+   ctx = mempool_alloc(read_callbacks_ctx_pool, GFP_NOFS);
+   if (!ctx)
+   return ERR_PTR(-ENOMEM);
+
+   ctx->inode = inode;
+   ctx->enabled_steps = enabled_steps;
+   ctx->cur_step = STEP_INITIAL;
+   }
+
+   return ctx;
+}
+
+static void decrypt_bio(struct bio *bio)
+{
+   struct bio_vec *bv;
+   int i;
+   struct bvec_iter_all iter_all;
+
+   bio_for_each_segment_all(bv, bio, i, iter_all) {
+   struct page *page = bv->bv_page;
+   int ret = fscrypt_decrypt_pagecache_blocks(page, bv->bv_len,
+  bv->bv_offset);
+   if (ret)
+   SetPageError(page);
+   }
+}
+
+static void decrypt_bh(struct buffer_head *bh)
+{
+   struct page *page;
+   int ret;
+
+   page = bh->b_page;
+
+   ret = fscrypt_decrypt_pagecache_blocks(page, bh->b_size,
+

[f2fs-dev] [PATCH V4 7/8] ext4: Enable encryption for subpage-sized blocks

2019-08-16 Thread Chandan Rajendra
Now that we have the code to support encryption for subpage-sized
blocks, this commit removes the conditional check in filesystem mount
code.

The commit also changes the support statement in
Documentation/filesystems/fscrypt.rst to reflect the fact that
encryption of filesystems with blocksize less than page size now works.

Signed-off-by: Chandan Rajendra 
---
 Documentation/filesystems/fscrypt.rst | 4 ++--
 fs/ext4/super.c   | 7 ---
 2 files changed, 2 insertions(+), 9 deletions(-)

diff --git a/Documentation/filesystems/fscrypt.rst 
b/Documentation/filesystems/fscrypt.rst
index 08c23b60e016..c3efe86bf2b2 100644
--- a/Documentation/filesystems/fscrypt.rst
+++ b/Documentation/filesystems/fscrypt.rst
@@ -213,8 +213,8 @@ Contents encryption
 ---
 
 For file contents, each filesystem block is encrypted independently.
-Currently, only the case where the filesystem block size is equal to
-the system's page size (usually 4096 bytes) is supported.
+Starting from Linux kernel 5.4, encryption of filesystems with block
+size less than system's page size is supported.
 
 Each block's IV is set to the logical block number within the file as
 a little endian number, except that:
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 5b92054bf8ea..d580e71ad9c7 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -4322,13 +4322,6 @@ static int ext4_fill_super(struct super_block *sb, void 
*data, int silent)
}
}
 
-   if ((DUMMY_ENCRYPTION_ENABLED(sbi) || ext4_has_feature_encrypt(sb)) &&
-   (blocksize != PAGE_SIZE)) {
-   ext4_msg(sb, KERN_ERR,
-"Unsupported blocksize for fs encryption");
-   goto failed_mount_wq;
-   }
-
if (DUMMY_ENCRYPTION_ENABLED(sbi) && !sb_rdonly(sb) &&
!ext4_has_feature_encrypt(sb)) {
ext4_set_feature_encrypt(sb);
-- 
2.19.1



___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


[f2fs-dev] [PATCH V4 3/8] fs/mpage.c: Integrate read callbacks

2019-08-16 Thread Chandan Rajendra
This commit adds code to make do_mpage_readpage() to be "read callbacks"
aware i.e. for files requiring decryption, do_mpage_readpage() now
sets up the read callbacks state machine when allocating a bio and later
starts execution of the state machine after file data is read from the
underlying disk.

Signed-off-by: Chandan Rajendra 
---
 fs/mpage.c | 24 +---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/fs/mpage.c b/fs/mpage.c
index 3f19da75178b..65e7165644e2 100644
--- a/fs/mpage.c
+++ b/fs/mpage.c
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "internal.h"
 
 /*
@@ -44,7 +45,7 @@
  * status of that page is hard.  See end_buffer_async_read() for the details.
  * There is no point in duplicating all that complexity.
  */
-static void mpage_end_io(struct bio *bio)
+static void end_bio(struct bio *bio)
 {
struct bio_vec *bv;
int i;
@@ -52,13 +53,24 @@ static void mpage_end_io(struct bio *bio)
 
bio_for_each_segment_all(bv, bio, i, iter_all) {
struct page *page = bv->bv_page;
-   page_endio(page, bio_op(bio),
-  blk_status_to_errno(bio->bi_status));
+   int err;
+
+   err = blk_status_to_errno(bio->bi_status);
+
+   if (!err && read_callbacks_failed(page))
+   err = -EIO;
+
+   page_endio(page, bio_op(bio), err);
}
 
bio_put(bio);
 }
 
+static void mpage_end_io(struct bio *bio)
+{
+   read_callbacks_endio_bio(bio, end_bio);
+}
+
 static struct bio *mpage_bio_submit(int op, int op_flags, struct bio *bio)
 {
bio->bi_end_io = mpage_end_io;
@@ -310,6 +322,12 @@ static struct bio *do_mpage_readpage(struct 
mpage_readpage_args *args)
gfp);
if (args->bio == NULL)
goto confused;
+
+   if (read_callbacks_setup_bio(inode, args->bio)) {
+   bio_put(args->bio);
+   args->bio = NULL;
+   goto confused;
+   }
}
 
length = first_hole << blkbits;
-- 
2.19.1



___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


[f2fs-dev] [PATCH V4 5/8] f2fs: Use read_callbacks for decrypting file data

2019-08-16 Thread Chandan Rajendra
F2FS has a copy of "post read processing" code using which encrypted
file data is decrypted. This commit replaces it to make use of the
generic read_callbacks facility.

Signed-off-by: Chandan Rajendra 
---
 fs/f2fs/data.c  | 109 
 fs/f2fs/f2fs.h  |   2 -
 fs/f2fs/super.c |   9 +---
 3 files changed, 11 insertions(+), 109 deletions(-)

diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 757f050c650a..3cf1eca2ece9 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -18,6 +18,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "f2fs.h"
 #include "node.h"
@@ -25,11 +26,6 @@
 #include "trace.h"
 #include 
 
-#define NUM_PREALLOC_POST_READ_CTXS128
-
-static struct kmem_cache *bio_post_read_ctx_cache;
-static mempool_t *bio_post_read_ctx_pool;
-
 static bool __is_cp_guaranteed(struct page *page)
 {
struct address_space *mapping = page->mapping;
@@ -69,19 +65,6 @@ static enum count_type __read_io_type(struct page *page)
return F2FS_RD_DATA;
 }
 
-/* postprocessing steps for read bios */
-enum bio_post_read_step {
-   STEP_INITIAL = 0,
-   STEP_DECRYPT,
-};
-
-struct bio_post_read_ctx {
-   struct bio *bio;
-   struct work_struct work;
-   unsigned int cur_step;
-   unsigned int enabled_steps;
-};
-
 static void __read_end_io(struct bio *bio)
 {
struct page *page;
@@ -93,7 +76,7 @@ static void __read_end_io(struct bio *bio)
page = bv->bv_page;
 
/* PG_error was set if any post_read step failed */
-   if (bio->bi_status || PageError(page)) {
+   if (bio->bi_status || read_callbacks_failed(page)) {
ClearPageUptodate(page);
/* will re-read again later */
ClearPageError(page);
@@ -103,42 +86,8 @@ static void __read_end_io(struct bio *bio)
dec_page_count(F2FS_P_SB(page), __read_io_type(page));
unlock_page(page);
}
-   if (bio->bi_private)
-   mempool_free(bio->bi_private, bio_post_read_ctx_pool);
-   bio_put(bio);
-}
 
-static void bio_post_read_processing(struct bio_post_read_ctx *ctx);
-
-static void decrypt_work(struct work_struct *work)
-{
-   struct bio_post_read_ctx *ctx =
-   container_of(work, struct bio_post_read_ctx, work);
-
-   fscrypt_decrypt_bio(ctx->bio);
-
-   bio_post_read_processing(ctx);
-}
-
-static void bio_post_read_processing(struct bio_post_read_ctx *ctx)
-{
-   switch (++ctx->cur_step) {
-   case STEP_DECRYPT:
-   if (ctx->enabled_steps & (1 << STEP_DECRYPT)) {
-   INIT_WORK(>work, decrypt_work);
-   fscrypt_enqueue_decrypt_work(>work);
-   return;
-   }
-   ctx->cur_step++;
-   /* fall-through */
-   default:
-   __read_end_io(ctx->bio);
-   }
-}
-
-static bool f2fs_bio_post_read_required(struct bio *bio)
-{
-   return bio->bi_private && !bio->bi_status;
+   bio_put(bio);
 }
 
 static void f2fs_read_end_io(struct bio *bio)
@@ -149,15 +98,7 @@ static void f2fs_read_end_io(struct bio *bio)
bio->bi_status = BLK_STS_IOERR;
}
 
-   if (f2fs_bio_post_read_required(bio)) {
-   struct bio_post_read_ctx *ctx = bio->bi_private;
-
-   ctx->cur_step = STEP_INITIAL;
-   bio_post_read_processing(ctx);
-   return;
-   }
-
-   __read_end_io(bio);
+   read_callbacks_endio_bio(bio, __read_end_io);
 }
 
 static void f2fs_write_end_io(struct bio *bio)
@@ -556,8 +497,7 @@ static struct bio *f2fs_grab_read_bio(struct inode *inode, 
block_t blkaddr,
 {
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
struct bio *bio;
-   struct bio_post_read_ctx *ctx;
-   unsigned int post_read_steps = 0;
+   int err;
 
if (!f2fs_is_valid_blkaddr(sbi, blkaddr, DATA_GENERIC))
return ERR_PTR(-EFAULT);
@@ -569,17 +509,10 @@ static struct bio *f2fs_grab_read_bio(struct inode 
*inode, block_t blkaddr,
bio->bi_end_io = f2fs_read_end_io;
bio_set_op_attrs(bio, REQ_OP_READ, op_flag);
 
-   if (f2fs_encrypted_file(inode))
-   post_read_steps |= 1 << STEP_DECRYPT;
-   if (post_read_steps) {
-   ctx = mempool_alloc(bio_post_read_ctx_pool, GFP_NOFS);
-   if (!ctx) {
-   bio_put(bio);
-   return ERR_PTR(-ENOMEM);
-   }
-   ctx->bio = bio;
-   ctx->enabled_steps = post_read_steps;
-   bio->bi_private = ctx;
+   err = read_callbacks_setup_bio(inode, bio);
+   if (err) {
+   bio_put(bio);
+   return ERR_PTR(err);
}
 
return bio;
@@ -2860,27 +2793,3 @@ void f2fs_clear_page_cache_dirty_tag(struct page *page)

[f2fs-dev] [PATCH V4 8/8] fscrypt: remove struct fscrypt_ctx

2019-08-16 Thread Chandan Rajendra
Commit "fscrypt: remove the 'write' part of struct fscrypt_ctx" reduced
"struct fscrypt_ctx" to be used only for decryption. With "read
callbacks" being integrated into Ext4 and F2FS, we don't use "struct
fscrypt_ctx" anymore. Hence this commit removes the structure and the
associated code.

While at it, this commit also removes definitions of
__fscrypt_decrypt_bio() and fscrypt_decrypt_bio() since we have to now
use the APIs provided by read_callbacks facility.

Signed-off-by: Chandan Rajendra 
---
 fs/crypto/bio.c | 43 --
 fs/crypto/crypto.c  | 89 +
 fs/crypto/fscrypt_private.h |  3 --
 include/linux/fscrypt.h | 38 
 4 files changed, 2 insertions(+), 171 deletions(-)

diff --git a/fs/crypto/bio.c b/fs/crypto/bio.c
index b4f47b98ee6d..f65cc3059e5c 100644
--- a/fs/crypto/bio.c
+++ b/fs/crypto/bio.c
@@ -26,49 +26,6 @@
 #include 
 #include "fscrypt_private.h"
 
-static void __fscrypt_decrypt_bio(struct bio *bio, bool done)
-{
-   struct bio_vec *bv;
-   int i;
-   struct bvec_iter_all iter_all;
-
-   bio_for_each_segment_all(bv, bio, i, iter_all) {
-   struct page *page = bv->bv_page;
-   int ret = fscrypt_decrypt_pagecache_blocks(page, bv->bv_len,
-  bv->bv_offset);
-   if (ret)
-   SetPageError(page);
-   else if (done)
-   SetPageUptodate(page);
-   if (done)
-   unlock_page(page);
-   }
-}
-
-void fscrypt_decrypt_bio(struct bio *bio)
-{
-   __fscrypt_decrypt_bio(bio, false);
-}
-EXPORT_SYMBOL(fscrypt_decrypt_bio);
-
-static void completion_pages(struct work_struct *work)
-{
-   struct fscrypt_ctx *ctx = container_of(work, struct fscrypt_ctx, work);
-   struct bio *bio = ctx->bio;
-
-   __fscrypt_decrypt_bio(bio, true);
-   fscrypt_release_ctx(ctx);
-   bio_put(bio);
-}
-
-void fscrypt_enqueue_decrypt_bio(struct fscrypt_ctx *ctx, struct bio *bio)
-{
-   INIT_WORK(>work, completion_pages);
-   ctx->bio = bio;
-   fscrypt_enqueue_decrypt_work(>work);
-}
-EXPORT_SYMBOL(fscrypt_enqueue_decrypt_bio);
-
 int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk,
sector_t pblk, unsigned int len)
 {
diff --git a/fs/crypto/crypto.c b/fs/crypto/crypto.c
index dcf630d7e446..2e5245f5639f 100644
--- a/fs/crypto/crypto.c
+++ b/fs/crypto/crypto.c
@@ -31,24 +31,16 @@
 #include "fscrypt_private.h"
 
 static unsigned int num_prealloc_crypto_pages = 32;
-static unsigned int num_prealloc_crypto_ctxs = 128;
 
 module_param(num_prealloc_crypto_pages, uint, 0444);
 MODULE_PARM_DESC(num_prealloc_crypto_pages,
"Number of crypto pages to preallocate");
-module_param(num_prealloc_crypto_ctxs, uint, 0444);
-MODULE_PARM_DESC(num_prealloc_crypto_ctxs,
-   "Number of crypto contexts to preallocate");
 
 static mempool_t *fscrypt_bounce_page_pool = NULL;
 
-static LIST_HEAD(fscrypt_free_ctxs);
-static DEFINE_SPINLOCK(fscrypt_ctx_lock);
-
 static struct workqueue_struct *fscrypt_read_workqueue;
 static DEFINE_MUTEX(fscrypt_init_mutex);
 
-static struct kmem_cache *fscrypt_ctx_cachep;
 struct kmem_cache *fscrypt_info_cachep;
 
 void fscrypt_enqueue_decrypt_work(struct work_struct *work)
@@ -57,62 +49,6 @@ void fscrypt_enqueue_decrypt_work(struct work_struct *work)
 }
 EXPORT_SYMBOL(fscrypt_enqueue_decrypt_work);
 
-/**
- * fscrypt_release_ctx() - Release a decryption context
- * @ctx: The decryption context to release.
- *
- * If the decryption context was allocated from the pre-allocated pool, return
- * it to that pool.  Else, free it.
- */
-void fscrypt_release_ctx(struct fscrypt_ctx *ctx)
-{
-   unsigned long flags;
-
-   if (ctx->flags & FS_CTX_REQUIRES_FREE_ENCRYPT_FL) {
-   kmem_cache_free(fscrypt_ctx_cachep, ctx);
-   } else {
-   spin_lock_irqsave(_ctx_lock, flags);
-   list_add(>free_list, _free_ctxs);
-   spin_unlock_irqrestore(_ctx_lock, flags);
-   }
-}
-EXPORT_SYMBOL(fscrypt_release_ctx);
-
-/**
- * fscrypt_get_ctx() - Get a decryption context
- * @gfp_flags:   The gfp flag for memory allocation
- *
- * Allocate and initialize a decryption context.
- *
- * Return: A new decryption context on success; an ERR_PTR() otherwise.
- */
-struct fscrypt_ctx *fscrypt_get_ctx(gfp_t gfp_flags)
-{
-   struct fscrypt_ctx *ctx;
-   unsigned long flags;
-
-   /*
-* First try getting a ctx from the free list so that we don't have to
-* call into the slab allocator.
-*/
-   spin_lock_irqsave(_ctx_lock, flags);
-   ctx = list_first_entry_or_null(_free_ctxs,
-   struct fscrypt_ctx, free_list);
-   if (ctx)
-   list_del(>free_list);
-   spin_unlock_irqrestore(_ctx_lock, flags);
-   if (!ctx) {
- 

[f2fs-dev] [PATCH V4 1/8] buffer_head: Introduce BH_Read_Cb flag

2019-08-16 Thread Chandan Rajendra
Decryption of file content encrypted using fscrypt relies on
bio->bi_private holding a pointer to an encryption context
i.e. Decryption operation is not performed for bios having a NULL value
at bio->bi_private.

The same logic cannot be used on buffer heads because,
1. In Btrfs, write_dev_supers() sets bh->b_private to 'struct
   btrfs_device' pointer and submits the buffer head for a write
   operation.
   1. In btrfs/146 test, the write operation fails and hence the
  endio function clears the BH_Uptodate flag.
   2. A read operation initiated later will submit the buffer head to
  the block layer. During endio processing, bh_>b_private would have a
  non-NULL value.

2. Another instance is when an Ext4 metadata block with BH_Uptodate set and
   also part of the in-memory JBD list undergoes the following,
   1. A sync() syscall is invoked by the userspace and the write
  operation on the metadata block is initiated.
   2. Due to an I/O failure, the BH_Uptodate flag is cleared by
  end_buffer_async_write(). The bh->b_private member would be
  pointing to a journal head structure.
   3. In such a case, a read operation invoked on the block mapped by the
  buffer head will initiate a read from the disk since the buffer head is
  missing the BH_Uptodate flag.
   4. After the read I/O request is submitted, end_buffer_async_read()
  will find a non-NULL value at bh->b_private.
   This scenario was observed when executing generic/475 test case.

Hence this commit introduces a new buffer head flag to reliably check for
decryption of a buffer head's contents after the block has been read
from the disk.

Signed-off-by: Chandan Rajendra 
---
 include/linux/buffer_head.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h
index 7b73ef7f902d..08f217ba8114 100644
--- a/include/linux/buffer_head.h
+++ b/include/linux/buffer_head.h
@@ -38,6 +38,7 @@ enum bh_state_bits {
BH_Meta,/* Buffer contains metadata */
BH_Prio,/* Buffer should be submitted with REQ_PRIO */
BH_Defer_Completion, /* Defer AIO completion to workqueue */
+   BH_Read_Cb,  /* Block's contents needs to be decrypted */
 
BH_PrivateStart,/* not a state bit, but the first bit available
 * for private allocation by other entities
@@ -134,6 +135,7 @@ BUFFER_FNS(Unwritten, unwritten)
 BUFFER_FNS(Meta, meta)
 BUFFER_FNS(Prio, prio)
 BUFFER_FNS(Defer_Completion, defer_completion)
+BUFFER_FNS(Read_Cb, read_cb)
 
 #define bh_offset(bh)  ((unsigned long)(bh)->b_data & ~PAGE_MASK)
 
-- 
2.19.1



___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel