diff mbox series

[RFC] net: core: Replace kmap() with kmap_local_page()

Message ID 20220701105152.6920-1-fmdefrancesco@gmail.com (mailing list archive)
State RFC
Delegated to: Netdev Maintainers
Headers show
Series [RFC] net: core: Replace kmap() with kmap_local_page() | expand

Checks

Context Check Description
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 6 this patch: 6
netdev/cc_maintainers warning 3 maintainers not CCed: soheil@google.com willemb@google.com talalahmad@google.com
netdev/build_clang success Errors and warnings before: 6 this patch: 6
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 6 this patch: 6
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 43 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Fabio M. De Francesco July 1, 2022, 10:51 a.m. UTC
The use of kmap() is being deprecated in favor of kmap_local_page().

With kmap_local_page(), the mappings are per thread, CPU local and not
globally visible. Taking page faults is allowed. Furthermore, the mappings
can be acquired from any context (including interrupts).

Therefore, use kmap_local_page() in sock.c and datagram.c because these
mappings are per thread, CPU local, and not globally visible.

Actually this is an RFC because I'm not 100% sure that the mappings in
sock.c are not handed over to other contexts. Unfortunately I know very
little about this code. The fact that "page" is kmapped and then kunmapped
before exiting sock_send_page*() is not a guarantee of thread locality.
That "kernel_sendmsg*()" is a bit "suspicious".

Can anyone please confirm whether or not "kaddr" is handed over to other
contexts while the call sites might sleep between kmap() / kunmap()?

Suggested-by: Ira Weiny <ira.weiny@intel.com>
Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
---
 net/core/datagram.c | 4 ++--
 net/core/sock.c     | 8 ++++----
 2 files changed, 6 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/net/core/datagram.c b/net/core/datagram.c
index 50f4faeea76c..3a8fa210e1a1 100644
--- a/net/core/datagram.c
+++ b/net/core/datagram.c
@@ -438,14 +438,14 @@  static int __skb_datagram_iter(const struct sk_buff *skb, int offset,
 		end = start + skb_frag_size(frag);
 		if ((copy = end - offset) > 0) {
 			struct page *page = skb_frag_page(frag);
-			u8 *vaddr = kmap(page);
+			u8 *vaddr = kmap_local_page(page);
 
 			if (copy > len)
 				copy = len;
 			n = INDIRECT_CALL_1(cb, simple_copy_to_iter,
 					vaddr + skb_frag_off(frag) + offset - start,
 					copy, data, to);
-			kunmap(page);
+			kunmap_local(vaddr);
 			offset += n;
 			if (n != copy)
 				goto short_copy;
diff --git a/net/core/sock.c b/net/core/sock.c
index 2ff40dd0a7a6..12dd6ced62cf 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -3155,11 +3155,11 @@  ssize_t sock_no_sendpage(struct socket *sock, struct page *page, int offset, siz
 	ssize_t res;
 	struct msghdr msg = {.msg_flags = flags};
 	struct kvec iov;
-	char *kaddr = kmap(page);
+	char *kaddr = kmap_local_page(page);
 	iov.iov_base = kaddr + offset;
 	iov.iov_len = size;
 	res = kernel_sendmsg(sock, &msg, &iov, 1, size);
-	kunmap(page);
+	kunmap_local(kaddr);
 	return res;
 }
 EXPORT_SYMBOL(sock_no_sendpage);
@@ -3170,12 +3170,12 @@  ssize_t sock_no_sendpage_locked(struct sock *sk, struct page *page,
 	ssize_t res;
 	struct msghdr msg = {.msg_flags = flags};
 	struct kvec iov;
-	char *kaddr = kmap(page);
+	char *kaddr = kmap_local_page(page);
 
 	iov.iov_base = kaddr + offset;
 	iov.iov_len = size;
 	res = kernel_sendmsg_locked(sk, &msg, &iov, 1, size);
-	kunmap(page);
+	kunmap_local(kaddr);
 	return res;
 }
 EXPORT_SYMBOL(sock_no_sendpage_locked);