From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:47282 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753948AbeBLJmm (ORCPT ); Mon, 12 Feb 2018 04:42:42 -0500 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w1C9d3ci039069 for ; Mon, 12 Feb 2018 04:42:41 -0500 Received: from e33.co.us.ibm.com (e33.co.us.ibm.com [32.97.110.151]) by mx0b-001b2d01.pphosted.com with ESMTP id 2g3552qfkm-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 12 Feb 2018 04:42:41 -0500 Received: from localhost by e33.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 12 Feb 2018 02:42:40 -0700 From: Chandan Rajendra To: linux-ext4@vger.kernel.org Cc: Chandan Rajendra , linux-fsdevel@vger.kernel.org, ebiggers3@gmail.com, linux-fscrypt@vger.kernel.org, tytso@mit.edu Subject: [RFC PATCH V2 04/11] completion_pages: Decrypt all contiguous blocks in a page Date: Mon, 12 Feb 2018 15:13:40 +0530 In-Reply-To: <20180212094347.22071-1-chandan@linux.vnet.ibm.com> References: <20180212094347.22071-1-chandan@linux.vnet.ibm.com> Message-Id: <20180212094347.22071-5-chandan@linux.vnet.ibm.com> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: With blocksize < pagesize, a page can contain more than one block. Hence this commit changes completion_pages() to invoke fscrypt_decrypt_block() for all the contiguous blocks mapped by the page. Signed-off-by: Chandan Rajendra --- fs/crypto/bio.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/fs/crypto/bio.c b/fs/crypto/bio.c index efb0734..378df08 100644 --- a/fs/crypto/bio.c +++ b/fs/crypto/bio.c @@ -40,8 +40,23 @@ static void completion_pages(struct work_struct *work) bio_for_each_segment_all(bv, bio, i) { struct page *page = bv->bv_page; - int ret = fscrypt_decrypt_block(page->mapping->host, page, - PAGE_SIZE, 0, page->index); + struct inode *inode = page->mapping->host; + const unsigned long blocksize = inode->i_sb->s_blocksize; + const unsigned int blkbits = inode->i_blkbits; + u64 page_blk = page->index << (PAGE_SHIFT - blkbits); + u64 blk = page_blk + (bv->bv_offset >> blkbits); + int nr_blks = bv->bv_len >> blkbits; + int ret = 0; + int j; + + for (j = 0; j < nr_blks; j++, blk++) { + ret = fscrypt_decrypt_block(page->mapping->host, + page, blocksize, + bv->bv_offset + (j << blkbits), + blk); + if (ret) + break; + } if (ret) { WARN_ON_ONCE(1); -- 2.9.5