From patchwork Fri Oct 25 19:08:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13851342 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 3FA8220EA53; Fri, 25 Oct 2024 19:08:27 +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=1729883310; cv=none; b=T+TZE1HyYiPt3Xyn4A2Pf8bz91M7FyNpTFczo/ZwlEIzIisXWLmJ4z6OaNzHUpYT1VnvXmJ8M0iL1w5kImXJDIG67VgM0JmZooFlCC6o7m65SNcFOyQLUuM+NGQrBBEQzGlU2ywgY13DptWZPJr6IO+IHtA5IsuIgGYrs9a+4Rk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729883310; c=relaxed/simple; bh=O23Gy//oeLZ55SVeNW28SgBcNWSa8ozwd5Oo71wrXH8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hPE+X8FEQ+yQvl7kiBTyvIFntpLDa8MBhK5f7fbFUh6TUiVRU2qpZlxyVeLfulOMYzBuYk8822YkA0WPwBJK2AdiasOfj8uxMig03VetCTCL+mEPpkBN9/BQOONcjV4SddbfiUpJ/hBGncQxvzlDP9MK0ys1OUATof4JhNE4w/8= 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=q3fJalPh; 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="q3fJalPh" 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=q3fJalPh2j4HuO/lfwDBj2gn0o oSo/l/oQzMzQQS+BgYDt4YwYBgiqPrqIDG0KCeUD1jZ0W7RKyciRCjtEab2dkZE8iTjaHqA01OJgk mUvBXdt5K8l+JorgyTxS3zCi80AQfMBauEaJT4fS/sexNieoHxKqQiel+wfIoVuCQXOd5xa518Wcw GlVMWh3NFFIWTHQwm+Ef/4p1wAPEDdMFFFQFFgE4CPTLxKuwmjJPqH1gB3xtVor1FrNIhZvaA2wPY P9bYlK11K0XvkQSOPIk/eo9fENxCAtEuLylRooX/ME9NTnbZYYFwrDp9ZnNP1p3qyktmZ8ZBpyiFk Qrr5AFvw==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1t4Pfb-00000005XB2-2MGJ; Fri, 25 Oct 2024 19:08:23 +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 v2 01/10] ecryptfs: Convert ecryptfs_writepage() to ecryptfs_writepages() Date: Fri, 25 Oct 2024 20:08:11 +0100 Message-ID: <20241025190822.1319162-2-willy@infradead.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241025190822.1319162-1-willy@infradead.org> References: <20241025190822.1319162-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 Fri Oct 25 19:08:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13851334 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 3229220D4F9; Fri, 25 Oct 2024 19:08:25 +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=1729883307; cv=none; b=lGqFqbOWtxPYztUso1myBf4wswMyW9l3YTSf1g48367g+dQD7bS6A4TEtDXzHLRLN1Fp2IUlcWY4Ak4cMqUGapXFOEtUJjf4A5M+g0mJxV5pym4sYxLFs5JSwrxR4CAMq8S2sX8cQ5petkueMtjVBbyvZt17MlbdSXjdaqJrr44= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729883307; c=relaxed/simple; bh=yMd3c8W3s/W+W73+PzOt8tHrfz0d7KV4KHFiXlvrZ1A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NckqEcT5OBQkipBfXQJs7QnqOC9oBCv0wVs/e0UU0t74KdlH1ZEAhXezh9Mv1PdAHg4ilm0icHkc6lDhLiGSQknMmuf0hXQP8x6GEuwKfPd+WDQX7CU+GRfwSkcLy7OgrJ71dt/F+QZx9s/VxHEb/X5xGgxqY/WFBre+Zk0kV8I= 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=WIt7Qdkj; 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="WIt7Qdkj" 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=ngUUNpMHchzF+LT0PYTuG94y5wEqsIYZzLCEqG1mipQ=; b=WIt7QdkjJnUJSbX1hGDNBGS7+n jqqR2SbscxqBe/Xx2kGqe5v2Z2PwYN38eD58GY6HQgjMrZoSUcrLakh3aTEPqSdLUfTkUYR/bzkOO GcUYUvHV2re9928zGWvqTYvSc6S4ruHjUWYLCHBp5sfZmu8tO7rwzD+7lG898o/4Z6vM6kyw7k6Y8 rxMwQ7CFVL6GR8ssG48cqR8GZ9rc3lN2fo9LeODfXu52790pHFDkMcuMHSIMdLmCELRhCMkkJfzn4 6PeqT5qjpVM9Pv/3wdZQHyaz4Lg3/EW013hAeHjwA+ohIPkmLRDUfz+vvHRyY0zWTMdRr7imjCNqb Pguun7BQ==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1t4Pfb-00000005XB4-2lXI; Fri, 25 Oct 2024 19:08:23 +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 v2 02/10] ecryptfs: Use a folio throughout ecryptfs_read_folio() Date: Fri, 25 Oct 2024 20:08:12 +0100 Message-ID: <20241025190822.1319162-3-willy@infradead.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241025190822.1319162-1-willy@infradead.org> References: <20241025190822.1319162-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(). Use 'err' instead of 'rc' for clarity. Also remove the unnecessary call to ClearPageUptodate(); the uptodate flag is already clear if this function is being called. That lets us switch to folio_end_read() which does one atomic flag operation instead of two. Signed-off-by: Matthew Wilcox (Oracle) --- fs/ecryptfs/mmap.c | 50 +++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c index 92ea39d907de..25a756fec5c2 100644 --- a/fs/ecryptfs/mmap.c +++ b/fs/ecryptfs/mmap.c @@ -178,55 +178,51 @@ 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; - int rc = 0; + &ecryptfs_inode_to_private(inode)->crypt_stat; + int err = 0; if (!crypt_stat || !(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) { - rc = ecryptfs_read_lower_page_segment(page, page->index, 0, - PAGE_SIZE, - page->mapping->host); + err = 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, + err = ecryptfs_copy_up_encrypted_with_header(&folio->page, crypt_stat); - if (rc) { + if (err) { printk(KERN_ERR "%s: Error attempting to copy " "the encrypted content from the lower " "file whilst inserting the metadata " - "from the xattr into the header; rc = " - "[%d]\n", __func__, rc); + "from the xattr into the header; err = " + "[%d]\n", __func__, err); goto out; } } else { - rc = ecryptfs_read_lower_page_segment( - page, page->index, 0, PAGE_SIZE, - page->mapping->host); - if (rc) { - printk(KERN_ERR "Error reading page; rc = " - "[%d]\n", rc); + err = ecryptfs_read_lower_page_segment(&folio->page, + folio->index, 0, folio_size(folio), + inode); + if (err) { + printk(KERN_ERR "Error reading page; err = " + "[%d]\n", err); goto out; } } } else { - rc = ecryptfs_decrypt_page(page); - if (rc) { + err = ecryptfs_decrypt_page(&folio->page); + if (err) { ecryptfs_printk(KERN_ERR, "Error decrypting page; " - "rc = [%d]\n", rc); + "err = [%d]\n", err); goto out; } } out: - if (rc) - ClearPageUptodate(page); - else - SetPageUptodate(page); - ecryptfs_printk(KERN_DEBUG, "Unlocking page with index = [0x%.16lx]\n", - page->index); - unlock_page(page); - return rc; + ecryptfs_printk(KERN_DEBUG, "Unlocking folio with index = [0x%.16lx]\n", + folio->index); + folio_end_read(folio, err == 0); + return err; } /* From patchwork Fri Oct 25 19:08:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13851338 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 CEA3E20D50B; Fri, 25 Oct 2024 19:08:25 +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=1729883308; cv=none; b=JgEja+ewMZhX+SxVKkHlU/Q4aIinX2C53O2aV/n8GBtaXTsGH9vA1pxk+oGAFaD5lxSCCuDIIWlSYizb50Dh/erxE4l1UJ3klK3e3rbdTkfbYR3TwRINBVGrf11s5n9wkrJnfRdipTqCSHJ+m8PiMGn7M8AObdHXG1ssXHIoVZM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729883308; c=relaxed/simple; bh=ojjdtH8wwN2gx0LLWaCdJn90MbZLfqJQ8xCLGuKjS/U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OhL6ilDFoP6HWk2TLDIpodma6RXIBvs5NNiivAvMmzsszBKvxE8oh4KvbAzP8nud3GGlovaSQrWDrpiOEjyz+ihaYAWcH7rC2Xxm8CiKdDlbjiBcJTnr8Hv0AJ5zDYde/OtsdYTjJ4Ik7izIoEnY/rVFdRO3c7nlFR3OBm9Qjvo= 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=R4DN4upI; 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="R4DN4upI" 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=jc8caRVXBO4jUHzGBRatQ/0YKXkRahvWyjp4uv+Vz74=; b=R4DN4upI76RrzQHgB37eAlJV/h RTQBax3RXioqCsOS+cjO9C0aN7GMB4xkEOeau0P8fb9lY1IGiaEoFGc3Qcs5GTGK8lGNRvRW5v6Bf xzHXmwUyvRho59qy7W53lNnrHVeIK8OH6OeTgU5/NmI1sdAHm8Qza81QLz/Txj22Fnl6aZG8zLqjj /zhpS8v5zhrPkjtkykMbdQhqLgtqMVeUvARWq5VvyOLXadsYgDLzFVEY4N+WY4fiSFC31o+5SYSmI TDGhvtlL4ZB2Cb0X5UGsNxp9H1Y5T23WCczvGqWs87+UoQUVvZm4pLJeKJK4jCbU5949XDey6dLQm q84Z5edA==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1t4Pfb-00000005XB8-3H5g; Fri, 25 Oct 2024 19:08:23 +0000 From: "Matthew Wilcox (Oracle)" To: Tyler Hicks Cc: "Matthew Wilcox (Oracle)" , ecryptfs@vger.kernel.org, Christian Brauner , linux-fsdevel@vger.kernel.org, Pankaj Raghav Subject: [PATCH v2 03/10] ecryptfs: Convert ecryptfs_copy_up_encrypted_with_header() to take a folio Date: Fri, 25 Oct 2024 20:08:13 +0100 Message-ID: <20241025190822.1319162-4-willy@infradead.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241025190822.1319162-1-willy@infradead.org> References: <20241025190822.1319162-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 | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c index 25a756fec5c2..bd78a36ed479 100644 --- a/fs/ecryptfs/mmap.c +++ b/fs/ecryptfs/mmap.c @@ -95,7 +95,7 @@ static void strip_xattr_flag(char *page_virt, /** * ecryptfs_copy_up_encrypted_with_header - * @page: Sort of a ``virtual'' representation of the encrypted lower + * @folio: Sort of a ``virtual'' representation of the encrypted lower * file. The actual lower file does not have the metadata in * the header. This is locked. * @crypt_stat: The eCryptfs inode's cryptographic context @@ -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,8 +189,8 @@ 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) { - err = ecryptfs_copy_up_encrypted_with_header(&folio->page, - crypt_stat); + err = ecryptfs_copy_up_encrypted_with_header(folio, + crypt_stat); if (err) { printk(KERN_ERR "%s: Error attempting to copy " "the encrypted content from the lower " @@ -291,7 +291,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 Fri Oct 25 19:08:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13851335 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 760CC20D507; Fri, 25 Oct 2024 19:08:25 +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=1729883307; cv=none; b=nXlytjDVEksCbVijbK3oS++m2s097GinEkBFihMSQRtOfeUC4gX4OcIeLXeLSJAFQLVm2WTXz2UfMHfL4Hj2HE+rwL1FMxBHzRqoGwBbwr2IUQf6KT7kAt1BdsbfY1H2kvD6pO+IK77oyZnkzUTJtneybe5/RAW+wjjt0ZRCf90= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729883307; c=relaxed/simple; bh=9enTVMVHs12oKfVFpWnjhqvGuFpEAoOlLxy3Fzi7IXA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Iga8YxF+5Sdxx0S8LW1izZjKLkob7JE1bonBU8yMPXYcaZM7OcdmNc818I7YDHCa2uzGklrCKzEtluyRLHJVoGsZX3OQZzRWORIQ315To5eTkFy5Ce9uO76UWr/tP6XCqc2Cy0W7/Txr/qqdkbGEY27MkIMba+MK1O8tB4LdQVA= 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=Z9CKdDsE; 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="Z9CKdDsE" 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=bYLtvapkR7mcubzCOgvmer10s+f1RTTVikU9TF3hbBA=; b=Z9CKdDsEz4JMlRlPWuCVGKZt01 GtO1EvbE+LYe8HAn77ofsWAET1MG3O3GQMZbNWTuDMfKPVvVdhWFJnmiDgpAl5TgzgsNxC+ZzPaSl +uqkEUmK7QRPrSYwSLThXHi9fL3pdtBUNUmaGRrug3aZo+9xK7mwcO3aU+WxqwlgOH5kG7zar1YBo g4Xky4/PKYi6Xr6f3vqfY7KMXGwnpOMiqM6da0zh8jgoet0KZMLiY0tYLIKwZ8dgtY+dzwrHeFxZm qWvnICkolymZVqN4+sd8CzMkQtOzmG3GjE8p27c9kS0Xys7w/1EY2mBAnLPrLUvnTdW+zbbGkRi28 DcyiMMUg==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1t4Pfb-00000005XBJ-3sKj; Fri, 25 Oct 2024 19:08:23 +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 v2 04/10] ecryptfs: Convert ecryptfs_read_lower_page_segment() to take a folio Date: Fri, 25 Oct 2024 20:08:14 +0100 Message-ID: <20241025190822.1319162-5-willy@infradead.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241025190822.1319162-1-willy@infradead.org> References: <20241025190822.1319162-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 | 13 ++++++------- fs/ecryptfs/read_write.c | 10 +++++----- 3 files changed, 12 insertions(+), 13 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 bd78a36ed479..1fc87c83e43c 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,9 +184,8 @@ static int ecryptfs_read_folio(struct file *file, struct folio *folio) int err = 0; if (!crypt_stat || !(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) { - err = ecryptfs_read_lower_page_segment(&folio->page, folio->index, 0, - folio_size(folio), - inode); + err = ecryptfs_read_lower_page_segment(folio, folio->index, 0, + folio_size(folio), inode); } else if (crypt_stat->flags & ECRYPTFS_VIEW_AS_ENCRYPTED) { if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR) { err = ecryptfs_copy_up_encrypted_with_header(folio, @@ -201,7 +200,7 @@ static int ecryptfs_read_folio(struct file *file, struct folio *folio) } } else { - err = ecryptfs_read_lower_page_segment(&folio->page, + err = ecryptfs_read_lower_page_segment(folio, folio->index, 0, folio_size(folio), inode); if (err) { @@ -279,7 +278,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", @@ -305,7 +304,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 Fri Oct 25 19:08:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13851343 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 E0DF220F3E9; Fri, 25 Oct 2024 19:08:28 +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=1729883310; cv=none; b=jrcGNMWw7SzpBR4WXXu/02wBJvAmNj96XUKizyfhi7Uuq5PYIQEgSbDtlljcTmLj3i+7oy7DQ7i3ZY7Pp2FpJr2FMEIuX94uUlOtCEKkWqeKbJb2oQZpWgZTGN/1h2mb/ZolaJrkezg/rBz7w9tE10ZD79M7W0mfeaZfhpliDQk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729883310; c=relaxed/simple; bh=ALkEMND5YMvhbJ2+CnCL8OdosGMJCP2ZOv9ELv+nEfw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UPCLKvslyGBMQWJ+w2J6SLOrznbcjsDs7NRIq2LLsGBJXCVCPXVTKICJ16AX3b2NMX/TRC4Y5mq545PBIgrmjqmeA5JHdxHt9f1bMnwMjaQc7dA5qQGWN7rcZvsvYd5aO3ZpAx/j6eqPjKHAp6MHNoyshxmp56sr8YtvpPLVhOI= 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=srhCtQ4e; 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="srhCtQ4e" 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=R+C+x5yy1n5WeLXrriW8ixLELGKIHvlS2PI0jfWKMBU=; b=srhCtQ4eFkLsvISYO/hpy1FgFo kip2gpRjAJXscP8CvGTnedctHCjrTVMzNLgcJfDBzy1ehtyhKoF8DE+YglIANkciXWh09pKmn7Mml f7FjQoSdugnpwQkS8Eo+A4HVS4688y/4m68qjWN6mRkYBoWHmig+JiQfHmFvrZtatLu4hvWKv/GaY JFxDegwg/2aakj413rAF63Oli4a/RaJ5wvrOH3K7fDLtMKv5vyXL21Ickv7mDHzBB+cPHUFbN8b1l xbCwfsZyO/3N6qbWIq800s1wry9DXWR0kr83G8czbpjOyKKCC3CYZHrYuYV/UV+HI7h6YLXL7qVsY J8EPTjxw==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1t4Pfc-00000005XBL-05vN; Fri, 25 Oct 2024 19:08:24 +0000 From: "Matthew Wilcox (Oracle)" To: Tyler Hicks Cc: "Matthew Wilcox (Oracle)" , ecryptfs@vger.kernel.org, Christian Brauner , linux-fsdevel@vger.kernel.org, Pankaj Raghav Subject: [PATCH v2 05/10] ecryptfs: Convert ecryptfs_write() to use a folio Date: Fri, 25 Oct 2024 20:08:15 +0100 Message-ID: <20241025190822.1319162-6-willy@infradead.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241025190822.1319162-1-willy@infradead.org> References: <20241025190822.1319162-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 1fc87c83e43c..f6b9390e720a 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 Fri Oct 25 19:08:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13851336 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 B0BC720D508; Fri, 25 Oct 2024 19:08:25 +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=1729883308; cv=none; b=UmH9MxuMf5fHUIpFbiJ8ECq0kk0jzUWVv0i9PFeF08MaAdtobB5r33V2ZuLX4stCGJhuRQTOWvGy4OtWijA3OEPfYmuycdr4CgfgIbWx3fkptT9eYvqwOLCg33wQLTQ14V/Wb13jibsrk/26lycPeI2btIAKPvVE23mL8oKfDfw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729883308; c=relaxed/simple; bh=zR1rFS9CcuxjNQMJISzDQGlXWxJJyIokWA6+HpfBpnM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cokzSJKKuquCegtlqH2LdR3dhFLz/Ip6SRfTCeirwCm9725HdTzLnTjMiUSajappi77O4iwVZonYmxdCSDvYn6MjDrITvWiXNdpok1zSHn7h7MB+aiRz4vQNCHVDz6dq7YGur8wI8WaearME7peAcUmRBRdkn6JOwhc+oO312Z0= 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=DFDAXATc; 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="DFDAXATc" 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=3c7tc6/8ADMDvwX4lzwD+tbR0dZCupwqYmZWb/nOPJA=; b=DFDAXATcWs07KDPrCKAzcFusL3 dLMNRW1X5hvvzUZ7IoPBbnL4sKgrmjWcJMnkKs4K6PcPtZ774a7ioocCmRhwjRP+Y2U0xl8qDnaQE HRcPoLEz+501l3ycEQLNLCywMFbSuWsr0nqJAiOKLEpsG1xGeqgEE1CYapy/POuvVxo1RVZSV4B+u XpDrW/ypDMrqQ52nlEe8itfrm22JF1eqrAcZP21KBnXTdH4uGBijGSHujRsyJAk9PyEa3PUgu4kKI PbGAmTzqtDLkzCReioY1s9+JYELKuduz6//auShOtTA0udMTctGZdUsj2g5KK1sj7cP1C/pBYf6wy HekGfL3w==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1t4Pfc-00000005XBS-0ck6; Fri, 25 Oct 2024 19:08:24 +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 v2 06/10] ecryptfs: Convert ecryptfs_write_lower_page_segment() to take a folio Date: Fri, 25 Oct 2024 20:08:16 +0100 Message-ID: <20241025190822.1319162-7-willy@infradead.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241025190822.1319162-1-willy@infradead.org> References: <20241025190822.1319162-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 f6b9390e720a..1c1eb9437505 100644 --- a/fs/ecryptfs/mmap.c +++ b/fs/ecryptfs/mmap.c @@ -454,7 +454,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 Fri Oct 25 19:08:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13851337 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 C550B20D50A; Fri, 25 Oct 2024 19:08:25 +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=1729883307; cv=none; b=M2vTOqdgaCZCjycMAMBiZx6QbA0cweysFq1/kHslQb3og4EUJ67tVe/NH9hnSsY/U8QhFj08K3d/wH3edHwWmYG76SEFOjIBh61TM71s3LX4248KsT4hZ1mhNs0Bac7vT0AEi38VzxLa9TsytVrY4GD00Nw31gW2E5BjPwbn8TI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729883307; c=relaxed/simple; bh=11GVfrGHVGUJ8rEw/ymHMCSa9wpYBo4NA4H0pP1QBbM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OKoBBJM8P9nFRRW6SRO7EmS9BPnm172ZzsOzg5TLGKszWOA7lIESxClQH2SS99K1A5FduDfVvGuyenuYntxYWrKsw7traYTYJ6qyfirYTnPt6Lw3Xrs/3fb6sBmwwucbEesGNLFIqHDmkndHH55RiVxxzT+2BPI1AD/htL3WeOs= 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=AJCIDfM1; 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="AJCIDfM1" 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=T8anEtHvOl0eVCeTvnZyGUr2OJt/aDQDu9u2v9ejoZQ=; b=AJCIDfM1Y4//I2IqWOQMuU+OU5 wgJSfg9s47djG8h8IJlKb2kcK0P2rvHvA7OUMjuMPy0DOzrEBJkb6Za041WLXsEZSlk1UEeC1SaAM UTP5g2NngRJcFNHf9toiYadk/4Wo6uRN8spmHhjjpQQGM7E6Clzc8M1Bpb1+iY/tpWcPyGPH/DMRl UwlT6oyt+nfWYzVzPZ1TpB/7mhfk/Jd5RD3c2Sc4BGJuv14LterHziIjPNNNU0kp+4kWBWiK6huBN tcHwFtmMR5Q/fJ190F2V+2wPpE1hCdQzT9RhPxDN7Bw9XXLKDDLU7qAw5LoXDZe7AcSj8Eu5Vv+qK vF+MmBMw==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1t4Pfc-00000005XBU-11Q3; Fri, 25 Oct 2024 19:08:24 +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 v2 07/10] ecryptfs: Convert ecryptfs_encrypt_page() to take a folio Date: Fri, 25 Oct 2024 20:08:17 +0100 Message-ID: <20241025190822.1319162-8-willy@infradead.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241025190822.1319162-1-willy@infradead.org> References: <20241025190822.1319162-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 | 12 ++++++------ fs/ecryptfs/ecryptfs_kernel.h | 2 +- fs/ecryptfs/mmap.c | 4 ++-- fs/ecryptfs/read_write.c | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c index 827278525fd9..995ae3a97d52 100644 --- a/fs/ecryptfs/crypto.c +++ b/fs/ecryptfs/crypto.c @@ -392,7 +392,7 @@ static int crypt_extent(struct ecryptfs_crypt_stat *crypt_stat, /** * ecryptfs_encrypt_page - * @page: Page mapped from the eCryptfs inode for the file; contains + * @folio: Folio mapped from the eCryptfs inode for the file; contains * decrypted content that needs to be encrypted (to a temporary * page; not in place) and written out to the lower file * @@ -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 1c1eb9437505..b2c22f49ef6f 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", @@ -476,7 +476,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 Fri Oct 25 19:08:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13851339 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 E8F5A20D51B; Fri, 25 Oct 2024 19:08:25 +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=1729883308; cv=none; b=iCn/AnzFvp3lWc0WkTF1JtaBf8E+7MXcRnOB7DT/cIhGU6/psJIPVZ+MD2nzGy71AaEDC88fTaQ4rUDP+Lq3bXrts0b4kviGcRhxt9vrMeP12mnjPgvsyUh/D6sr92EcpluTjNX7RRr61xhRXKqdSFyHVp4CNp61m/WZ1MOukiM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729883308; c=relaxed/simple; bh=zCtwuMGfmVQ+CLZLLhLQfjj/Ev/qC8lmWla36qaB6U8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Eq56lzgR0S+QhUcCWqkeDLrHmjABiNjjHnlSOBx0JE+Rsm6dYebLiSunTT2eTrinXPTAsfPrCAw25OE/OcslRagqXByLQBW5cvV0sTOA4YGW3caFiDWW6LvkCEW91ObueZ2/b5tOnvPXcWCqz6VP9Cq+N/CFcytVljyUpT/8R7A= 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=UfAGQyV1; 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="UfAGQyV1" 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=YGh8Qx+cNNRKdyZI9uSuxmcBFtJTd/xUnCbR88szoos=; b=UfAGQyV1ePC6yT2TRgOYsU2JJd 7wIVlkN56X0NPqHb0V87alZzeRFSegPgGRMDkXmcBuMObDHa8v4hkBrfmExNVBLd9Zv/x78ANw5V3 2nBGcVzhX1IHOUmORmCHD6/ck5sDmskvdSSZE9xzbVgCUqKjK37yg0fb50QnvFWinsmg2owYWo05y GeuHs5fC3BwmO/uzL9+BYbL6hCxDXMC1ocDhw8aiOJuY1h2hYpZny/9QEa12ZdYzff1mA3Zn7Hzof fDiPsM3n6BIMKH7ZaHpmahpmoeokzypU5CzvRVX1kePzYcpY4Xr0Ydz3W73pUoCQ6rpkVwmHn4a9v 6tPMWmJw==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1t4Pfc-00000005XBb-1eTu; Fri, 25 Oct 2024 19:08:24 +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 v2 08/10] ecryptfs: Convert ecryptfs_decrypt_page() to take a folio Date: Fri, 25 Oct 2024 20:08:18 +0100 Message-ID: <20241025190822.1319162-9-willy@infradead.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241025190822.1319162-1-willy@infradead.org> References: <20241025190822.1319162-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 | 11 ++++++----- fs/ecryptfs/ecryptfs_kernel.h | 2 +- fs/ecryptfs/mmap.c | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c index 995ae3a97d52..90d38da20f5c 100644 --- a/fs/ecryptfs/crypto.c +++ b/fs/ecryptfs/crypto.c @@ -461,7 +461,7 @@ int ecryptfs_encrypt_page(struct folio *folio) /** * ecryptfs_decrypt_page - * @page: Page mapped from the eCryptfs inode for the file; data read + * @folio: Folio mapped from the eCryptfs inode for the file; data read * and decrypted from the lower file will be written into this * page * @@ -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 b2c22f49ef6f..60f0ac8744b5 100644 --- a/fs/ecryptfs/mmap.c +++ b/fs/ecryptfs/mmap.c @@ -194,7 +194,7 @@ static int ecryptfs_read_folio(struct file *file, struct folio *folio) } } } else { - err = ecryptfs_decrypt_page(&folio->page); + err = ecryptfs_decrypt_page(folio); if (err) { ecryptfs_printk(KERN_ERR, "Error decrypting page; " "err = [%d]\n", err); @@ -305,7 +305,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 Fri Oct 25 19:08:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13851340 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 387AA20D51E; Fri, 25 Oct 2024 19:08:26 +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=1729883308; cv=none; b=EgwtiiPejacq5U2O4LVkSsXJe0DEhAcxCrIoSIho0u8yq3gsbug/x0nUZdvAfOKWlJ2BZfiMWs/xAhDBwoExFs1IGs/vn4T1e0OmGXeFxNiE3Mx3qqU5YyB30X2QcKVuSDxYyJUVoUP3FxR5uUeMx4hkCRn128uRixnHVSQjv0M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729883308; c=relaxed/simple; bh=Zf6IFeDThq7v2Y7xaFvMMf2OXdzzhK1pUHUjiCQJ+5w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gKcs6APUTb+cNRVM+ed7LWA4VHQnekdznX8EjofoRG1UKfv7q209AXVfbnFfRLbg5AealYTJSvi6jpCczo/2u1kRFD0P7hgyqr1jwBZdTlJzvKxIIMAJCuEH9xuwkPvN/pxJM+X4G2CA2Oh7PKw/Zt1Uo1ZP9PHwK3bn8jGC1QU= 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=VOThyNEo; 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="VOThyNEo" 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=6tUZAdyZshlb80tzJO64EAEmD350EUVJIOOAQNegrtw=; b=VOThyNEo6WelIa41NITLxPmQ0U Ej6HH9RG6bBaMzEgscsWlqJxaphsahgna+Dhh6RIP5TfQWxT4yz2jD62KdtuL+SBBk39Fj1ybaWgB j2P8lY7DsU3fHoHuBStZ2q02mZHFJm3g6oscYVjX730CbNkSsBdzohNQLMqbOfQ56uEybDgjoJyAD CWR42v089LXsIO3kz1WdOvYVD2FUbiykcpAR35NWKQuCJvfd7j4bPKuVD2R1sACp/O/qlnyj8/adA Sp94pjn4VHdF227OlJY948l6tttyRHkJf42SC8HkY3axkhEs1CTuVYN4OfIF3E9lKbvQJ8ZL+U8sw HqelW70A==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1t4Pfc-00000005XBk-2KIT; Fri, 25 Oct 2024 19:08:24 +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 v2 09/10] ecryptfs: Convert lower_offset_for_page() to take a folio Date: Fri, 25 Oct 2024 20:08:19 +0100 Message-ID: <20241025190822.1319162-10-willy@infradead.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241025190822.1319162-1-willy@infradead.org> References: <20241025190822.1319162-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 90d38da20f5c..bb65a3a5ee9b 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 Fri Oct 25 19:08:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13851341 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 36EFD1FF04A; Fri, 25 Oct 2024 19:08:26 +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=1729883308; cv=none; b=AIm0ECvg+HqggAkIUgsqux9q3fqZ7Rvaw1zePhHFvwhV1JYMJ49WZk0JyYWkVTNloKp4jr2yZ6kicXDq/yC0WFVtwkkDx86O4VWAuYUtyxETRPEy8BpWZHKjMEpEgnudra33sIWfCIyJvbH61LHlQnu1rUii6Q5K4ymdohdYRQY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729883308; c=relaxed/simple; bh=+N/3CNeSqYIiw3WeWycoxeyoK/Wg6RrHh9USwpRdx5g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YQwzP1i0LC5ftpwHZgrBaKUcVqbr3IOqOQBepAmEisj/QIc5vceoFdWy6TTsPWRaI+FE1MmelOrD9F/DN8APT5/VjCnkOuZm2+PMN09stKDFmOpc09x2QjICXC3L9BL3/kvO2S9xKz1ZGWMifIFZyfVZ64VCVI0X/jMtT7fSNYM= 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=pGLP2lMb; 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="pGLP2lMb" 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=oG70nI1x0BD9NrNKwoyfLV7xuyzNiqaZvDa2zjd+ZR8=; b=pGLP2lMbJttjY+JHAe6DLku11/ hAPguFWSzcwgJaSS/rhn4X4bjtREB07Sqi25v4NUgE690f0CfhlhkqSiE9pNmrVFVzHJySanFubC5 bfPZy9zoRNNDRQJied5e9Tez65fpSkVxt+zmN7Wpuq8F5FvjfoicWo41vknb58O53l1XBzMmluWFM iGRXpw30JjtLp/hHmwc29H2FfuWNbTR3s1N8rYaWSnCLl7U6CJqOh3o7VrW9NhkxynWnGhOgH/dB0 nNcOCAId0MbE7k38bX+sw1gpdMzfKB10OCSuv3qqqBhjhaujIhmXKhLbOQQYzQJwDrQiBRzYV5Egp 7K47pz+A==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1t4Pfc-00000005XBw-2k3p; Fri, 25 Oct 2024 19:08:24 +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 v2 10/10] ecryptfs: Pass the folio index to crypt_extent() Date: Fri, 25 Oct 2024 20:08:20 +0100 Message-ID: <20241025190822.1319162-11-willy@infradead.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241025190822.1319162-1-willy@infradead.org> References: <20241025190822.1319162-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 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c index bb65a3a5ee9b..69536cacdea8 100644 --- a/fs/ecryptfs/crypto.c +++ b/fs/ecryptfs/crypto.c @@ -340,6 +340,7 @@ static loff_t lower_offset_for_page(struct ecryptfs_crypt_stat *crypt_stat, * encryption operation * @dst_page: The page to write the result into * @src_page: The page to read from + * @page_index: The offset in the file (in units of PAGE_SIZE) * @extent_offset: Page extent offset for use in generating IV * @op: ENCRYPT or DECRYPT to indicate the desired operation * @@ -350,9 +351,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 +433,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 +507,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);