net-zerocopy: Fast return if inq < PAGE_SIZE
authorArjun Roy <arjunroy@google.com>
Wed, 2 Dec 2020 22:53:46 +0000 (14:53 -0800)
committerJakub Kicinski <kuba@kernel.org>
Fri, 4 Dec 2020 21:40:53 +0000 (13:40 -0800)
Sometimes, we may call tcp receive zerocopy when inq is 0,
or inq < PAGE_SIZE, in which case we cannot remap pages. In this case,
simply return the appropriate hint for regular copying without taking
mmap_sem.

Signed-off-by: Arjun Roy <arjunroy@google.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Soheil Hassas Yeganeh <soheil@google.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/ipv4/tcp.c

index aa1040b5a9776d2f88043c2e487d57cffba1d2a8..b9e44ad2b40d97e88ac1e3133338f9916d731631 100644 (file)
@@ -1904,6 +1904,14 @@ static int tcp_zerocopy_receive(struct sock *sk,
 
        sock_rps_record_flow(sk);
 
+       if (inq < PAGE_SIZE) {
+               zc->length = 0;
+               zc->recv_skip_hint = inq;
+               if (!inq && sock_flag(sk, SOCK_DONE))
+                       return -EIO;
+               return 0;
+       }
+
        mmap_read_lock(current->mm);
 
        vma = find_vma(current->mm, address);