From patchwork Thu Oct 17 15:16:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13840218 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 75ABC1DED56; Thu, 17 Oct 2024 15:17:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729178241; cv=none; b=fTsLpToZPiTS4uaqRhCA7OvtFq3EkFOxMkqnC8gWCuIktvIkYeiafvddvvY5LMrUQDZTr27wt7bHuuSEf9W706kZUQ1pPsUbPCfXEXV/p2hYIBYgiN4vjGPyC1x4Hu2N53+VcnZQWkMkk53DJbzhbrkrEQj5pe5F9bJP0sYQR4g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729178241; c=relaxed/simple; bh=O23Gy//oeLZ55SVeNW28SgBcNWSa8ozwd5Oo71wrXH8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fmhJ2QAxCdW/i8NlziF9bjuLYrlXDaGuks4ufiYKuMiqQcAuyjs17oXj4Y3+I4MULDOs3t2H/kwnHWHFieBsNqyn5p8ZCSpxai2nGPerXg7Jobbojdmg0qyeLRLD3/pQJ8kyXnInJirVjQ1tUuPopq4cLKMVxs96aL9AI9UKBG4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=rzZ20EUx; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="rzZ20EUx" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=QvXLg6hq5jvQb9bvdZtTJRsSaVrN4g0Ygii5MFDj5NA=; b=rzZ20EUxGJWQ0Z22D6+KH7C0zx jhhNgAGMl0joCw7WPq5c5SOZoq8yEourvRLxPw7aS3WJm2G9gXGXdxxDXUItpZzNt4UAjrEma3iem txi9d1QzJ3DGt1zbK5g0q+hgiBKxfnjR5x1T32pTFU8zjgrX9hPpIqxX+rVkrmO+iTs8QKS2yxB9H O4YGsG4inPA4OKOKBIdJsHbHhGrNK2Qe3wT/kaPq+fMUkeocr+3nEX7Ok5ZoA0TvBXTC9+lXB4cdx KpzP+nM0dNNbaTnTHM78YZO2wRLA+SCFmR9deIbJTgSmhax7eaha3RQNC9lYoX3tbJFEGT2fvREUA IrY0TWYg==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1t1SFS-0000000BNnF-3Kx4; Thu, 17 Oct 2024 15:17:10 +0000 From: "Matthew Wilcox (Oracle)" To: Tyler Hicks Cc: "Matthew Wilcox (Oracle)" , ecryptfs@vger.kernel.org, Christian Brauner , linux-fsdevel@vger.kernel.org Subject: [PATCH 01/10] ecryptfs: Convert ecryptfs_writepage() to ecryptfs_writepages() Date: Thu, 17 Oct 2024 16:16:56 +0100 Message-ID: <20241017151709.2713048-2-willy@infradead.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241017151709.2713048-1-willy@infradead.org> References: <20241017151709.2713048-1-willy@infradead.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 By adding a ->migrate_folio implementation, theree is no need to keep the ->writepage implementation. The new writepages removes the unnecessary call to SetPageUptodate(); the folio should already be uptodate at this point. Signed-off-by: Matthew Wilcox (Oracle) --- fs/ecryptfs/mmap.c | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c index ceda5555971a..92ea39d907de 100644 --- a/fs/ecryptfs/mmap.c +++ b/fs/ecryptfs/mmap.c @@ -38,32 +38,30 @@ struct page *ecryptfs_get_locked_page(struct inode *inode, loff_t index) return page; } -/** - * ecryptfs_writepage - * @page: Page that is locked before this call is made - * @wbc: Write-back control structure - * - * Returns zero on success; non-zero otherwise - * +/* * This is where we encrypt the data and pass the encrypted data to * the lower filesystem. In OpenPGP-compatible mode, we operate on * entire underlying packets. */ -static int ecryptfs_writepage(struct page *page, struct writeback_control *wbc) +static int ecryptfs_writepages(struct address_space *mapping, + struct writeback_control *wbc) { - int rc; - - rc = ecryptfs_encrypt_page(page); - if (rc) { - ecryptfs_printk(KERN_WARNING, "Error encrypting " - "page (upper index [0x%.16lx])\n", page->index); - ClearPageUptodate(page); - goto out; + struct folio *folio = NULL; + int error; + + while ((folio = writeback_iter(mapping, wbc, folio, &error))) { + error = ecryptfs_encrypt_page(&folio->page); + if (error) { + ecryptfs_printk(KERN_WARNING, + "Error encrypting folio (index [0x%.16lx])\n", + folio->index); + folio_clear_uptodate(folio); + mapping_set_error(mapping, error); + } + folio_unlock(folio); } - SetPageUptodate(page); -out: - unlock_page(page); - return rc; + + return error; } static void strip_xattr_flag(char *page_virt, @@ -548,9 +546,10 @@ const struct address_space_operations ecryptfs_aops = { .dirty_folio = block_dirty_folio, .invalidate_folio = block_invalidate_folio, #endif - .writepage = ecryptfs_writepage, + .writepages = ecryptfs_writepages, .read_folio = ecryptfs_read_folio, .write_begin = ecryptfs_write_begin, .write_end = ecryptfs_write_end, + .migrate_folio = filemap_migrate_folio, .bmap = ecryptfs_bmap, }; From patchwork Thu Oct 17 15:16:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13840195 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC9255FDA7; Thu, 17 Oct 2024 15:17:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729178236; cv=none; b=cWZEJVmpS69cMyOliDcT43sVz3R6lwnsAHxHF9lVTxazK8b6lYSo8OofTvNo49aYarlvCe5jzKGLOd+btbLOa8qfVMar2L8p7AtWACbd1PhNJUfCodrWlAn5MfkKxmQ103mKJZyDNn7Yv23FRl8bqu9CV6Be0sFFYRBXvded8+w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729178236; c=relaxed/simple; bh=1caFjQQZvB3+JN+dIMswr4Vcy1txHMt8bmAs/dJUoLk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TPhNeeAg1aLriJpPCgGLNHyKxZv99pzYTOeM4iFQJ6cq95EcGaJKbm1mbVoqzTlAzTy2KisWz/t8MasgjXHFupKmErB6iIv7SR0xdRTgmtqSlM8KBExMvXr5/md+Vzo6kVudc2cAqMLuBnWXTV5zYzSQ3K+isYlUe7bOR8SqFt4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=p0SmMe3l; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="p0SmMe3l" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=ng0eZp01OgC9cDIHYLX7obIwbMG6Cc8dT+Ls+v/nGIM=; b=p0SmMe3lIKO7KTukY7se+NlyqL Do9yvdvfNlbwxpFepAnwxbzFESd/alDbYJcE4/mRVPz26KVBqItk6rk8UZ+kXj9OkSMFqsCyChIo0 lrnr1k53betDbcaxX8IVNrWqQrlpW+jejKwLdMRpy9xafJO5cp8qyfVyusXiuKcLeCYV8T3mvO0YS ubfaeNlRoD/R2ff6Vc3wIeckJERHoNDg7RFRX7fFtCfHiLl674TeRCsFcJSmI2TcBYW2mh+z59bdN LKu0rh8vvStOSNH0k+D0DTt9C0UQ0PFZYzgkc1hkqXZVhlHmTat2KkkBRkxgCvF6gEykh88mFNPt1 eKSxnBJA==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1t1SFS-0000000BNnH-3gNT; Thu, 17 Oct 2024 15:17:10 +0000 From: "Matthew Wilcox (Oracle)" To: Tyler Hicks Cc: "Matthew Wilcox (Oracle)" , ecryptfs@vger.kernel.org, Christian Brauner , linux-fsdevel@vger.kernel.org Subject: [PATCH 02/10] ecryptfs: Use a folio throughout ecryptfs_read_folio() Date: Thu, 17 Oct 2024 16:16:57 +0100 Message-ID: <20241017151709.2713048-3-willy@infradead.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241017151709.2713048-1-willy@infradead.org> References: <20241017151709.2713048-1-willy@infradead.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Remove the conversion to a struct page. Removes a few hidden calls to compound_head(). Also remove the unnecessary call to ClearPageUptodate(); the uptodate flag is already clear if this function is being called. Signed-off-by: Matthew Wilcox (Oracle) --- fs/ecryptfs/mmap.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c index 92ea39d907de..346ed5f7ff8d 100644 --- a/fs/ecryptfs/mmap.c +++ b/fs/ecryptfs/mmap.c @@ -178,18 +178,18 @@ ecryptfs_copy_up_encrypted_with_header(struct page *page, */ static int ecryptfs_read_folio(struct file *file, struct folio *folio) { - struct page *page = &folio->page; + struct inode *inode = folio->mapping->host; struct ecryptfs_crypt_stat *crypt_stat = - &ecryptfs_inode_to_private(page->mapping->host)->crypt_stat; + &ecryptfs_inode_to_private(inode)->crypt_stat; int rc = 0; if (!crypt_stat || !(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) { - rc = ecryptfs_read_lower_page_segment(page, page->index, 0, - PAGE_SIZE, - page->mapping->host); + rc = ecryptfs_read_lower_page_segment(&folio->page, folio->index, 0, + folio_size(folio), + inode); } else if (crypt_stat->flags & ECRYPTFS_VIEW_AS_ENCRYPTED) { if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR) { - rc = ecryptfs_copy_up_encrypted_with_header(page, + rc = ecryptfs_copy_up_encrypted_with_header(&folio->page, crypt_stat); if (rc) { printk(KERN_ERR "%s: Error attempting to copy " @@ -201,9 +201,9 @@ static int ecryptfs_read_folio(struct file *file, struct folio *folio) } } else { - rc = ecryptfs_read_lower_page_segment( - page, page->index, 0, PAGE_SIZE, - page->mapping->host); + rc = ecryptfs_read_lower_page_segment(&folio->page, + folio->index, 0, folio_size(folio), + inode); if (rc) { printk(KERN_ERR "Error reading page; rc = " "[%d]\n", rc); @@ -211,7 +211,7 @@ static int ecryptfs_read_folio(struct file *file, struct folio *folio) } } } else { - rc = ecryptfs_decrypt_page(page); + rc = ecryptfs_decrypt_page(&folio->page); if (rc) { ecryptfs_printk(KERN_ERR, "Error decrypting page; " "rc = [%d]\n", rc); @@ -219,13 +219,11 @@ static int ecryptfs_read_folio(struct file *file, struct folio *folio) } } out: - if (rc) - ClearPageUptodate(page); - else - SetPageUptodate(page); + if (!rc) + folio_mark_uptodate(folio); ecryptfs_printk(KERN_DEBUG, "Unlocking page with index = [0x%.16lx]\n", - page->index); - unlock_page(page); + folio->index); + folio_unlock(folio); return rc; } From patchwork Thu Oct 17 15:16:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13840196 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0EB7D1DE3DA; Thu, 17 Oct 2024 15:17:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729178237; cv=none; b=ewjt7m91yIUFFA0jDxHg8VTRb/qADQfMvdR4DPPnEdAgbG8Iy9+6lgET52+PxE0qwrLqe+NhSxSeIeDOD3NChlCeiLR/jBU8qjArt+3Xt/o1FVH9Xa+rxAp9wMGEKm/O4ijvPzZ+GqrbrQQivY/wLnV3+EAAVcg/M9W6LaWrW/4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729178237; c=relaxed/simple; bh=8pAWhcWtuSzL12yIxfUX052bkioSKjfVIoE1A9I3nhw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SE/gxrQram9hImFpqeDejXYg43cUP+beKgLS6xd1+iopF8vL8ur8t9w8Ss95Jo75x7WbhQ3ZXMhQhw4VrqlZuHMnG3k/i3Y9U2su8L5qSQOqjnfAnxar68CthW8mAX2SQAFMWusrp+fb6wfnmS84z3KA6EWJQcV7E3+tuCZx4Qk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=YAPcy7cM; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="YAPcy7cM" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=QmpeqJjAnL48nebWrTmTIYxty79g5twXYGWmGvJfuYM=; b=YAPcy7cMy/erGe8B9qAuYsbmEv XuacXjb2ESdtQXcyxuxI39Ekn9OHhj89TLG8tKw9ZfLK436bi2XOXXQ6uKU0Il8TudLaIVydpT2sI k493YW4C0GoIgmEUxw6wfAgYOlRf8SQS6DBJ2+ZY3LXQk3PeV5WrtmdYHFjJL9B4gV7qQMnq0IZNl I3g14JGPGs5ka3kSgM6+ZLon4Md9ftX0C22MTmiDyQWIFfRnwTSrj7p4CgydwE1yZ5730yiZ6QtnP Q7ca29e0H1XwAO7TBo51iibB17cGrl1XZmvZi8QvF+xT4O9R/Uy2xsRfVbua90Rpstdq6LxBJ90x2 xhhC/wYw==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1t1SFT-0000000BNnS-0GIR; Thu, 17 Oct 2024 15:17:11 +0000 From: "Matthew Wilcox (Oracle)" To: Tyler Hicks Cc: "Matthew Wilcox (Oracle)" , ecryptfs@vger.kernel.org, Christian Brauner , linux-fsdevel@vger.kernel.org Subject: [PATCH 03/10] ecryptfs: Convert ecryptfs_copy_up_encrypted_with_header() to take a folio Date: Thu, 17 Oct 2024 16:16:58 +0100 Message-ID: <20241017151709.2713048-4-willy@infradead.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241017151709.2713048-1-willy@infradead.org> References: <20241017151709.2713048-1-willy@infradead.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Both callers have a folio, so pass it in and use it throughout. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Pankaj Raghav --- fs/ecryptfs/mmap.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c index 346ed5f7ff8d..f7525a906ef7 100644 --- a/fs/ecryptfs/mmap.c +++ b/fs/ecryptfs/mmap.c @@ -104,7 +104,7 @@ static void strip_xattr_flag(char *page_virt, * seeing, with the header information inserted. */ static int -ecryptfs_copy_up_encrypted_with_header(struct page *page, +ecryptfs_copy_up_encrypted_with_header(struct folio *folio, struct ecryptfs_crypt_stat *crypt_stat) { loff_t extent_num_in_page = 0; @@ -113,9 +113,9 @@ ecryptfs_copy_up_encrypted_with_header(struct page *page, int rc = 0; while (extent_num_in_page < num_extents_per_page) { - loff_t view_extent_num = ((((loff_t)page->index) + loff_t view_extent_num = ((loff_t)folio->index * num_extents_per_page) - + extent_num_in_page); + + extent_num_in_page; size_t num_header_extents_at_front = (crypt_stat->metadata_size / crypt_stat->extent_size); @@ -123,21 +123,21 @@ ecryptfs_copy_up_encrypted_with_header(struct page *page, /* This is a header extent */ char *page_virt; - page_virt = kmap_local_page(page); + page_virt = kmap_local_folio(folio, 0); memset(page_virt, 0, PAGE_SIZE); /* TODO: Support more than one header extent */ if (view_extent_num == 0) { size_t written; rc = ecryptfs_read_xattr_region( - page_virt, page->mapping->host); + page_virt, folio->mapping->host); strip_xattr_flag(page_virt + 16, crypt_stat); ecryptfs_write_header_metadata(page_virt + 20, crypt_stat, &written); } kunmap_local(page_virt); - flush_dcache_page(page); + flush_dcache_folio(folio); if (rc) { printk(KERN_ERR "%s: Error reading xattr " "region; rc = [%d]\n", __func__, rc); @@ -150,9 +150,9 @@ ecryptfs_copy_up_encrypted_with_header(struct page *page, - crypt_stat->metadata_size); rc = ecryptfs_read_lower_page_segment( - page, (lower_offset >> PAGE_SHIFT), + &folio->page, (lower_offset >> PAGE_SHIFT), (lower_offset & ~PAGE_MASK), - crypt_stat->extent_size, page->mapping->host); + crypt_stat->extent_size, folio->mapping->host); if (rc) { printk(KERN_ERR "%s: Error attempting to read " "extent at offset [%lld] in the lower " @@ -189,7 +189,7 @@ static int ecryptfs_read_folio(struct file *file, struct folio *folio) inode); } else if (crypt_stat->flags & ECRYPTFS_VIEW_AS_ENCRYPTED) { if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR) { - rc = ecryptfs_copy_up_encrypted_with_header(&folio->page, + rc = ecryptfs_copy_up_encrypted_with_header(folio, crypt_stat); if (rc) { printk(KERN_ERR "%s: Error attempting to copy " @@ -293,7 +293,7 @@ static int ecryptfs_write_begin(struct file *file, } else if (crypt_stat->flags & ECRYPTFS_VIEW_AS_ENCRYPTED) { if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR) { rc = ecryptfs_copy_up_encrypted_with_header( - &folio->page, crypt_stat); + folio, crypt_stat); if (rc) { printk(KERN_ERR "%s: Error attempting " "to copy the encrypted content " From patchwork Thu Oct 17 15:16:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13840198 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 87EB81DE4D8; Thu, 17 Oct 2024 15:17:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729178237; cv=none; b=SH7tOehEyQ6bSOkyGL089hyRnGPUK8MEhsE5r1TdhXosbnv5rR/7vmgU20B3nHdblWoOrKK/d7oq+xyvaSDEg78yz/Dj+sjLBD/vk1t7CeyowSktjtm+qmtvSATZyASQ9in+yGSBjyyJryhtju6QJTsvqgQ5Z/cJoyZhiFfx1CM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729178237; c=relaxed/simple; bh=zL4bAyjZ05KtEFhcr7cpGZOvmTcjnNvx+pBCNxyZq7o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gyPlR3+3TcM8hFhSO7N2BFditYLExjDeCDrDp3VKmE6QccR2xH9LmkCOAaXrEzeTkWBgY2KcDD+fVQ/TPCH2H1qUwE+7dxm2YAZMvJjZphhH8CHn04J20G+YQ4M9sRFwwb/xPBLcn/+1i805ytrTyz0jsDDmsZsFX0CfvsKzAXs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=Ro0YL+FT; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Ro0YL+FT" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=38rLqhcMsy0L5Ad3kKQDodstFFHRENi1Ve1Bu3tuyy4=; b=Ro0YL+FTZUIdT5Y+iwBs2cmtcE /gVhklnlZ5a2+hO+dSe1SHv7SmmeUgx2mWD0c6gygsiN4stoL/iMRB+b7HIGVF5nIMaZMyiAlALOX 3iKlP5neDDHJvmX1eafkVHzkgIT+WKzdEoMl+B8O59gXJlhrrdZRea8r+rYul4VGwJBC0TZP8bG8+ e1Y8RsxuqoyYCQuwOm2T5069vRtIeAGVm0XDbskq3QtyvrJ496kj+rELJf7pvk+RWmHmqORvS2HPd xQdUoJil1XHPznEO5ENVBFKsWJPUlX8RuR6tApb92CTKODzDW1dazIA4Mq7ki/dve24TuuXNhCuI0 Q3UX41CQ==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1t1SFT-0000000BNna-11kJ; Thu, 17 Oct 2024 15:17:11 +0000 From: "Matthew Wilcox (Oracle)" To: Tyler Hicks Cc: "Matthew Wilcox (Oracle)" , ecryptfs@vger.kernel.org, Christian Brauner , linux-fsdevel@vger.kernel.org Subject: [PATCH 04/10] ecryptfs: Convert ecryptfs_read_lower_page_segment() to take a folio Date: Thu, 17 Oct 2024 16:16:59 +0100 Message-ID: <20241017151709.2713048-5-willy@infradead.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241017151709.2713048-1-willy@infradead.org> References: <20241017151709.2713048-1-willy@infradead.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 All callers have a folio, so pass it in and use it directly. This will not work for large folios, but I doubt anybody wants to use large folios with ecryptfs. Signed-off-by: Matthew Wilcox (Oracle) --- fs/ecryptfs/ecryptfs_kernel.h | 2 +- fs/ecryptfs/mmap.c | 10 +++++----- fs/ecryptfs/read_write.c | 10 +++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/fs/ecryptfs/ecryptfs_kernel.h b/fs/ecryptfs/ecryptfs_kernel.h index c586c5db18b5..43f1b5ff987d 100644 --- a/fs/ecryptfs/ecryptfs_kernel.h +++ b/fs/ecryptfs/ecryptfs_kernel.h @@ -658,7 +658,7 @@ int ecryptfs_write_lower_page_segment(struct inode *ecryptfs_inode, int ecryptfs_write(struct inode *inode, char *data, loff_t offset, size_t size); int ecryptfs_read_lower(char *data, loff_t offset, size_t size, struct inode *ecryptfs_inode); -int ecryptfs_read_lower_page_segment(struct page *page_for_ecryptfs, +int ecryptfs_read_lower_page_segment(struct folio *folio_for_ecryptfs, pgoff_t page_index, size_t offset_in_page, size_t size, struct inode *ecryptfs_inode); diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c index f7525a906ef7..b7ef0bf563bd 100644 --- a/fs/ecryptfs/mmap.c +++ b/fs/ecryptfs/mmap.c @@ -150,7 +150,7 @@ ecryptfs_copy_up_encrypted_with_header(struct folio *folio, - crypt_stat->metadata_size); rc = ecryptfs_read_lower_page_segment( - &folio->page, (lower_offset >> PAGE_SHIFT), + folio, (lower_offset >> PAGE_SHIFT), (lower_offset & ~PAGE_MASK), crypt_stat->extent_size, folio->mapping->host); if (rc) { @@ -184,7 +184,7 @@ static int ecryptfs_read_folio(struct file *file, struct folio *folio) int rc = 0; if (!crypt_stat || !(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) { - rc = ecryptfs_read_lower_page_segment(&folio->page, folio->index, 0, + rc = ecryptfs_read_lower_page_segment(folio, folio->index, 0, folio_size(folio), inode); } else if (crypt_stat->flags & ECRYPTFS_VIEW_AS_ENCRYPTED) { @@ -201,7 +201,7 @@ static int ecryptfs_read_folio(struct file *file, struct folio *folio) } } else { - rc = ecryptfs_read_lower_page_segment(&folio->page, + rc = ecryptfs_read_lower_page_segment(folio, folio->index, 0, folio_size(folio), inode); if (rc) { @@ -281,7 +281,7 @@ static int ecryptfs_write_begin(struct file *file, if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) { rc = ecryptfs_read_lower_page_segment( - &folio->page, index, 0, PAGE_SIZE, mapping->host); + folio, index, 0, PAGE_SIZE, mapping->host); if (rc) { printk(KERN_ERR "%s: Error attempting to read " "lower page segment; rc = [%d]\n", @@ -307,7 +307,7 @@ static int ecryptfs_write_begin(struct file *file, folio_mark_uptodate(folio); } else { rc = ecryptfs_read_lower_page_segment( - &folio->page, index, 0, PAGE_SIZE, + folio, index, 0, PAGE_SIZE, mapping->host); if (rc) { printk(KERN_ERR "%s: Error reading " diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c index 3458f153a588..251e9f6c6972 100644 --- a/fs/ecryptfs/read_write.c +++ b/fs/ecryptfs/read_write.c @@ -228,7 +228,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size, /** * ecryptfs_read_lower_page_segment - * @page_for_ecryptfs: The page into which data for eCryptfs will be + * @folio_for_ecryptfs: The folio into which data for eCryptfs will be * written * @page_index: Page index in @page_for_ecryptfs from which to start * writing @@ -243,7 +243,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size, * * Returns zero on success; non-zero otherwise */ -int ecryptfs_read_lower_page_segment(struct page *page_for_ecryptfs, +int ecryptfs_read_lower_page_segment(struct folio *folio_for_ecryptfs, pgoff_t page_index, size_t offset_in_page, size_t size, struct inode *ecryptfs_inode) @@ -252,12 +252,12 @@ int ecryptfs_read_lower_page_segment(struct page *page_for_ecryptfs, loff_t offset; int rc; - offset = ((((loff_t)page_index) << PAGE_SHIFT) + offset_in_page); - virt = kmap_local_page(page_for_ecryptfs); + offset = (loff_t)page_index * PAGE_SIZE + offset_in_page; + virt = kmap_local_folio(folio_for_ecryptfs, 0); rc = ecryptfs_read_lower(virt, offset, size, ecryptfs_inode); if (rc > 0) rc = 0; kunmap_local(virt); - flush_dcache_page(page_for_ecryptfs); + flush_dcache_folio(folio_for_ecryptfs); return rc; } From patchwork Thu Oct 17 15:17:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13840203 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 87E681DB34B; Thu, 17 Oct 2024 15:17:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729178238; cv=none; b=fXsgh1By9iQN0s1aM6ZxiZCgNKzNiI1nARRRTg8fHQGqBTXRS/P4x8nghgxyQnn/FjtSIYQGCwRtL41StjbcxXVrPDZ4G6qud5nNiKbiBUyiByucei1eOYIH4ZBCPdNxXu9xIe+Exc0sLYrq4414IT23CXnvWRn4PsYNKdzK+EU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729178238; c=relaxed/simple; bh=5J6se2Wk/u3ANJ+0sjOE7omHJXFfyalcDj4VENz2P0c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZiOvMVb3RmL8LyM3aq8n6PCmf+57GUuUyN6skdi3ahSBb3PbHXCx6CbD0LHUHvhe0RYmgcZH/FIKnEIZfjtEJdrR0qav6SijskEkHysG13pxcnebaL1Xwg0BPZnt3MJjMKZXInCbLXc9LKnoPpV1dDYdpj7vawHMNH0Wt36XKUM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=V3RGVG3y; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="V3RGVG3y" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=QiZivunybxzP8kjGTH60sGPFjrRaIoLZx+rnZcsuhXY=; b=V3RGVG3ykl/8xBS8RFvq6+Gi65 XPi1K8kdR/6g8XASUC1BXQN7Gdz2nehw0i6vfS3jec+GAGSKMIGrm+wAJ7SAHbNvNeLB6ea+THV3d Ol3ZOra0pn83czNOwH9wo5eLx4LyhPOLp6HA+lx+OPK2w9kQSbMLlWkn1GyN4nWZqZaIkzewn4WWL LxU+STT5vknXRw7FYRFOUcpwEev6N1fxgA1Y0u+OivriSBKYObBkyZHC7m43aTGFpLXwgJhjvomj6 D6FbBMiZNC8+ygsLuxUc4iuEL43MhKQDp860zzgtisyn96ao8GWwfI8OnOfN3LhelHw1Ufh3FtGNx 2HmkuM3A==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1t1SFT-0000000BNnh-2q7j; Thu, 17 Oct 2024 15:17:11 +0000 From: "Matthew Wilcox (Oracle)" To: Tyler Hicks Cc: "Matthew Wilcox (Oracle)" , ecryptfs@vger.kernel.org, Christian Brauner , linux-fsdevel@vger.kernel.org Subject: [PATCH 05/10] ecryptfs: Convert ecryptfs_write() to use a folio Date: Thu, 17 Oct 2024 16:17:00 +0100 Message-ID: <20241017151709.2713048-6-willy@infradead.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241017151709.2713048-1-willy@infradead.org> References: <20241017151709.2713048-1-willy@infradead.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Remove ecryptfs_get_locked_page() and call read_mapping_folio() directly. Use the folio throught this function. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Pankaj Raghav --- fs/ecryptfs/ecryptfs_kernel.h | 1 - fs/ecryptfs/mmap.c | 16 ---------------- fs/ecryptfs/read_write.c | 25 +++++++++++++------------ 3 files changed, 13 insertions(+), 29 deletions(-) diff --git a/fs/ecryptfs/ecryptfs_kernel.h b/fs/ecryptfs/ecryptfs_kernel.h index 43f1b5ff987d..f04aa24f6bcd 100644 --- a/fs/ecryptfs/ecryptfs_kernel.h +++ b/fs/ecryptfs/ecryptfs_kernel.h @@ -662,7 +662,6 @@ int ecryptfs_read_lower_page_segment(struct folio *folio_for_ecryptfs, pgoff_t page_index, size_t offset_in_page, size_t size, struct inode *ecryptfs_inode); -struct page *ecryptfs_get_locked_page(struct inode *inode, loff_t index); int ecryptfs_parse_packet_length(unsigned char *data, size_t *size, size_t *length_size); int ecryptfs_write_packet_length(char *dest, size_t size, diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c index b7ef0bf563bd..ad535bf9d2f9 100644 --- a/fs/ecryptfs/mmap.c +++ b/fs/ecryptfs/mmap.c @@ -22,22 +22,6 @@ #include #include "ecryptfs_kernel.h" -/* - * ecryptfs_get_locked_page - * - * Get one page from cache or lower f/s, return error otherwise. - * - * Returns locked and up-to-date page (if ok), with increased - * refcnt. - */ -struct page *ecryptfs_get_locked_page(struct inode *inode, loff_t index) -{ - struct page *page = read_mapping_page(inode->i_mapping, index, NULL); - if (!IS_ERR(page)) - lock_page(page); - return page; -} - /* * This is where we encrypt the data and pass the encrypted data to * the lower filesystem. In OpenPGP-compatible mode, we operate on diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c index 251e9f6c6972..cddfdfced879 100644 --- a/fs/ecryptfs/read_write.c +++ b/fs/ecryptfs/read_write.c @@ -93,7 +93,6 @@ int ecryptfs_write_lower_page_segment(struct inode *ecryptfs_inode, int ecryptfs_write(struct inode *ecryptfs_inode, char *data, loff_t offset, size_t size) { - struct page *ecryptfs_page; struct ecryptfs_crypt_stat *crypt_stat; char *ecryptfs_page_virt; loff_t ecryptfs_file_size = i_size_read(ecryptfs_inode); @@ -111,6 +110,7 @@ int ecryptfs_write(struct inode *ecryptfs_inode, char *data, loff_t offset, else pos = offset; while (pos < (offset + size)) { + struct folio *ecryptfs_folio; pgoff_t ecryptfs_page_idx = (pos >> PAGE_SHIFT); size_t start_offset_in_page = (pos & ~PAGE_MASK); size_t num_bytes = (PAGE_SIZE - start_offset_in_page); @@ -130,17 +130,18 @@ int ecryptfs_write(struct inode *ecryptfs_inode, char *data, loff_t offset, if (num_bytes > total_remaining_zeros) num_bytes = total_remaining_zeros; } - ecryptfs_page = ecryptfs_get_locked_page(ecryptfs_inode, - ecryptfs_page_idx); - if (IS_ERR(ecryptfs_page)) { - rc = PTR_ERR(ecryptfs_page); + ecryptfs_folio = read_mapping_folio(ecryptfs_inode->i_mapping, + ecryptfs_page_idx, NULL); + if (IS_ERR(ecryptfs_folio)) { + rc = PTR_ERR(ecryptfs_folio); printk(KERN_ERR "%s: Error getting page at " "index [%ld] from eCryptfs inode " "mapping; rc = [%d]\n", __func__, ecryptfs_page_idx, rc); goto out; } - ecryptfs_page_virt = kmap_local_page(ecryptfs_page); + folio_lock(ecryptfs_folio); + ecryptfs_page_virt = kmap_local_folio(ecryptfs_folio, 0); /* * pos: where we're now writing, offset: where the request was @@ -164,17 +165,17 @@ int ecryptfs_write(struct inode *ecryptfs_inode, char *data, loff_t offset, data_offset += num_bytes; } kunmap_local(ecryptfs_page_virt); - flush_dcache_page(ecryptfs_page); - SetPageUptodate(ecryptfs_page); - unlock_page(ecryptfs_page); + flush_dcache_folio(ecryptfs_folio); + folio_mark_uptodate(ecryptfs_folio); + folio_unlock(ecryptfs_folio); if (crypt_stat->flags & ECRYPTFS_ENCRYPTED) - rc = ecryptfs_encrypt_page(ecryptfs_page); + rc = ecryptfs_encrypt_page(&ecryptfs_folio->page); else rc = ecryptfs_write_lower_page_segment(ecryptfs_inode, - ecryptfs_page, + &ecryptfs_folio->page, start_offset_in_page, data_offset); - put_page(ecryptfs_page); + folio_put(ecryptfs_folio); if (rc) { printk(KERN_ERR "%s: Error encrypting " "page; rc = [%d]\n", __func__, rc); From patchwork Thu Oct 17 15:17:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13840200 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 87F131DE4DF; Thu, 17 Oct 2024 15:17:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729178237; cv=none; b=hX+AEuZZ2ugtwyj2cjoFzgx/d7bwQCf9YyLHVyoIbWB4Mlg/Yl6Do+4cS03icJhiiDdBnP2TMAk/oKyRTHuPHsO46q1qY92omywIGt2oppuK0AEjpb1ldbrvTUclHui/5V/eYR29Le04+99Ji6KNaURCCBx0Qn+LwYhwpSfgtLU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729178237; c=relaxed/simple; bh=+inIYYTHCinhHWUkniRjXfv/ZjFYWploj+4M/z6VJB4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M8JNyBNRed+9Vj7fqmzNM52FewoPODF0Qm0+/7m7hez3W8xh3Mu4+m2cCzy9RFV9+of/mRKH+b4qT/6EGUh/fdR+hH2WAoDOooFMc/DOBO/sAAxo8GZB24kH/SmiGCXHinZvujDAARJotwogwNuuAE7K0wwrsOk1PXozSQCodqM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=qTGjjPNr; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="qTGjjPNr" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=hbfyFWqCh2VWYf2n6aCxX1QX0AXK76icZVonkKpknhs=; b=qTGjjPNrmT0odM/Nlh5yy03hAp zcpF/McpBKqugyVVu85tbnNViAdbgfL3j6+b56/VFDX56H7BWHjFZEoX4egzyiRWvXN0CfsgkInDE igh0b/vbaErXv9eQ9Iw4qSDy3IDjac9Mj9kIj7y89yjp143LkogMvPL+82uTUWl1X0vUUIZHn/Yco sTNSJFNuYhXU8LGH0EHVPfnDVJOR3fa2HulJThlg/dp7+PhloH80RSmptwMKvlq5IPQAGZ07ALWoM EuVVkOfSf9OrB9UGbHIizKTDSYgq0KMxjedf+LydpGK/g0IgyMsVu/S53l5ekLkggI3OAfuyGfQar PP0UbkOQ==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1t1SFT-0000000BNns-3USI; Thu, 17 Oct 2024 15:17:11 +0000 From: "Matthew Wilcox (Oracle)" To: Tyler Hicks Cc: "Matthew Wilcox (Oracle)" , ecryptfs@vger.kernel.org, Christian Brauner , linux-fsdevel@vger.kernel.org Subject: [PATCH 06/10] ecryptfs: Convert ecryptfs_write_lower_page_segment() to take a folio Date: Thu, 17 Oct 2024 16:17:01 +0100 Message-ID: <20241017151709.2713048-7-willy@infradead.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241017151709.2713048-1-willy@infradead.org> References: <20241017151709.2713048-1-willy@infradead.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Both callers now have a folio, so pass it in and use it throughout. Signed-off-by: Matthew Wilcox (Oracle) --- fs/ecryptfs/ecryptfs_kernel.h | 2 +- fs/ecryptfs/mmap.c | 2 +- fs/ecryptfs/read_write.c | 17 ++++++++--------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/fs/ecryptfs/ecryptfs_kernel.h b/fs/ecryptfs/ecryptfs_kernel.h index f04aa24f6bcd..0cac8d3155ae 100644 --- a/fs/ecryptfs/ecryptfs_kernel.h +++ b/fs/ecryptfs/ecryptfs_kernel.h @@ -653,7 +653,7 @@ int ecryptfs_keyring_auth_tok_for_sig(struct key **auth_tok_key, int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data, loff_t offset, size_t size); int ecryptfs_write_lower_page_segment(struct inode *ecryptfs_inode, - struct page *page_for_lower, + struct folio *folio_for_lower, size_t offset_in_page, size_t size); int ecryptfs_write(struct inode *inode, char *data, loff_t offset, size_t size); int ecryptfs_read_lower(char *data, loff_t offset, size_t size, diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c index ad535bf9d2f9..acbef67d9c85 100644 --- a/fs/ecryptfs/mmap.c +++ b/fs/ecryptfs/mmap.c @@ -457,7 +457,7 @@ static int ecryptfs_write_end(struct file *file, "(page w/ index = [0x%.16lx], to = [%d])\n", index, to); if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) { rc = ecryptfs_write_lower_page_segment(ecryptfs_inode, - &folio->page, 0, to); + folio, 0, to); if (!rc) { rc = copied; fsstack_copy_inode_size(ecryptfs_inode, diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c index cddfdfced879..665bcd7d1c8e 100644 --- a/fs/ecryptfs/read_write.c +++ b/fs/ecryptfs/read_write.c @@ -41,30 +41,29 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data, /** * ecryptfs_write_lower_page_segment * @ecryptfs_inode: The eCryptfs inode - * @page_for_lower: The page containing the data to be written to the + * @folio_for_lower: The folio containing the data to be written to the * lower file - * @offset_in_page: The offset in the @page_for_lower from which to + * @offset_in_page: The offset in the @folio_for_lower from which to * start writing the data - * @size: The amount of data from @page_for_lower to write to the + * @size: The amount of data from @folio_for_lower to write to the * lower file * * Determines the byte offset in the file for the given page and * offset within the page, maps the page, and makes the call to write - * the contents of @page_for_lower to the lower inode. + * the contents of @folio_for_lower to the lower inode. * * Returns zero on success; non-zero otherwise */ int ecryptfs_write_lower_page_segment(struct inode *ecryptfs_inode, - struct page *page_for_lower, + struct folio *folio_for_lower, size_t offset_in_page, size_t size) { char *virt; loff_t offset; int rc; - offset = ((((loff_t)page_for_lower->index) << PAGE_SHIFT) - + offset_in_page); - virt = kmap_local_page(page_for_lower); + offset = (loff_t)folio_for_lower->index * PAGE_SIZE + offset_in_page; + virt = kmap_local_folio(folio_for_lower, 0); rc = ecryptfs_write_lower(ecryptfs_inode, virt, offset, size); if (rc > 0) rc = 0; @@ -172,7 +171,7 @@ int ecryptfs_write(struct inode *ecryptfs_inode, char *data, loff_t offset, rc = ecryptfs_encrypt_page(&ecryptfs_folio->page); else rc = ecryptfs_write_lower_page_segment(ecryptfs_inode, - &ecryptfs_folio->page, + ecryptfs_folio, start_offset_in_page, data_offset); folio_put(ecryptfs_folio); From patchwork Thu Oct 17 15:17:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13840201 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 87F601DE4E8; Thu, 17 Oct 2024 15:17:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729178237; cv=none; b=D1p4IbE/rHL5nHLPSrvB7hXb5+ZpImNNQdHtLsi9y5wgui0UGqcqiZJIDJaPgTz9mHi1PXtxZuNR5nqawMY/Az5YG8EmErhzlleKkMztvkQFS8U1eenmSrcfd2ywzusObQ/AGZSkY8PJQjtgspqBquCwOnj03YiJyJ5CfSVt9uc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729178237; c=relaxed/simple; bh=NMXZxmEQvb3sQIVkLZIc4AD0YHx1u+CKKnmOafA1Wm0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=auEaCJTAM+bdayw9r77hbIgiFT+gcAzelYRkj050wUZLNktUxpW6hEpMTVSrIa2vOrK6KGUBwnjU5hALb9RgFfam6mPTTRV0/5arTpzdIhk6ePefQQrxdkzcjlr99hf8m04eWD20+TvmlM9LxQEyK5v6UTvGOlvne2PzErgg0C8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=dhjBhth1; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="dhjBhth1" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=0bhHWasPADTkJ6e52B6yvpnvHXphAS2s33U8awJ+RH4=; b=dhjBhth1iOANvUNlgGM70z4EvS XQ+2HgOTpCZBzcmeWIX2CPioNQkmwUgR1ia6kAwJa84uw+HGd2CKujUEcINKeKm2ywPQCGObaLxuF Hirt7hBIwJFgniwiCnmYoHWIr19GW2gEjJaE9P0K7eEswtNvg4LYHAb1odnG7fmvzysvbJls7YA/C WjW0Lw8p3jDLeJitTYQcukl/pTByPm7q1Mcp12YFCPW9TH/6kJXIW1zpdRx15xcPky1tqbaZeYTJT /pFlC0cjmcyG5O/fvBy0unn+VnGA13C/xAqQvxpyJq5/r+47fvt6os5bBcQlQCDPpR134grwpved3 CCzKUcHQ==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1t1SFT-0000000BNnz-44Uu; Thu, 17 Oct 2024 15:17:12 +0000 From: "Matthew Wilcox (Oracle)" To: Tyler Hicks Cc: "Matthew Wilcox (Oracle)" , ecryptfs@vger.kernel.org, Christian Brauner , linux-fsdevel@vger.kernel.org Subject: [PATCH 07/10] ecryptfs: Convert ecryptfs_encrypt_page() to take a folio Date: Thu, 17 Oct 2024 16:17:02 +0100 Message-ID: <20241017151709.2713048-8-willy@infradead.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241017151709.2713048-1-willy@infradead.org> References: <20241017151709.2713048-1-willy@infradead.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 All three callers have a folio, so pass it in and use it throughout. Signed-off-by: Matthew Wilcox (Oracle) --- fs/ecryptfs/crypto.c | 10 +++++----- fs/ecryptfs/ecryptfs_kernel.h | 2 +- fs/ecryptfs/mmap.c | 4 ++-- fs/ecryptfs/read_write.c | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c index 827278525fd9..424233177b43 100644 --- a/fs/ecryptfs/crypto.c +++ b/fs/ecryptfs/crypto.c @@ -406,7 +406,7 @@ static int crypt_extent(struct ecryptfs_crypt_stat *crypt_stat, * * Returns zero on success; negative on error */ -int ecryptfs_encrypt_page(struct page *page) +int ecryptfs_encrypt_page(struct folio *folio) { struct inode *ecryptfs_inode; struct ecryptfs_crypt_stat *crypt_stat; @@ -416,7 +416,7 @@ int ecryptfs_encrypt_page(struct page *page) loff_t lower_offset; int rc = 0; - ecryptfs_inode = page->mapping->host; + ecryptfs_inode = folio->mapping->host; crypt_stat = &(ecryptfs_inode_to_private(ecryptfs_inode)->crypt_stat); BUG_ON(!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)); @@ -431,8 +431,8 @@ int ecryptfs_encrypt_page(struct page *page) for (extent_offset = 0; extent_offset < (PAGE_SIZE / crypt_stat->extent_size); extent_offset++) { - rc = crypt_extent(crypt_stat, enc_extent_page, page, - extent_offset, ENCRYPT); + rc = crypt_extent(crypt_stat, enc_extent_page, + folio_page(folio, 0), extent_offset, ENCRYPT); if (rc) { printk(KERN_ERR "%s: Error encrypting extent; " "rc = [%d]\n", __func__, rc); @@ -440,7 +440,7 @@ int ecryptfs_encrypt_page(struct page *page) } } - lower_offset = lower_offset_for_page(crypt_stat, page); + lower_offset = lower_offset_for_page(crypt_stat, &folio->page); enc_extent_virt = kmap_local_page(enc_extent_page); rc = ecryptfs_write_lower(ecryptfs_inode, enc_extent_virt, lower_offset, PAGE_SIZE); diff --git a/fs/ecryptfs/ecryptfs_kernel.h b/fs/ecryptfs/ecryptfs_kernel.h index 0cac8d3155ae..bffced0c1d8f 100644 --- a/fs/ecryptfs/ecryptfs_kernel.h +++ b/fs/ecryptfs/ecryptfs_kernel.h @@ -569,7 +569,7 @@ void ecryptfs_destroy_mount_crypt_stat( struct ecryptfs_mount_crypt_stat *mount_crypt_stat); int ecryptfs_init_crypt_ctx(struct ecryptfs_crypt_stat *crypt_stat); int ecryptfs_write_inode_size_to_metadata(struct inode *ecryptfs_inode); -int ecryptfs_encrypt_page(struct page *page); +int ecryptfs_encrypt_page(struct folio *folio); int ecryptfs_decrypt_page(struct page *page); int ecryptfs_write_metadata(struct dentry *ecryptfs_dentry, struct inode *ecryptfs_inode); diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c index acbef67d9c85..1bf46d2c6a82 100644 --- a/fs/ecryptfs/mmap.c +++ b/fs/ecryptfs/mmap.c @@ -34,7 +34,7 @@ static int ecryptfs_writepages(struct address_space *mapping, int error; while ((folio = writeback_iter(mapping, wbc, folio, &error))) { - error = ecryptfs_encrypt_page(&folio->page); + error = ecryptfs_encrypt_page(folio); if (error) { ecryptfs_printk(KERN_WARNING, "Error encrypting folio (index [0x%.16lx])\n", @@ -479,7 +479,7 @@ static int ecryptfs_write_end(struct file *file, "zeros in page with index = [0x%.16lx]\n", index); goto out; } - rc = ecryptfs_encrypt_page(&folio->page); + rc = ecryptfs_encrypt_page(folio); if (rc) { ecryptfs_printk(KERN_WARNING, "Error encrypting page (upper " "index [0x%.16lx])\n", index); diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c index 665bcd7d1c8e..b3b451c2b941 100644 --- a/fs/ecryptfs/read_write.c +++ b/fs/ecryptfs/read_write.c @@ -168,7 +168,7 @@ int ecryptfs_write(struct inode *ecryptfs_inode, char *data, loff_t offset, folio_mark_uptodate(ecryptfs_folio); folio_unlock(ecryptfs_folio); if (crypt_stat->flags & ECRYPTFS_ENCRYPTED) - rc = ecryptfs_encrypt_page(&ecryptfs_folio->page); + rc = ecryptfs_encrypt_page(ecryptfs_folio); else rc = ecryptfs_write_lower_page_segment(ecryptfs_inode, ecryptfs_folio, From patchwork Thu Oct 17 15:17:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13840197 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9414D1DE4EB; Thu, 17 Oct 2024 15:17:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729178237; cv=none; b=F6tx5tlZi8NQFfJcn6zXq6tN5OYmo0wkBRvJBP94w+EinCbZ9epdS9x61MlF2R1Kh6MAVNDsco1AL3Fain8kzdyPGo1MNL2GlsZ7wQ8TI7YsgnnrcxykWyrMURnj9Eh1jrCSucMM23r06v0CJn6KFJknFaNCBBcmIqP8/t/+yAE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729178237; c=relaxed/simple; bh=2P/Q+WTVtaXSZxbAymCvV9JDU1wdXYHtetE2/H2WYyI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=phxAtQB7V+kZAsjh6AYDowIqAG3Lsm8gBDWx2bNx+UHC8+R06guy+KBptZ8x5vXnnEgJF5b0u9xf/F+OQqVA30iTigE6XKk2dg93fh0zgAU4iK6xlxJo0+5AuTQUiTRJzTy88FNBsKinELSo3xWajH2ecDO9y2tHjSZ97VT+BvI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=fVUvKPiZ; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="fVUvKPiZ" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=yXLPyePunnFCiAm+ZZYOcAd5KjXkJ4YfWrDc5djqjl0=; b=fVUvKPiZsabViaCoAX68Sn6kR1 dKDwM296DSvJHXpe0wm0ST0Z9VZN21Qal/Uev6qPJ5a468w+OJJJXYhcN5Z54ysqsGXZ09z/HtzsY yBSQjYb1fVnUr/de/7ePlsH7fdtU7ymn51EDW7Eadxd54z801yBvAqkBxbiXbbvwNqxcTzco9L7aB EZXtJXofc2FUP8+JSqZfey2eDOCW1RYtOxkpwAsa5frFwURCfimWkpZFuvmxU4ctCp8/YOMz3rHDg URcf+fTkH4vurAtNgjAXm5a2MIzTuFc8/c2/XvTZOyZ2w4zHh391VBADFxSeNpOMVomhd5dEbx2uq hhOOolRQ==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1t1SFU-0000000BNo6-0Xr9; Thu, 17 Oct 2024 15:17:12 +0000 From: "Matthew Wilcox (Oracle)" To: Tyler Hicks Cc: "Matthew Wilcox (Oracle)" , ecryptfs@vger.kernel.org, Christian Brauner , linux-fsdevel@vger.kernel.org Subject: [PATCH 08/10] ecryptfs: Convert ecryptfs_decrypt_page() to take a folio Date: Thu, 17 Oct 2024 16:17:03 +0100 Message-ID: <20241017151709.2713048-9-willy@infradead.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241017151709.2713048-1-willy@infradead.org> References: <20241017151709.2713048-1-willy@infradead.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Both callers have a folio, so pass it in and use it throughout. Signed-off-by: Matthew Wilcox (Oracle) --- fs/ecryptfs/crypto.c | 9 +++++---- fs/ecryptfs/ecryptfs_kernel.h | 2 +- fs/ecryptfs/mmap.c | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c index 424233177b43..02bccaa7c666 100644 --- a/fs/ecryptfs/crypto.c +++ b/fs/ecryptfs/crypto.c @@ -475,7 +475,7 @@ int ecryptfs_encrypt_page(struct folio *folio) * * Returns zero on success; negative on error */ -int ecryptfs_decrypt_page(struct page *page) +int ecryptfs_decrypt_page(struct folio *folio) { struct inode *ecryptfs_inode; struct ecryptfs_crypt_stat *crypt_stat; @@ -484,13 +484,13 @@ int ecryptfs_decrypt_page(struct page *page) loff_t lower_offset; int rc = 0; - ecryptfs_inode = page->mapping->host; + ecryptfs_inode = folio->mapping->host; crypt_stat = &(ecryptfs_inode_to_private(ecryptfs_inode)->crypt_stat); BUG_ON(!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)); - lower_offset = lower_offset_for_page(crypt_stat, page); - page_virt = kmap_local_page(page); + lower_offset = lower_offset_for_page(crypt_stat, &folio->page); + page_virt = kmap_local_folio(folio, 0); rc = ecryptfs_read_lower(page_virt, lower_offset, PAGE_SIZE, ecryptfs_inode); kunmap_local(page_virt); @@ -504,6 +504,7 @@ int ecryptfs_decrypt_page(struct page *page) for (extent_offset = 0; extent_offset < (PAGE_SIZE / crypt_stat->extent_size); extent_offset++) { + struct page *page = folio_page(folio, 0); rc = crypt_extent(crypt_stat, page, page, extent_offset, DECRYPT); if (rc) { diff --git a/fs/ecryptfs/ecryptfs_kernel.h b/fs/ecryptfs/ecryptfs_kernel.h index bffced0c1d8f..1f562e75d0e4 100644 --- a/fs/ecryptfs/ecryptfs_kernel.h +++ b/fs/ecryptfs/ecryptfs_kernel.h @@ -570,7 +570,7 @@ void ecryptfs_destroy_mount_crypt_stat( int ecryptfs_init_crypt_ctx(struct ecryptfs_crypt_stat *crypt_stat); int ecryptfs_write_inode_size_to_metadata(struct inode *ecryptfs_inode); int ecryptfs_encrypt_page(struct folio *folio); -int ecryptfs_decrypt_page(struct page *page); +int ecryptfs_decrypt_page(struct folio *folio); int ecryptfs_write_metadata(struct dentry *ecryptfs_dentry, struct inode *ecryptfs_inode); int ecryptfs_read_metadata(struct dentry *ecryptfs_dentry); diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c index 1bf46d2c6a82..6ec4a60c1f3a 100644 --- a/fs/ecryptfs/mmap.c +++ b/fs/ecryptfs/mmap.c @@ -195,7 +195,7 @@ static int ecryptfs_read_folio(struct file *file, struct folio *folio) } } } else { - rc = ecryptfs_decrypt_page(&folio->page); + rc = ecryptfs_decrypt_page(folio); if (rc) { ecryptfs_printk(KERN_ERR, "Error decrypting page; " "rc = [%d]\n", rc); @@ -308,7 +308,7 @@ static int ecryptfs_write_begin(struct file *file, folio_zero_range(folio, 0, PAGE_SIZE); folio_mark_uptodate(folio); } else if (len < PAGE_SIZE) { - rc = ecryptfs_decrypt_page(&folio->page); + rc = ecryptfs_decrypt_page(folio); if (rc) { printk(KERN_ERR "%s: Error decrypting " "page at index [%ld]; " From patchwork Thu Oct 17 15:17:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13840199 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E48111DE8B4; Thu, 17 Oct 2024 15:17:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729178237; cv=none; b=lJiihAof8cLcjQj+K4+6MvTmhmg+BFXjgjMe55+R0Op6yrbjACfxAglareV/cQ0Mo2w2RL2GyPVDF6lfDRX93l5vOkPylkEIXnRma+HqQrQltN3EBrLuevnJnXtYZRBH+quZ6y+0RXTsdChOidNHQIN6F8dNqcWdD5eyS5i5WLs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729178237; c=relaxed/simple; bh=eP9Pd8WPiP0C2LM+4D3U5ZJRKmug9Sv8RNRm4SF9Tnw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LRi/QReiduNf7W1GxBjFJu908AhgQE3b21JXS3IwAnvw75H/ejK52PNUkg+pVBKTwMbHd/wU1WlULlAi4fyWD/kFoj3KXYbuK7gncx1zR86jHabsTxu75SJ6hBkzR2eybb4XuFQuz7b/TgmahBd/3bvQikTQHftIvyxdyj9G58k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=O2DswwE2; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="O2DswwE2" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=QUSeCVFD42RiBhC+sU6UxLp8wUh9+38xI1tcqMh2AaA=; b=O2DswwE2mtCUOm9kO/oJqmNm8s o7ll7XI9n2pRKk9ZCqvnAT2os37QlrZ/8F6yYk2zHMlbJw2zL1zOTBAEzNpUkm3wAr++Z6Q9hc9ga /PyiH+jG91x6iGrQIsWWbEan6Avs7m6LmzvUGfp17uZkHsYH31kr2b/84xLoLXOF/l7z64AcfDA7p ZVc0X/77wYUUfpabeM+OKtxuQoJ4w9pIVS0vIGQEhIGiAeGJqhjqjQPmpZnpOPaXmHmJj4Ira4e4t x1qntSY9Qdixr35Xth2+5Vy+T7uUV5ssuqejHqBSE3nIqFfBQOEDDM/TWRFOcV5XFK0EErYeDVQ+U rEpxeL5w==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1t1SFU-0000000BNoD-17Q1; Thu, 17 Oct 2024 15:17:12 +0000 From: "Matthew Wilcox (Oracle)" To: Tyler Hicks Cc: "Matthew Wilcox (Oracle)" , ecryptfs@vger.kernel.org, Christian Brauner , linux-fsdevel@vger.kernel.org Subject: [PATCH 09/10] ecryptfs: Convert lower_offset_for_page() to take a folio Date: Thu, 17 Oct 2024 16:17:04 +0100 Message-ID: <20241017151709.2713048-10-willy@infradead.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241017151709.2713048-1-willy@infradead.org> References: <20241017151709.2713048-1-willy@infradead.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Both callers have a folio, so pass it in and use folio->index instead of page->index. Signed-off-by: Matthew Wilcox (Oracle) --- fs/ecryptfs/crypto.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c index 02bccaa7c666..3db50a779dc7 100644 --- a/fs/ecryptfs/crypto.c +++ b/fs/ecryptfs/crypto.c @@ -328,10 +328,10 @@ static int crypt_scatterlist(struct ecryptfs_crypt_stat *crypt_stat, * Convert an eCryptfs page index into a lower byte offset */ static loff_t lower_offset_for_page(struct ecryptfs_crypt_stat *crypt_stat, - struct page *page) + struct folio *folio) { return ecryptfs_lower_header_size(crypt_stat) + - ((loff_t)page->index << PAGE_SHIFT); + (loff_t)folio->index * PAGE_SIZE; } /** @@ -440,7 +440,7 @@ int ecryptfs_encrypt_page(struct folio *folio) } } - lower_offset = lower_offset_for_page(crypt_stat, &folio->page); + lower_offset = lower_offset_for_page(crypt_stat, folio); enc_extent_virt = kmap_local_page(enc_extent_page); rc = ecryptfs_write_lower(ecryptfs_inode, enc_extent_virt, lower_offset, PAGE_SIZE); @@ -489,7 +489,7 @@ int ecryptfs_decrypt_page(struct folio *folio) &(ecryptfs_inode_to_private(ecryptfs_inode)->crypt_stat); BUG_ON(!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)); - lower_offset = lower_offset_for_page(crypt_stat, &folio->page); + lower_offset = lower_offset_for_page(crypt_stat, folio); page_virt = kmap_local_folio(folio, 0); rc = ecryptfs_read_lower(page_virt, lower_offset, PAGE_SIZE, ecryptfs_inode); From patchwork Thu Oct 17 15:17:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13840202 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E47761DE880; Thu, 17 Oct 2024 15:17:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729178238; cv=none; b=ImGJAPtlO1MnEuEA9NbIiAIzyWe5jUXAkXqYQF6iS/r5ukDQSNcdOZYNJ6alfG4cttgO4t+gwLZKs1Rdk94ml8OP0IiQzpJwT8e2vIBXXzDH58IwtpoLkMRvY4BcoyKBj3DyorFIYXDGxVYPqNPqZ1Gu/owuOrCdyQldNY6+rDo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729178238; c=relaxed/simple; bh=j1w3D0/GYQm8w5sx0WH65fsXPT8LlvpjQRplmRHK0/g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UZbGeROVMf8qzH2ih7OQCbEg1wtnryJ49QgYyUkzWq/GdtSx+jtnI3rZcug+U2lT8+wXdJq/ypMgc5Ril30EM5IwYa2NOffdLzvbSBgDg9GecR+I1UUMOUMdrNbXXIOWOMzbYeCTrYaZf7uCQA5FixmlR060S9ySbKY71H87kwo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=JS3Va2Rw; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="JS3Va2Rw" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=yMR4u+v8EKlznoGnXM+GjQA9dD0RqUEprsHyhwzZiEg=; b=JS3Va2RwXHTHGrysz6953yuyoA NzbSHxEBLf377zKb5TMltoOZfRnXsg6T4cyb51wOAwZkmI+2NoMuFm7oY861XFXRbVfduBkHhTFEq l0ic4A6KSLy/rzbZOu+Uc2uAp0s+Dw/+Qq8WrzigdDJOonEY4LJTYy1JbN824s4WuGImXZMbhXO6s nGRcklZEZtpcGvrIn85AJ1UWV0Od9Iemz90rIRzhVh+e0yX55Ccwlpxf1X1+BVPDUPs+FR1ul20ru Zn+Ylpl07W23WMDB4ocfNIE/8q83jfpoFvmZxF94F6jVdLJXJO3VWqJjlCxzXZnCarVxBYzh5UvYZ qtOsVJNA==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1t1SFU-0000000BNoL-1if6; Thu, 17 Oct 2024 15:17:12 +0000 From: "Matthew Wilcox (Oracle)" To: Tyler Hicks Cc: "Matthew Wilcox (Oracle)" , ecryptfs@vger.kernel.org, Christian Brauner , linux-fsdevel@vger.kernel.org Subject: [PATCH 10/10] ecryptfs: Pass the folio index to crypt_extent() Date: Thu, 17 Oct 2024 16:17:05 +0100 Message-ID: <20241017151709.2713048-11-willy@infradead.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241017151709.2713048-1-willy@infradead.org> References: <20241017151709.2713048-1-willy@infradead.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We need to pass pages, not folios, to crypt_extent() as we may be working with a plain page rather than a folio. But we need to know the index in the file, so pass it in from the caller. Signed-off-by: Matthew Wilcox (Oracle) --- fs/ecryptfs/crypto.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c index 3db50a779dc7..c708b9012e21 100644 --- a/fs/ecryptfs/crypto.c +++ b/fs/ecryptfs/crypto.c @@ -350,9 +350,9 @@ static loff_t lower_offset_for_page(struct ecryptfs_crypt_stat *crypt_stat, static int crypt_extent(struct ecryptfs_crypt_stat *crypt_stat, struct page *dst_page, struct page *src_page, + pgoff_t page_index, unsigned long extent_offset, int op) { - pgoff_t page_index = op == ENCRYPT ? src_page->index : dst_page->index; loff_t extent_base; char extent_iv[ECRYPTFS_MAX_IV_BYTES]; struct scatterlist src_sg, dst_sg; @@ -432,7 +432,8 @@ int ecryptfs_encrypt_page(struct folio *folio) extent_offset < (PAGE_SIZE / crypt_stat->extent_size); extent_offset++) { rc = crypt_extent(crypt_stat, enc_extent_page, - folio_page(folio, 0), extent_offset, ENCRYPT); + folio_page(folio, 0), folio->index, + extent_offset, ENCRYPT); if (rc) { printk(KERN_ERR "%s: Error encrypting extent; " "rc = [%d]\n", __func__, rc); @@ -505,8 +506,8 @@ int ecryptfs_decrypt_page(struct folio *folio) extent_offset < (PAGE_SIZE / crypt_stat->extent_size); extent_offset++) { struct page *page = folio_page(folio, 0); - rc = crypt_extent(crypt_stat, page, page, - extent_offset, DECRYPT); + rc = crypt_extent(crypt_stat, page, page, folio->index, + extent_offset, DECRYPT); if (rc) { printk(KERN_ERR "%s: Error decrypting extent; " "rc = [%d]\n", __func__, rc);