From patchwork Wed Mar 29 14:13:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13192546 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E09CAC74A5B for ; Wed, 29 Mar 2023 14:15:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1EE02900003; Wed, 29 Mar 2023 10:15:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 19EC3900002; Wed, 29 Mar 2023 10:15:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 018C4900003; Wed, 29 Mar 2023 10:15:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id E2C97900002 for ; Wed, 29 Mar 2023 10:15:48 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 6A0AF1A0653 for ; Wed, 29 Mar 2023 14:15:48 +0000 (UTC) X-FDA: 80622134376.23.7009E74 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf21.hostedemail.com (Postfix) with ESMTP id 9B94B1C0039 for ; Wed, 29 Mar 2023 14:15:46 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="B7/Li8vP"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf21.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680099346; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=cLmy3QT3PxPcXOXP8Tmrcj7ottmHeL6VPbhO66kxXIU=; b=7tAhM1mobQ15tvz4Bnv4FXWoQ2QeadBsKCrZAoQ4skmtePtFqYgo/usk6s3pDGxv9KbZSl qeR7PS6jECpuD+/1QycAZCcC2UL9hdnr7z768xt49WzccdJtcXTzYnaQmsXhVUz2OW6wU4 QCjtfkomiGQ9K0MZ8yKI31FNtXONR5M= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="B7/Li8vP"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf21.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680099346; a=rsa-sha256; cv=none; b=Kk5uYPgJuvHU0r7s6TCL4inJVmrlCm9rDNEuI28N8FRg9s065nuMqd/7TY+Nl6A91gTQOr va+cuG7TjWV8MUHWgBt6Xp2/S+lcbnhal0hFRH69EBJP2U5/MGCyGc7qzcVQCI4HE+eSdJ bwzX5IzW6ojrQMokGcDlMdqWl2DAI8g= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680099345; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cLmy3QT3PxPcXOXP8Tmrcj7ottmHeL6VPbhO66kxXIU=; b=B7/Li8vP54U6ZNw+x0ktzje7bcG2jarXaqAb+uhKJRybtsBxbErhfv/erhaKLeOy0qyjlj 5pumXGQs5nGsAyX8buKYRap7HXJXWoIge+MXEnLnMTyASM1SJOZ/oePZHtphkvvOrNTeb8 Kv1+M3lvlULCkABM0sTqdfNc43tYOxs= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-407-avHEhrC2M-SiXN4UZyk2qA-1; Wed, 29 Mar 2023 10:15:42 -0400 X-MC-Unique: avHEhrC2M-SiXN4UZyk2qA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9129B85530C; Wed, 29 Mar 2023 14:15:32 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 64BD62027040; Wed, 29 Mar 2023 14:15:30 +0000 (UTC) From: David Howells To: Matthew Wilcox , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: David Howells , Al Viro , Christoph Hellwig , Jens Axboe , Jeff Layton , Christian Brauner , Chuck Lever III , Linus Torvalds , netdev@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, John Fastabend , Jakub Sitnicki , bpf@vger.kernel.org Subject: [RFC PATCH v2 34/48] tcp_bpf: Make tcp_bpf_sendpage() go through tcp_bpf_sendmsg(MSG_SPLICE_PAGES) Date: Wed, 29 Mar 2023 15:13:40 +0100 Message-Id: <20230329141354.516864-35-dhowells@redhat.com> In-Reply-To: <20230329141354.516864-1-dhowells@redhat.com> References: <20230329141354.516864-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 9B94B1C0039 X-Stat-Signature: h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jEBZRd9Wk6OAGPfHM2f3ZAOLwVcdHGrwWOgKlSA9/jemOr8IZZIjX6WvfB6LKv5gsvQKHoE6dR3HRuLiSXFfrh1Njd7TPfX2IbPrJYvhewnPnArkqlCI/moflH+SlUeIuCJRGdBvPR/4+TKwS7MgjyU/4vno+PBKOy8To0JBB9M+zttD/0jI82C0pGr21tOdZFdGtnL0z5wSiZ8gbK03dZeodoj/y5Ckyfl8v0gdBy51nzU+n/HqJGYHULvnERJiUiQn5Ler1zDWGeFRzibTD8FjNBRFZmJj98+Hs0Dok2avZJi06uZ3WzTPjUFF72r+C1qM14mg+USnkew/IWmb8p/DUJeLocPDo1Z9QwZd05Yv1QubQng80WZ+Pao5E9Vh77dElPhYqApTZAYc/LFAwFr4skwp1Q4IA54b9M8og330HZNvn56rZYSqp1QDodA+IYSxRw9K8RM1aOV+2T49k72YZTtq8Bh+6lCoGngggRG9SkNGGitZ45GH4koeT6FBH0F4snYWX+9agukCq9zVbOuUPsjhlIJnPozsh0apQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Translate tcp_bpf_sendpage() calls to tcp_bpf_sendmsg(MSG_SPLICE_PAGES). Signed-off-by: David Howells cc: John Fastabend cc: Jakub Sitnicki cc: "David S. Miller" cc: Eric Dumazet cc: Jakub Kicinski cc: Paolo Abeni cc: Jens Axboe cc: Matthew Wilcox cc: bpf@vger.kernel.org cc: netdev@vger.kernel.org --- net/ipv4/tcp_bpf.c | 49 +++++++++------------------------------------- 1 file changed, 9 insertions(+), 40 deletions(-) diff --git a/net/ipv4/tcp_bpf.c b/net/ipv4/tcp_bpf.c index 7f17134637eb..de37a4372437 100644 --- a/net/ipv4/tcp_bpf.c +++ b/net/ipv4/tcp_bpf.c @@ -485,49 +485,18 @@ static int tcp_bpf_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) static int tcp_bpf_sendpage(struct sock *sk, struct page *page, int offset, size_t size, int flags) { - struct sk_msg tmp, *msg = NULL; - int err = 0, copied = 0; - struct sk_psock *psock; - bool enospc = false; - - psock = sk_psock_get(sk); - if (unlikely(!psock)) - return tcp_sendpage(sk, page, offset, size, flags); + struct bio_vec bvec; + struct msghdr msg = { + .msg_flags = flags | MSG_SPLICE_PAGES, + }; - lock_sock(sk); - if (psock->cork) { - msg = psock->cork; - } else { - msg = &tmp; - sk_msg_init(msg); - } + bvec_set_page(&bvec, page, size, offset); + iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, &bvec, 1, size); - /* Catch case where ring is full and sendpage is stalled. */ - if (unlikely(sk_msg_full(msg))) - goto out_err; - - sk_msg_page_add(msg, page, size, offset); - sk_mem_charge(sk, size); - copied = size; - if (sk_msg_full(msg)) - enospc = true; - if (psock->cork_bytes) { - if (size > psock->cork_bytes) - psock->cork_bytes = 0; - else - psock->cork_bytes -= size; - if (psock->cork_bytes && !enospc) - goto out_err; - /* All cork bytes are accounted, rerun the prog. */ - psock->eval = __SK_NONE; - psock->cork_bytes = 0; - } + if (flags & MSG_SENDPAGE_NOTLAST) + msg.msg_flags |= MSG_MORE; - err = tcp_bpf_send_verdict(sk, psock, msg, &copied, flags); -out_err: - release_sock(sk); - sk_psock_put(sk, psock); - return copied ? copied : err; + return tcp_bpf_sendmsg(sk, &msg, size); } enum {