public inbox for ecryptfs@vger.kernel.org
 help / color / mirror / Atom feed
From: "Fabio M. De Francesco" <fmdefrancesco@gmail.com>
To: Tyler Hicks <code@tyhicks.com>,
	Christian Brauner <brauner@kernel.org>,
	Dave Chinner <dchinner@redhat.com>,
	"Fabio M. De Francesco" <fmdefrancesco@gmail.com>,
	"Matthew Wilcox (Oracle)" <willy@infradead.org>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	Al Viro <viro@zeniv.linux.org.uk>,
	ecryptfs@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Ira Weiny <ira.weiny@intel.com>
Subject: [PATCH v2 3/3] fs/ecryptfs: Use kmap_local_page() in copy_up_encrypted_with_header()
Date: Wed, 26 Apr 2023 19:22:23 +0200	[thread overview]
Message-ID: <20230426172223.8896-4-fmdefrancesco@gmail.com> (raw)
In-Reply-To: <20230426172223.8896-1-fmdefrancesco@gmail.com>

kmap_atomic() has been deprecated in favor of kmap_local_page().

Therefore, replace kmap_atomic() with kmap_local_page() in
ecryptfs_copy_up_encrypted_with_header().

kmap_atomic() is implemented like a kmap_local_page() which also
disables page-faults and preemption (the latter only in !PREEMPT_RT
kernels). The kernel virtual addresses returned by these two API are
only valid in the context of the callers (i.e., they cannot be handed to
other threads).

With kmap_local_page() the mappings are per thread and CPU local like
in kmap_atomic(); however, they can handle page-faults and can be called
from any context (including interrupts). The tasks that call
kmap_local_page() can be preempted and, when they are scheduled to run
again, the kernel virtual addresses are restored and are still valid.

In ecryptfs_copy_up_encrypted_with_header(), the block of code between
the mapping and un-mapping does not depend on the above-mentioned side
effects of kmap_aatomic(), so that the mere replacements of the old API
with the new one is all that is required (i.e., there is no need to
explicitly call pagefault_disable() and/or preempt_disable()).

Tested in a QEMU/KVM x86_32 VM, 6GB RAM, booting a kernel with
HIGHMEM64GB enabled.

Cc: Ira Weiny <ira.weiny@intel.com>
Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
---
 fs/ecryptfs/mmap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c
index 373c3e5747e6..cb1e998ce54d 100644
--- a/fs/ecryptfs/mmap.c
+++ b/fs/ecryptfs/mmap.c
@@ -125,7 +125,7 @@ ecryptfs_copy_up_encrypted_with_header(struct page *page,
 			/* This is a header extent */
 			char *page_virt;
 
-			page_virt = kmap_atomic(page);
+			page_virt = kmap_local_page(page);
 			memset(page_virt, 0, PAGE_SIZE);
 			/* TODO: Support more than one header extent */
 			if (view_extent_num == 0) {
@@ -138,7 +138,7 @@ ecryptfs_copy_up_encrypted_with_header(struct page *page,
 							       crypt_stat,
 							       &written);
 			}
-			kunmap_atomic(page_virt);
+			kunmap_local(page_virt);
 			flush_dcache_page(page);
 			if (rc) {
 				printk(KERN_ERR "%s: Error reading xattr "
-- 
2.40.0


  parent reply	other threads:[~2023-04-26 17:22 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-26 17:22 [PATCH v2 0/3] fs/ecryptfs: Replace kmap{,_atomic}() with kmap_local_page() Fabio M. De Francesco
2023-04-26 17:22 ` [PATCH v2 1/3] fs/ecryptfs: Replace kmap() " Fabio M. De Francesco
2023-04-26 17:22 ` [PATCH v2 2/3] fs/ecryptfs: Use kmap_local_page() in ecryptfs_write() Fabio M. De Francesco
2023-04-26 17:22 ` Fabio M. De Francesco [this message]
2023-06-28 13:50 ` [PATCH v2 0/3] fs/ecryptfs: Replace kmap{,_atomic}() with kmap_local_page() Fabio M. De Francesco
2023-06-30  2:31   ` Eric Biggers
2023-06-30  7:38     ` Christian Brauner
2023-06-30  8:45 ` Christian Brauner
2023-07-01 10:46   ` Fabio M. De Francesco
2023-08-17 17:13   ` Fabio M. De Francesco
2023-08-18 13:18     ` Christian Brauner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230426172223.8896-4-fmdefrancesco@gmail.com \
    --to=fmdefrancesco@gmail.com \
    --cc=brauner@kernel.org \
    --cc=code@tyhicks.com \
    --cc=dchinner@redhat.com \
    --cc=ecryptfs@vger.kernel.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=ira.weiny@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox