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@xxxxxxxxx> Signed-off-by: Fabio M. De Francesco <fmdefrancesco@xxxxxxxxx> --- net/core/datagram.c | 4 ++-- net/core/sock.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) 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); -- 2.36.1