From patchwork Fri Jun 9 10:02:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13273619 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 D4726C7EE2E for ; Fri, 9 Jun 2023 10:02:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6ACD18E0009; Fri, 9 Jun 2023 06:02:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 65CA98E0001; Fri, 9 Jun 2023 06:02:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4FDB48E0009; Fri, 9 Jun 2023 06:02:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 3FC308E0001 for ; Fri, 9 Jun 2023 06:02:46 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id EC777A019D for ; Fri, 9 Jun 2023 10:02:45 +0000 (UTC) X-FDA: 80882770290.30.57F27B1 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf14.hostedemail.com (Postfix) with ESMTP id 3478710001C for ; Fri, 9 Jun 2023 10:02:43 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=X8nfrF2j; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf14.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.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=1686304964; 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=Q9KEcNHQNL0heWM2/AbZS5PCqRXLyTBij/nK3rNCY6c=; b=nK81/ieCR/tG3IduCUbXBiQbTMdzW/ADGZ3hvfeJCSpeY/KdeAY747V8lHTrrGL4NZ+bOq j3uu2pAQpC4wDl09d/D57vkWrrwK5qnshdYmvVwsWel8dHidC/tyI/C6D/XgHKnxwQcXrJ nvuTjUmtQ92PJSF/ga2EWimZyDjI91Y= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=X8nfrF2j; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf14.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686304964; a=rsa-sha256; cv=none; b=vjLob7SznL6J1Nx+u7V8pu/bYtOSCLPTynb7T2ZsSLW+vTjXOgJ9QjsHiiHFCfrCeBDTla 6cr8bvFIbpGZ2eHwoyCSglqGzl6UF3jbTyrt0xHzca3jsbzbP7fmYN6/tRKUJHkjms6GkJ CWDFvVVr/+GVgToBNtLVHKWAx0L+qnA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686304963; 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=Q9KEcNHQNL0heWM2/AbZS5PCqRXLyTBij/nK3rNCY6c=; b=X8nfrF2jTCA86pDidBpJkLlIK4wsBnGDikffEPrNRJN0JfShM4nlJZ0XRZev4A5LeyEHTl 7UaMUoTzw4n3rj5RV3anjOkDqaPThrCI/DrdMGRJcyPhJdcOveo9n4Y/pdA2BEEEeEfqUd Uc2UURQgAzD6L1dTTOgL3IUJVj3wQgI= 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-274-aAfw7x-ZPUWuB_Kb0AVAug-1; Fri, 09 Jun 2023 06:02:39 -0400 X-MC-Unique: aAfw7x-ZPUWuB_Kb0AVAug-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AB5E680120A; Fri, 9 Jun 2023 10:02:38 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.51]) by smtp.corp.redhat.com (Postfix) with ESMTP id 582EB145B965; Fri, 9 Jun 2023 10:02:35 +0000 (UTC) From: David Howells To: netdev@vger.kernel.org Cc: David Howells , Jakub Kicinski , "David S. Miller" , Eric Dumazet , Paolo Abeni , Willem de Bruijn , David Ahern , Matthew Wilcox , Jens Axboe , linux-mm@kvack.org, linux-kernel@vger.kernel.org, John Fastabend , Jakub Sitnicki , bpf@vger.kernel.org Subject: [PATCH net-next 4/6] tcp_bpf: Make tcp_bpf_sendpage() go through tcp_bpf_sendmsg(MSG_SPLICE_PAGES) Date: Fri, 9 Jun 2023 11:02:19 +0100 Message-ID: <20230609100221.2620633-5-dhowells@redhat.com> In-Reply-To: <20230609100221.2620633-1-dhowells@redhat.com> References: <20230609100221.2620633-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 3478710001C X-Stat-Signature: 3oxertd1xrpy9ryt7ypbckoafptxf9we X-HE-Tag: 1686304963-619036 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MMLjPsGkm6hOFvLy+nhdvW/AdLzp00JDM/Fz75KwObtyEXH5Y5HC6McdPKTi6ZgUMCEg5oTFOVCQQ6SqzP+ZroRbLRYinDcD5FZfMasIc/NMzWLt7yH6jrcywSHr+smmgKSP6sto9slNjV7H8pjtZ75+CTsRfOsWmg4KBXgSid6BvJkul3g8kjYUWc1soVXqdtwm+JRRHdStc01NNt1Ie5c5PtCWShiOCA/BYSBxuXoJOHek/Pqf08Z1KeU1LLqWGqDVrHQ4oMhyzv+h/0djccS9RN0cHadvNuR5qPcKhMDSUnEBwHPuSdcuxnqp8P3SlgAxXtHEWsYSmWiHNoWRCcXE92S8f+50qZ7yB9SE3n0gEduK9AaMTn9wBaB5kIjXXt2pHd2u5ieulKNFdRhOpEge3q1DpvWwVmBsVqcXof+1m0vcDnot0OPZL2J64V/zox5/HmmDd655z65X/zGkVNCCymn5qklgZt/ 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: Make tcp_bpf_sendpage() a wrapper around tcp_bpf_sendmsg(MSG_SPLICE_PAGES) rather than a loop calling tcp_sendpage(). sendpage() will be removed in the future. 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 e75023ea052f..5a84053ac62b 100644 --- a/net/ipv4/tcp_bpf.c +++ b/net/ipv4/tcp_bpf.c @@ -568,49 +568,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 {