Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp6592252yba; Wed, 1 May 2019 15:48:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqwqG1ljbVN2cgqDS2U4yDPxSLlpsotbqHzDf/W6/5HaZTeMa7yYDXJSiinX6W51BEbADODf X-Received: by 2002:aa7:8a8d:: with SMTP id a13mr536593pfc.2.1556750884379; Wed, 01 May 2019 15:48:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556750884; cv=none; d=google.com; s=arc-20160816; b=isR6oPTGIxFN0ZOZHuSg0wkIDoIstJ+Jq1AiV/qJgZXTNPMWxsxvOLyaaed8ZO5GFq V4mOf0nk6ydrcHOdTi7Nz2GJ/V2dbNsDa1pDPZTJpd9XmlV1sjImQOsC8pXZf/xCHcPH FIQN/TmX/UoBai7xHyB6gD4ZYXHenkCflquTgYS/UvsWoJP03ylS0nlrkoC0jPuEi64l 0GxuSKezNRXuB1+fizeJWWKVaeWMUJ0JvUASKO/eLRaABY1f6jl8b934kq8Znt9YoH5i PYE7Hy/IqBn9fkFvzOpBXkw8x6Uck86z0Aoe8DZUfUjJJRMBNNJeB7qC/ou62WVJ5VF6 1wdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=kE3ozFmhwcnMx38jrPE5IqayYy7MgexcORG45HkQsg4=; b=H8IKjgbNX9LSoH0zVRVjfCkozqu1p+r8qlRCWAHFiSOtSkTsC4CMJ2QHR3Yvizn5wN cUK4gqoYcAR8dyULVPg0uhC+miXfnoh/S4SZAFmuNeoJjX1STOlXXO7j3biZ9oSKglyH Xm2GN3oriYU+HNF2Hpk22DfNBQL5/PCgon6+EbLGc31RTYf69/H+oeyN8rcoGWAOCE4+ noMWr0DxQMlRVbsqa+aP8+gDkckzrTDPtV554P+isLLZ/j9sLU9lAZynV/roUx4a4QDn 990RN+Q3WVJ2J1eJtc6CE0P8ejFM9VGPbq+LrUjVIBJisPP4KErKSOnxheKo3pZ378Ib qJhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=w0Gk63yD; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d22si4333565pgg.389.2019.05.01.15.47.50; Wed, 01 May 2019 15:48:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=w0Gk63yD; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726359AbfEAWqH (ORCPT + 99 others); Wed, 1 May 2019 18:46:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:47212 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726327AbfEAWqH (ORCPT ); Wed, 1 May 2019 18:46:07 -0400 Received: from ebiggers-linuxstation.mtv.corp.google.com (unknown [104.132.1.77]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0093621734; Wed, 1 May 2019 22:46:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556750767; bh=k4J5FpJhlAgJ16Pp5cNsgabyRPAvsfRr0/3EL88VutM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=w0Gk63yDzfh6XsEGODolMNkjblpOM+kEHHCK6/D5gE5zZjNtR/VjmPRiSp+r6Ge2Y IxVoeJiYgeiEa65NEmqzIMCBDS2jj9YOg0jCIsiOYg9XlvKqc4gkjVX2cvIk6bLNBB oSaCpgvtkJH9IdF1SX5CO1gHkoeeTWi25YpqCaQU= From: Eric Biggers To: linux-fscrypt@vger.kernel.org Cc: linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-mtd@lists.infradead.org, linux-fsdevel@vger.kernel.org, Chandan Rajendra Subject: [PATCH 07/13] fscrypt: handle blocksize < PAGE_SIZE in fscrypt_zeroout_range() Date: Wed, 1 May 2019 15:45:09 -0700 Message-Id: <20190501224515.43059-8-ebiggers@kernel.org> X-Mailer: git-send-email 2.21.0.593.g511ec345e18-goog In-Reply-To: <20190501224515.43059-1-ebiggers@kernel.org> References: <20190501224515.43059-1-ebiggers@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Eric Biggers Adjust fscrypt_zeroout_range() to encrypt a block at a time rather than a page at a time, so that it works when blocksize < PAGE_SIZE. This isn't optimized for performance, but then again this function already wasn't optimized for performance. As a future optimization, we could submit much larger bios here. This is in preparation for allowing encryption on ext4 filesystems with blocksize != PAGE_SIZE. This is based on work by Chandan Rajendra. Signed-off-by: Eric Biggers --- fs/crypto/bio.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/fs/crypto/bio.c b/fs/crypto/bio.c index bcab8822217b0..e67e9d4d342b3 100644 --- a/fs/crypto/bio.c +++ b/fs/crypto/bio.c @@ -73,12 +73,12 @@ EXPORT_SYMBOL(fscrypt_enqueue_decrypt_bio); int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk, sector_t pblk, unsigned int len) { + const unsigned int blockbits = inode->i_blkbits; + const unsigned int blocksize = 1 << blockbits; struct page *ciphertext_page; struct bio *bio; int ret, err = 0; - BUG_ON(inode->i_sb->s_blocksize != PAGE_SIZE); - ciphertext_page = fscrypt_alloc_bounce_page(GFP_NOWAIT); if (!ciphertext_page) return -ENOMEM; @@ -86,7 +86,7 @@ int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk, while (len--) { err = fscrypt_crypt_block(inode, FS_ENCRYPT, lblk, ZERO_PAGE(0), ciphertext_page, - PAGE_SIZE, 0, GFP_NOFS); + blocksize, 0, GFP_NOFS); if (err) goto errout; @@ -96,14 +96,11 @@ int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk, goto errout; } bio_set_dev(bio, inode->i_sb->s_bdev); - bio->bi_iter.bi_sector = - pblk << (inode->i_sb->s_blocksize_bits - 9); + bio->bi_iter.bi_sector = pblk << (blockbits - 9); bio_set_op_attrs(bio, REQ_OP_WRITE, 0); - ret = bio_add_page(bio, ciphertext_page, - inode->i_sb->s_blocksize, 0); - if (ret != inode->i_sb->s_blocksize) { + ret = bio_add_page(bio, ciphertext_page, blocksize, 0); + if (WARN_ON(ret != blocksize)) { /* should never happen! */ - WARN_ON(1); bio_put(bio); err = -EIO; goto errout; -- 2.21.0.593.g511ec345e18-goog