Received: by 10.192.165.148 with SMTP id m20csp882219imm; Fri, 27 Apr 2018 09:01:24 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrBehJ/W3JsVp2AuNCgWbpbyaMr5ok3h9TGpgTeelYMscC+k9tpQdZBaFP//lJFokD1doFV X-Received: by 2002:a63:7250:: with SMTP id c16-v6mr2542660pgn.385.1524844884010; Fri, 27 Apr 2018 09:01:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524844883; cv=none; d=google.com; s=arc-20160816; b=pyiPIIYBc/YhX1sxrpvF97buUxnNnFgh+iYSr0uPFINH1+jHd4U06t6CTIX486XzEf WPlAsV/BNlw/+up3AUtSbBY1h7KuQ0H6EhWDb3gthy5Gvd8BCon5wzxl4Py2fmA5KMCi PcxBMJ2RBegU6jEyWeaPMsUWiWOAFa9TYhGhDF7PR5H5PS8s/8fLBDP5LGaq5y94ouju FCBbN2mZNixtvcWsnlxfc+z+hrGuWfCpVdNTGHh6WZ4UVwHtV05NGAv6DVu5nUglANi+ mYbV5j+upnaWZDtBZaXwctQMYybMJAQ/ATp0PqWIxoA8i24JAjZv7RyMdEtQX2Tw2YZK nPcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=EPExV/f1S6B92uL6n7QMtbPDHb7RCZQVA0Kbf9qo4xw=; b=StlShgLD+0ihfYgrXtdL0WfddvCTgIxYMRJyMn+rRJmST4qCwEcgejUeYD1Dzoyolu YWXsDkqK5/O+B3B2XUvvWdll1XjwTfGmxrEKzHb6SljqUcxabiEP54gBw5tQuzv3/Tmi xHxwut7pntB5R6KqdXoYYtolmYuoDBF6IW4Cg8s3jFicSrXskNH/+UCm1EF+FVsd7jUI bl6uXojf+A862JG928CryFCBCMfWwZc0glidNHlD+4BgL19KXbRMpU5Cd55H2OS+YPje 56Vypji5UY+fVtawo0Kw5XndCrCoREO2oa7m800r8P9Vx38vrsmgoOb9LQWXJUka1ure 1oHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=LWb3kFqf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 145-v6si1430473pgd.561.2018.04.27.09.01.09; Fri, 27 Apr 2018 09:01:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=LWb3kFqf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758641AbeD0P7h (ORCPT + 99 others); Fri, 27 Apr 2018 11:59:37 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:36689 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758236AbeD0P61 (ORCPT ); Fri, 27 Apr 2018 11:58:27 -0400 Received: by mail-wr0-f194.google.com with SMTP id u18-v6so2254827wrg.3 for ; Fri, 27 Apr 2018 08:58:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=EPExV/f1S6B92uL6n7QMtbPDHb7RCZQVA0Kbf9qo4xw=; b=LWb3kFqfnrG+W4DGpcMpTkaEL6dJRTsAasg3l69sKKJGZR/5bLf6Z3w9MdsWaRi9v9 Ea7d1b71CNtaulBshx2XfCqrPtV6EWekqhgPyP93rl70AHFCvl4k2TpPbAXxYG0Gjltq DV5Y3vQRxVXSH89JQz8vO9fJF6KD/lmeaK1pjT0kvorq0IUV8oFrLR/LXNUj5aHQTjbu LINeS6rxOBpE+0ZumjEcQ3oUzWQ8IjU1JZPwdViJi2YqHk3Igtf6nN2XGvgOU5epGgv/ vYRTO0ciTdxGTQxH6gW8Z2/6HXB8e1RmQ3KNz/gSVW42McReKNpC+DIzSJF4pjtUTTWf IPlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=EPExV/f1S6B92uL6n7QMtbPDHb7RCZQVA0Kbf9qo4xw=; b=eb4Y1SsBej3fOvHC7FT4N1tzUXO2tk/8Px0lrHb3Xrv6ZNaJ6Xxk0Vsh+6IAdGTxxK rstrvsdDGxva1Mh3nUMzyDXARFmlSWLSd8gn7cLtTFjqDMQcZRvAobHnA+k5tcv15ZbZ 5ruY387Nwm1avd/j0X+Ls4drrS0wvpPRU/4dOphhrCWEH8r5XdoKJd/C2LUm3675p/PA h3/nxB3CZTF1brmRfR5S5n2X1bCRdIUjh1ABRsW8RdvYlfUayqZHAbPLLakdUSiSUBhG w8XF9j0ocsWJQyHHe+pEtdQiMaNjUUjtuyulPDu1gQv1tbEBcxqPU7QK8QsdZW1tl11i RFLA== X-Gm-Message-State: ALQs6tBNTPiI4WKeAUNwoACsX09k6aGP9fJ4Q8ZgVUTfhomV1U7zSsGK QrHqZEUh+Tt3GrPTdZ1AY0EVOg== X-Received: by 2002:adf:e343:: with SMTP id n3-v6mr2413183wrj.82.1524844705772; Fri, 27 Apr 2018 08:58:25 -0700 (PDT) Received: from localhost ([2620:15c:2c4:201:f5a:7eca:440a:3ead]) by smtp.gmail.com with ESMTPSA id c50-v6sm2211778wrc.11.2018.04.27.08.58.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 27 Apr 2018 08:58:24 -0700 (PDT) From: Eric Dumazet To: "David S . Miller" Cc: netdev , Andy Lutomirski , linux-kernel , linux-mm , Ka-Cheong Poon , Eric Dumazet , Eric Dumazet Subject: [PATCH v4 net-next 2/2] selftests: net: tcp_mmap must use TCP_ZEROCOPY_RECEIVE Date: Fri, 27 Apr 2018 08:58:09 -0700 Message-Id: <20180427155809.79094-3-edumazet@google.com> X-Mailer: git-send-email 2.17.0.441.gb46fe60e1d-goog In-Reply-To: <20180427155809.79094-1-edumazet@google.com> References: <20180427155809.79094-1-edumazet@google.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org After prior kernel change, mmap() on TCP socket only reserves VMA. We have to use getsockopt(fd, IPPROTO_TCP, TCP_ZEROCOPY_RECEIVE, ...) to perform the transfert of pages from skbs in TCP receive queue into such VMA. struct tcp_zerocopy_receive { __u64 address; /* in: address of mapping */ __u32 length; /* in/out: number of bytes to map/mapped */ __u32 recv_skip_hint; /* out: amount of bytes to skip */ }; After a successful getsockopt(...TCP_ZEROCOPY_RECEIVE...), @length contains number of bytes that were mapped, and @recv_skip_hint contains number of bytes that should be read using conventional read()/recv()/recvmsg() system calls, to skip a sequence of bytes that can not be mapped, because not properly page aligned. Signed-off-by: Eric Dumazet Cc: Andy Lutomirski Acked-by: Soheil Hassas Yeganeh --- tools/testing/selftests/net/tcp_mmap.c | 64 +++++++++++++++----------- 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/tools/testing/selftests/net/tcp_mmap.c b/tools/testing/selftests/net/tcp_mmap.c index dea342fe6f4e88b5709d2ac37b2fc9a2a320bf44..77f762780199ff1f69f9f6b3f18e72deddb69f5e 100644 --- a/tools/testing/selftests/net/tcp_mmap.c +++ b/tools/testing/selftests/net/tcp_mmap.c @@ -76,9 +76,10 @@ #include #include #include -#include #include #include +#include +#include #ifndef MSG_ZEROCOPY #define MSG_ZEROCOPY 0x4000000 @@ -134,11 +135,12 @@ void hash_zone(void *zone, unsigned int length) void *child_thread(void *arg) { unsigned long total_mmap = 0, total = 0; + struct tcp_zerocopy_receive zc; unsigned long delta_usec; int flags = MAP_SHARED; struct timeval t0, t1; char *buffer = NULL; - void *oaddr = NULL; + void *addr = NULL; double throughput; struct rusage ru; int lu, fd; @@ -153,41 +155,46 @@ void *child_thread(void *arg) perror("malloc"); goto error; } + if (zflg) { + addr = mmap(NULL, chunk_size, PROT_READ, flags, fd, 0); + if (addr == (void *)-1) + zflg = 0; + } while (1) { struct pollfd pfd = { .fd = fd, .events = POLLIN, }; int sub; poll(&pfd, 1, 10000); if (zflg) { - void *naddr; + socklen_t zc_len = sizeof(zc); + int res; - naddr = mmap(oaddr, chunk_size, PROT_READ, flags, fd, 0); - if (naddr == (void *)-1) { - if (errno == EAGAIN) { - /* That is if SO_RCVLOWAT is buggy */ - usleep(1000); - continue; - } - if (errno == EINVAL) { - flags = MAP_SHARED; - oaddr = NULL; - goto fallback; - } - if (errno != EIO) - perror("mmap()"); + zc.address = (__u64)addr; + zc.length = chunk_size; + zc.recv_skip_hint = 0; + res = getsockopt(fd, IPPROTO_TCP, TCP_ZEROCOPY_RECEIVE, + &zc, &zc_len); + if (res == -1) break; + + if (zc.length) { + assert(zc.length <= chunk_size); + total_mmap += zc.length; + if (xflg) + hash_zone(addr, zc.length); + total += zc.length; } - total_mmap += chunk_size; - if (xflg) - hash_zone(naddr, chunk_size); - total += chunk_size; - if (!keepflag) { - flags |= MAP_FIXED; - oaddr = naddr; + if (zc.recv_skip_hint) { + assert(zc.recv_skip_hint <= chunk_size); + lu = read(fd, buffer, zc.recv_skip_hint); + if (lu > 0) { + if (xflg) + hash_zone(buffer, lu); + total += lu; + } } continue; } -fallback: sub = 0; while (sub < chunk_size) { lu = read(fd, buffer + sub, chunk_size - sub); @@ -228,6 +235,8 @@ void *child_thread(void *arg) error: free(buffer); close(fd); + if (zflg) + munmap(addr, chunk_size); pthread_exit(0); } @@ -371,7 +380,8 @@ int main(int argc, char *argv[]) setup_sockaddr(cfg_family, host, &listenaddr); if (mss && - setsockopt(fdlisten, SOL_TCP, TCP_MAXSEG, &mss, sizeof(mss)) == -1) { + setsockopt(fdlisten, IPPROTO_TCP, TCP_MAXSEG, + &mss, sizeof(mss)) == -1) { perror("setsockopt TCP_MAXSEG"); exit(1); } @@ -402,7 +412,7 @@ int main(int argc, char *argv[]) setup_sockaddr(cfg_family, host, &addr); if (mss && - setsockopt(fd, SOL_TCP, TCP_MAXSEG, &mss, sizeof(mss)) == -1) { + setsockopt(fd, IPPROTO_TCP, TCP_MAXSEG, &mss, sizeof(mss)) == -1) { perror("setsockopt TCP_MAXSEG"); exit(1); } -- 2.17.0.441.gb46fe60e1d-goog