From patchwork Wed May 24 14:49:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13254098 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 931E6C7EE23 for ; Wed, 24 May 2023 14:49:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1DC02900004; Wed, 24 May 2023 10:49:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1654C900002; Wed, 24 May 2023 10:49:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F20EB900004; Wed, 24 May 2023 10:49:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id E3853900002 for ; Wed, 24 May 2023 10:49:38 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 680AD409F6 for ; Wed, 24 May 2023 14:49:38 +0000 (UTC) X-FDA: 80825432436.07.A95D0B0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf22.hostedemail.com (Postfix) with ESMTP id 7A99DC0014 for ; Wed, 24 May 2023 14:49:35 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UiOM2Gqt; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf22.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=1684939775; 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=97CTgaKk+HjxMsHB1NZqYRmtg/935y1khOuMG78saNk=; b=k1/AdlhNX0lFCIFY2AmjbvwLRRvwSeeMqe4bjHv9E7f19YHTn1g4zciRio6l7Fpd/+nNI0 TVwck8d3lSpBakvZs94WvX8HNVt2X8mavYdTlP2Ae6HHUYw2laLo9kE03hlnfjXvN16Scg 4TzuPjEMA0He0QZHjvxIGeiZzRzt4nI= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UiOM2Gqt; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf22.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=1684939775; a=rsa-sha256; cv=none; b=2P/jKyJVGuz6NM8C/zkZf1HJDlP6uP9+hTUjJOhJ+hJ9d4YtxLtk9lr+rNZTEaPxAHjpmT w11regMBH9uq6nBbf8r9bmbmFdIAhn0cJZ6I4TGcXKIYsN+LKtrjL5g0Gc7jLEaWrwMQrT cymSsXM04m4qYLTYrcRRqtgHDNHAhF0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684939774; 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=97CTgaKk+HjxMsHB1NZqYRmtg/935y1khOuMG78saNk=; b=UiOM2Gqt70+tvRsoicjN18XTKp7IUOk0QVTyBVWfDZF2NRIsDo2ws06ufQpYKgoeLXslUS nV1xHJgjiambG7qKiEi7qYGIxiUtdG8c//WCpn6+PqUJE4mQ2HIBouHAocnx6Mns34+nW6 zYfBO/2ev2kULwErDuaC731fMHB1myY= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-651-Tcx3RMC7MxyDhN2LK1DGPQ-1; Wed, 24 May 2023 10:49:31 -0400 X-MC-Unique: Tcx3RMC7MxyDhN2LK1DGPQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 91F1229ABA03; Wed, 24 May 2023 14:49:30 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.39.192.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id A11011121314; Wed, 24 May 2023 14:49:28 +0000 (UTC) From: David Howells To: netdev@vger.kernel.org Cc: David Howells , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , David Ahern , Matthew Wilcox , Jens Axboe , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Ayush Sawal Subject: [PATCH net-next 1/4] chelsio: Support MSG_SPLICE_PAGES Date: Wed, 24 May 2023 15:49:20 +0100 Message-Id: <20230524144923.3623536-2-dhowells@redhat.com> In-Reply-To: <20230524144923.3623536-1-dhowells@redhat.com> References: <20230524144923.3623536-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Rspamd-Queue-Id: 7A99DC0014 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: t6x9qy8fydq9styupwy4it4nc33zrojh X-HE-Tag: 1684939775-457792 X-HE-Meta: U2FsdGVkX1+c53VU7JuXfd9G0IDNQoxtX9Llc4rnXxnJTrIEUYtNyXMK+GhonNcS/XhtnJKXW4m491YThjQd9Qwog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mbNtKuwOKBcxKKJ7qMlDAWUnLi6m2EI3QgqR4kQLBFsYCBqXmN+Q5UszB+exkbH4lPAp8rZcYYC803E8hfknoszzF6TqoZBxoShmadXjfA+unu/EGMsI/mdtRN5/0PmGaf3r4SPdwK0VJVsXnJpLDl3t22EU8FVtPMOimaLWq9oA6lZth7k5BhsTjYMd9MWWqWD5vC46BLUteZ2+Dp0ACXl9HsXaLqHULe5XjhE1DCRB8Jra+Y3dNDbeJlEGRd7iQAzflbkFEb01JnmPJMjkTEewDBRZDecj30hwQiniohCiaGoCgGDpN9eg/8nVRp0mPwjVDDr+PRrePrdbepSCR8r3TjXgV9+Qep4vxNjcIUQ7vhPGQu7bobzeo= 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 Chelsio's TLS offload sendmsg() support MSG_SPLICE_PAGES, splicing in pages from the source iterator if possible and copying the data in otherwise. This allows ->sendpage() to be replaced by something that can handle multiple multipage folios in a single transaction. Signed-off-by: David Howells cc: Ayush Sawal cc: "David S. Miller" cc: Eric Dumazet cc: Jakub Kicinski cc: Paolo Abeni cc: Jens Axboe cc: Matthew Wilcox cc: netdev@vger.kernel.org --- .../ethernet/chelsio/inline_crypto/chtls/chtls_io.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_io.c b/drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_io.c index ae6b17b96bf1..1d08386ac916 100644 --- a/drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_io.c +++ b/drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_io.c @@ -1092,7 +1092,17 @@ int chtls_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) if (copy > size) copy = size; - if (skb_tailroom(skb) > 0) { + if (msg->msg_flags & MSG_SPLICE_PAGES) { + err = skb_splice_from_iter(skb, &msg->msg_iter, copy, + sk->sk_allocation); + if (err < 0) { + if (err == -EMSGSIZE) + goto new_buf; + goto do_fault; + } + copy = err; + sk_wmem_queued_add(sk, copy); + } else if (skb_tailroom(skb) > 0) { copy = min(copy, skb_tailroom(skb)); if (is_tls_tx(csk)) copy = min_t(int, copy, csk->tlshws.txleft); From patchwork Wed May 24 14:49:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13254099 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 76BEBC77B73 for ; Wed, 24 May 2023 14:49:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0CC8C900002; Wed, 24 May 2023 10:49:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 005DD280001; Wed, 24 May 2023 10:49:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D0084900005; Wed, 24 May 2023 10:49:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id BEDD8900002 for ; Wed, 24 May 2023 10:49:40 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 76DC51409D6 for ; Wed, 24 May 2023 14:49:40 +0000 (UTC) X-FDA: 80825432520.19.03C1D80 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf28.hostedemail.com (Postfix) with ESMTP id AB5C9C001C for ; Wed, 24 May 2023 14:49:38 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fBjZNcaQ; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf28.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=1684939778; 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=nothT9FIq6Z9ycyWUkVIpgNT4wFVAcCVf2ceuhBnnpo=; b=zbszPfMq9Vdca4eI+yybZnUGh3MAYjuoDXk4CepTlTJoyDiLQhQNyeVkgmbctLN27GDwmD ICKavGGqj6gyAGQeoM+Uq2Eh1uF9jKlWkEDOtMbDiBFLxxkzKP0o80ZJESqr9u3yXXMycR zOtYJW+Nrl0fqAIPrfeMze+cVvAnI60= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fBjZNcaQ; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf28.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=1684939778; a=rsa-sha256; cv=none; b=ewERNa9wDae0zO09sP9efQwiukx2y4CyW7fEBHuYbj+ySyq5a9mBa99SQxVTIVv7AA2hpj d2+BNCisE5P4w1zB5m4eLBieKtaqgCfXg7Vqk9EdHv2+HJahTt+htEuARqzLDb6bmPf68f Xv5Cqx2TgPwBr8fkYIAloAP2h+WsN4Q= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684939777; 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=nothT9FIq6Z9ycyWUkVIpgNT4wFVAcCVf2ceuhBnnpo=; b=fBjZNcaQfqjaai6Vz0UTDH45ys3LmUuQ9iIdrN5PrrNjEEAkxMf5UdzJfg7Dgdb1YcJAlM gIiSwzc/tZzWQzXh4s2ZEsoo+O0OBYt9fhYGvJ1oyAmI+fLdC/+nA9bPSkVxyuLfgK0Fnq wju62OHvPLtoStTu/aGcuIXNq6IEdU4= 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-437-z3GsRf65Owi5Meq-H94WQA-1; Wed, 24 May 2023 10:49:34 -0400 X-MC-Unique: z3GsRf65Owi5Meq-H94WQA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 272A68007D9; Wed, 24 May 2023 14:49:33 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.39.192.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 63B86492B0A; Wed, 24 May 2023 14:49:31 +0000 (UTC) From: David Howells To: netdev@vger.kernel.org Cc: David Howells , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , David Ahern , Matthew Wilcox , Jens Axboe , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Ayush Sawal Subject: [PATCH net-next 2/4] chelsio: Convert chtls_sendpage() to use MSG_SPLICE_PAGES Date: Wed, 24 May 2023 15:49:21 +0100 Message-Id: <20230524144923.3623536-3-dhowells@redhat.com> In-Reply-To: <20230524144923.3623536-1-dhowells@redhat.com> References: <20230524144923.3623536-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Rsp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H4R4nDGBvzYCi7nt428px FGUsuRaK TnVgaK8iaMl2fHc7re8Jkq8l+4ERC3OlCRiehfbMX6OzuIL/kSEWLLzSRtgGvX7Rkp4gbg7J1/miRjFCNe81oOdpd/tKJJrg7O273l0hLItvSE//E9OVGztUyvHgSkQH6fhyf38VRIs8iZB+IkWLrTm1y7trF/IgpZCBQvcOXpUMOxEjXVifKmW5mloy4Cj7mV3V92e4RJKGVhN9YNLRYfJ+YstVJcmknFLD61oJJEoEx7Oi213eUnxNRIw9XOz9lN3dwY//cCLxZAGSiiH7gUITyk3hgB/RMzn2obgbD2qghizH6hYPbf+zSR9Edt3xu5LP2MAd0Dq4lVCFu8oQeydlZp1tdy5RiSGpDJ7OIt7gsUumeNAhHb+DR/k4pTmcYfUphQUSFKjQY+BiNyr60J+pYtRXhj2ZkAqv8v790gyRW1ezTQlGEgxyi140zQ478+TiqXpWtFiCNvvZjJsw/Un13vxykJLJbSJo1RWli0RLDjXjvXQ2EZNbfz7LgE2iMC3t5+3Ccov4yvNFzDcDQWY7Pqv6M0xiLtrACcKrnPWUk8Dw= 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: Convert chtls_sendpage() to use sendmsg() with MSG_SPLICE_PAGES rather than directly splicing in the pages itself. This allows ->sendpage() to be replaced by something that can handle multiple multipage folios in a single transaction. Signed-off-by: David Howells cc: Ayush Sawal cc: "David S. Miller" cc: Eric Dumazet cc: Jakub Kicinski cc: Paolo Abeni cc: Jens Axboe cc: Matthew Wilcox cc: netdev@vger.kernel.org --- .../chelsio/inline_crypto/chtls/chtls_io.c | 109 ++---------------- 1 file changed, 7 insertions(+), 102 deletions(-) diff --git a/drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_io.c b/drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_io.c index 1d08386ac916..65efd20ec796 100644 --- a/drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_io.c +++ b/drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_io.c @@ -1240,110 +1240,15 @@ int chtls_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) int chtls_sendpage(struct sock *sk, struct page *page, int offset, size_t size, int flags) { - struct chtls_sock *csk; - struct chtls_dev *cdev; - int mss, err, copied; - struct tcp_sock *tp; - long timeo; - - tp = tcp_sk(sk); - copied = 0; - csk = rcu_dereference_sk_user_data(sk); - cdev = csk->cdev; - lock_sock(sk); - timeo = sock_sndtimeo(sk, flags & MSG_DONTWAIT); + struct bio_vec bvec; + struct msghdr msg = { .msg_flags = flags | MSG_SPLICE_PAGES, }; - err = sk_stream_wait_connect(sk, &timeo); - if (!sk_in_state(sk, TCPF_ESTABLISHED | TCPF_CLOSE_WAIT) && - err != 0) - goto out_err; - - mss = csk->mss; - csk_set_flag(csk, CSK_TX_MORE_DATA); - - while (size > 0) { - struct sk_buff *skb = skb_peek_tail(&csk->txq); - int copy, i; - - if (!skb || (ULP_SKB_CB(skb)->flags & ULPCB_FLAG_NO_APPEND) || - (copy = mss - skb->len) <= 0) { -new_buf: - if (!csk_mem_free(cdev, sk)) - goto wait_for_sndbuf; + if (flags & MSG_SENDPAGE_NOTLAST) + msg.msg_flags |= MSG_MORE; - if (is_tls_tx(csk)) { - skb = get_record_skb(sk, - select_size(sk, size, - flags, - TX_TLSHDR_LEN), - true); - } else { - skb = get_tx_skb(sk, 0); - } - if (!skb) - goto wait_for_memory; - copy = mss; - } - if (copy > size) - copy = size; - - i = skb_shinfo(skb)->nr_frags; - if (skb_can_coalesce(skb, i, page, offset)) { - skb_frag_size_add(&skb_shinfo(skb)->frags[i - 1], copy); - } else if (i < MAX_SKB_FRAGS) { - get_page(page); - skb_fill_page_desc(skb, i, page, offset, copy); - } else { - tx_skb_finalize(skb); - push_frames_if_head(sk); - goto new_buf; - } - - skb->len += copy; - if (skb->len == mss) - tx_skb_finalize(skb); - skb->data_len += copy; - skb->truesize += copy; - sk->sk_wmem_queued += copy; - tp->write_seq += copy; - copied += copy; - offset += copy; - size -= copy; - - if (corked(tp, flags) && - (sk_stream_wspace(sk) < sk_stream_min_wspace(sk))) - ULP_SKB_CB(skb)->flags |= ULPCB_FLAG_NO_APPEND; - - if (!size) - break; - - if (unlikely(ULP_SKB_CB(skb)->flags & ULPCB_FLAG_NO_APPEND)) - push_frames_if_head(sk); - continue; -wait_for_sndbuf: - set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); -wait_for_memory: - err = csk_wait_memory(cdev, sk, &timeo); - if (err) - goto do_error; - } -out: - csk_reset_flag(csk, CSK_TX_MORE_DATA); - if (copied) - chtls_tcp_push(sk, flags); -done: - release_sock(sk); - return copied; - -do_error: - if (copied) - goto out; - -out_err: - if (csk_conn_inline(csk)) - csk_reset_flag(csk, CSK_TX_MORE_DATA); - copied = sk_stream_error(sk, flags, err); - goto done; + bvec_set_page(&bvec, page, size, offset); + iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, &bvec, 1, size); + return chtls_sendmsg(sk, &msg, size); } static void chtls_select_window(struct sock *sk) From patchwork Wed May 24 14:49:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13254100 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 BE433C7EE23 for ; Wed, 24 May 2023 14:49:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 55FF4280002; Wed, 24 May 2023 10:49:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4E941280001; Wed, 24 May 2023 10:49:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 361FE280002; Wed, 24 May 2023 10:49:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 23139280001 for ; Wed, 24 May 2023 10:49:45 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id EE5E012096C for ; Wed, 24 May 2023 14:49:44 +0000 (UTC) X-FDA: 80825432688.05.739C32E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf09.hostedemail.com (Postfix) with ESMTP id F1700140009 for ; Wed, 24 May 2023 14:49:42 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=AdA2jPmG; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf09.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=1684939783; 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=BBjfMnLRdPLaOtZKQ3MfDk6Q85OlEId07NY6t+N1kv8=; b=jAK48zIhDda+RlEg7eNDDidEOXfgz3HWDwuzuB5Qyl5XSz4x3PAbC1lcQYNXblucWMfT7R ccOeXZ3BrDTf6YSovw0PPyn2PmijYq93AdWjYT1DsYPqCqqSkcg/I31BJIEQZxciCINGqp CfXeWN0fYFQgs0DV/Dk8x+NN82oGYQY= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=AdA2jPmG; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf09.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=1684939783; a=rsa-sha256; cv=none; b=kGTHWu7bYRvVIOBKL0wwbfINRy/E1ti/b16wKfa4UOywxObcoNDlnZsarh9oydX0vSKV1Z xVJ0S7gJiqKrW3YYHmZTcmAGWfULVK9BrAD5XV+8Wk7F7BB2hTzvs3+3vRBWdH/vspzDxq 73w2xNai3gyg3vuBoyp4P0Kc31MzZFk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684939782; 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=BBjfMnLRdPLaOtZKQ3MfDk6Q85OlEId07NY6t+N1kv8=; b=AdA2jPmGhYnd2oBS42BqR7w5xG5pYZzAte4bDyexV0kpdc2Fs1H0Z17/8ZZ7xFAm6Utx1x rMu+uNqDOsBc8iFlFs4M7PrRt9aH38I6kUVRDJpxfA6knMr/pQeB12qlzzoMdEwnasnoJw sSOgGEFt3FKc8ljRr6+yZwKdnLMgBcg= 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-586-WIiQwQthN-adX17FR81rFw-1; Wed, 24 May 2023 10:49:36 -0400 X-MC-Unique: WIiQwQthN-adX17FR81rFw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D2C9785A5B5; Wed, 24 May 2023 14:49:35 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.39.192.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id D2BDC407DEC6; Wed, 24 May 2023 14:49:33 +0000 (UTC) From: David Howells To: netdev@vger.kernel.org Cc: David Howells , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , David Ahern , Matthew Wilcox , Jens Axboe , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Tom Herbert , Tom Herbert Subject: [PATCH net-next 3/4] kcm: Support MSG_SPLICE_PAGES Date: Wed, 24 May 2023 15:49:22 +0100 Message-Id: <20230524144923.3623536-4-dhowells@redhat.com> In-Reply-To: <20230524144923.3623536-1-dhowells@redhat.com> References: <20230524144923.3623536-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Rspamd-Queue-Id: F1700140009 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 4oew1bg7t4c7ehwej9cz3qdaanqxbaes X-HE-Tag: 1684939782-311307 X-HE-Meta: U2FsdGVkX1/bIhTkvmwsNkt3zk8DMRK/J7bxKgzooybEU/aZ7sjIYOjZi/t/41XzODVwiG9Dz5zWzC1NMV0r+n3M1zwvgAh25GNElmrQMR60HMifVivAPsGsVOMV2XLS8gCGux3yHsVm1e9OE7UcVooTsszF6D8pDbgyGQpoXkQlm49d3s+MC0OVgyB4PLAVGtUoLGsjTRq+8sBNBF1Bk54OPnmqwgYNwsfBdJCt0RFxzdYj/ihv463UOE0D7kWnqsBX5Fyt92pORk8IQaxRK8E/QeFC/+5qemyCJLGCEpzKvS8y0a/+ksL7i2Td3xL7sRQalybTES4DhJnj4WY6euPYCWm2E0fsu2iC55FiZRynDs0NdeQb+OdnnVPBsuCODju/wTWIJuBneGpyBaVNLsS2M/igiThmnVEe+QKEQ9UVvOCmZPLsiJAXTOuSnG1YlG/0YPHxxfYKs4GeqtYctiEHVO4pW9eTgu2ZjPh0zXZg/ap8jaoqqtp/aa3TUrKF6i5KhhvGBj70rJarP63RcWbuO1w7V6Tr+SKlhE3tca8a3fPZWEPXxOZsFFq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1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Make AF_KCM sendmsg() support MSG_SPLICE_PAGES. This causes pages to be spliced from the source iterator if possible. This allows ->sendpage() to be replaced by something that can handle multiple multipage folios in a single transaction. Signed-off-by: David Howells cc: Tom Herbert cc: Tom Herbert cc: Jakub Kicinski cc: Eric Dumazet cc: "David S. Miller" cc: Paolo Abeni cc: Jens Axboe cc: Matthew Wilcox cc: netdev@vger.kernel.org --- net/kcm/kcmsock.c | 55 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/net/kcm/kcmsock.c b/net/kcm/kcmsock.c index cfe828bd7fc6..411726d830c0 100644 --- a/net/kcm/kcmsock.c +++ b/net/kcm/kcmsock.c @@ -989,29 +989,50 @@ static int kcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) merge = false; } - copy = min_t(int, msg_data_left(msg), - pfrag->size - pfrag->offset); + if (msg->msg_flags & MSG_SPLICE_PAGES) { + copy = msg_data_left(msg); + if (!sk_wmem_schedule(sk, copy)) + goto wait_for_memory; - if (!sk_wmem_schedule(sk, copy)) - goto wait_for_memory; + err = skb_splice_from_iter(skb, &msg->msg_iter, copy, + sk->sk_allocation); + if (err < 0) { + if (err == -EMSGSIZE) + goto wait_for_memory; + goto out_error; + } - err = skb_copy_to_page_nocache(sk, &msg->msg_iter, skb, - pfrag->page, - pfrag->offset, - copy); - if (err) - goto out_error; + skb_shinfo(skb)->flags |= SKBFL_SHARED_FRAG; + sk_wmem_queued_add(sk, copy); + sk_mem_charge(sk, copy); - /* Update the skb. */ - if (merge) { - skb_frag_size_add(&skb_shinfo(skb)->frags[i - 1], copy); + if (head != skb) + head->truesize += copy; } else { - skb_fill_page_desc(skb, i, pfrag->page, - pfrag->offset, copy); - get_page(pfrag->page); + copy = min_t(int, msg_data_left(msg), + pfrag->size - pfrag->offset); + if (!sk_wmem_schedule(sk, copy)) + goto wait_for_memory; + + err = skb_copy_to_page_nocache(sk, &msg->msg_iter, skb, + pfrag->page, + pfrag->offset, + copy); + if (err) + goto out_error; + + /* Update the skb. */ + if (merge) { + skb_frag_size_add(&skb_shinfo(skb)->frags[i - 1], copy); + } else { + skb_fill_page_desc(skb, i, pfrag->page, + pfrag->offset, copy); + get_page(pfrag->page); + } + + pfrag->offset += copy; } - pfrag->offset += copy; copied += copy; if (head != skb) { head->len += copy; From patchwork Wed May 24 14:49:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13254101 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 A6C08C77B73 for ; Wed, 24 May 2023 14:49:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 141DF280003; Wed, 24 May 2023 10:49:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 07BC4280001; Wed, 24 May 2023 10:49:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CD6A5280003; Wed, 24 May 2023 10:49:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id BD0C5280001 for ; Wed, 24 May 2023 10:49:45 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 9E3671409B9 for ; Wed, 24 May 2023 14:49:45 +0000 (UTC) X-FDA: 80825432730.26.DB5DA1B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf25.hostedemail.com (Postfix) with ESMTP id D3408A000B for ; Wed, 24 May 2023 14:49:43 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=FbusvB9N; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf25.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=1684939783; 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=3J8PHmDPb0Wk4jmNU2VIBExWXmpJgDgYePfc2qOgcg8=; b=fSLY1TiPQiTFYUGPE+XaxoIaUVQwOalcqsMsaWEEVJvAamNER5TQFWn91G/I36Hb3WE5+W iGrjRLdVPZI1JOAdzurMzrs0Ie82MeX12l/9MvjuRSV0v/Lkzi89gDRkNtmk3PjcrPANXz sdzZ7B3ForXSnTUxCbDyzJMrkhJXYEo= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=FbusvB9N; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf25.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=1684939783; a=rsa-sha256; cv=none; b=TSrwBRDJNZTPFoaqO2cp85CTy0n2F/xxsmyxU2Pahls9o/QUkO/HbKeeydhH0OFHpP5o/d 4S2Vp84FI5CNhNfmQcHIFPCA5QhqERI0elmt39DfEEboIVin23SpPp8ljo1LLGVgG/rC5t RynwlczoGNEBOodQzhEnHzF8VMs0nqE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684939783; 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=3J8PHmDPb0Wk4jmNU2VIBExWXmpJgDgYePfc2qOgcg8=; b=FbusvB9NnRXGqXiBpoPmcDFIE9Ii/wrKBNFTJhKDom9Tr3lnbtKpXyXbqWOPSMcn4Vaddb arsjDapeeK1xy9Cpp5Y2U5/Ho9Kxqcu0vIYfr8CBWI0vNogm1riA3h86YOhk7K7itXkoRm ShTA9yAKIa8dFjIQmCbJG7Kv3N2PiIU= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-576-zslUpdpYNp6S1clsL_W_IQ-1; Wed, 24 May 2023 10:49:39 -0400 X-MC-Unique: zslUpdpYNp6S1clsL_W_IQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C44043800E80; Wed, 24 May 2023 14:49:38 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.39.192.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id A8A32C1ED99; Wed, 24 May 2023 14:49:36 +0000 (UTC) From: David Howells To: netdev@vger.kernel.org Cc: David Howells , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , David Ahern , Matthew Wilcox , Jens Axboe , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Tom Herbert , Tom Herbert Subject: [PATCH net-next 4/4] kcm: Convert kcm_sendpage() to use MSG_SPLICE_PAGES Date: Wed, 24 May 2023 15:49:23 +0100 Message-Id: <20230524144923.3623536-5-dhowells@redhat.com> In-Reply-To: <20230524144923.3623536-1-dhowells@redhat.com> References: <20230524144923.3623536-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Rspamd-Queue-Id: D3408A000B X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 3audsu6z8ptrhqamdwcyqhwczbyagtts X-HE-Tag: 1684939783-861043 X-HE-Meta: U2FsdGVkX1/BCI4M8X/rq5Aw+RF9RCxL4Nj3BnevbsiXxJ3dcOoIOOkKxHexSbeZedwGL+y7u8XWCFoR154tOonKILZolqUMV5GEiOs8d70Ce3fz7aVsj2gkNQyb7Kgp9tYhsRGqqwJ2/CyxZ0VWOeKaM/qP1w/mN4KwEvxB3QQHS45/gJswIl9S+fWa79X0rMRC7h66rcLwEUucD5Ia826tu84GUwf8HC2bFWGyWNb5sh10D/EGK92nAJrMJySJdxARKWLndOkHXCrAeGb6pSGbxVH68Svcx38BxoL4xn7JCvNqnYA6jKffOaInuGcdSSpZWrDhSCOMGq3ufb9ExHO6KMDcWkbB0Nj3K0jq2HGeu7TYoa9JlxBqFQmjZLNJr72NF1Yw/6vP2wwWOr36MCWO9L60uM5vbPQEmvsuTddzsk/3Zh7wIFD/f5ctMIAFC9VaqdMdIqdeJg0APVHRhPf1GuZ2kkYtTdXxMWmafWeJtO2ZD7BOIxUrAqeX+S9XgOisVWsAvfy6kCoGgQmMP8smhXXc2seFUpEhibTfxwISgsgxbre7wpWajcTahydPrA8kMDk4Rx9DOyd8wl+vAO3BW+ayBTBTYW9WnjFPEzkqLg2+0KKC2np1GMDXfV0WSDA+03t9HLvagFHqxQukbNZmBJCVOgZYRMIP0YvTXLqwbq5CZuNB+PIfciydypG3z2BNTitlJG+o/ea/PAQChv7SV7Bxu5asuKJFivTiWFXj5qmTFM6R1vVRYDpy31Uwfrp2+tLLm3Lh56SawOfGLe5T2C5EzfJT/DLY3I2srPihsEmagqV4jg0DgIvubE97/mtGn1IdusEgm+MUuRm26T0Jgn8O+V2/5W5d0x+LuKpAvxlMzIulC8FuLennoJcirOKF/kYvAldnVTk1PKlqY2mcbTlsUWWPYz+xgtnffDy82V+eD9ZriDHaU5P2srhrLFwNKv5pp91igASvqf9 gkrnx1Ch 8BVsSfbO3Rkr4Xl2xukWeM0wbtvC1l3mfVcW7Zf9cHe3QYa+wVKDUCkYEsbT4Z5RkN9WrFdPMUS67ceuEu2FFvdj3uoGwNc1+4RQ1eIJmRV8e2JcZE+78Pml3IDcDmNunYPpcmYV5l8pUhQBG/zmcKOr6K6k8Rxb2NdlYeqzRuO/t9x4N3gSSPjQk1OO5F6wyDsShHsSwMXE4Axt3z3vPNW5Zk1d2API8jXp0B55q92LXSFlv7QK8+YBA65g4ljNxV8D9dnfNhhsNJ/DLEzPfwNdoop5d42ssHKqekTvJ+kUaEFTsCKs7jVoCHmyy2i9ujt9LHC7sfPAqUDneTAolkiooGV7/g0zIjo0nFWL+fXc1wER3Wyv7xyCOng+dCYzRfxITfzrdTAVhnEvX4McWQHeBaKYvxwPCzJR42skIwMkm2qbBh/PTj3DEtt1BCRQq3SeQxJaqEKSixuha4Ah2vwI/JlS3yEosoFX9hXBbuahdHMPl3uDdaJkSQfzxepsT0GQaPGMiLEtdWx3YyY2eKOEW8CjeZU73Q7QefImQdB89t4SG06jhpGgaHcZwZjqereVhl+ILF3ZUh8YbbbKI3u3h8XRnPKQ5HW5cvtLuT+pJ+A8= 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: Convert kcm_sendpage() to use sendmsg() with MSG_SPLICE_PAGES rather than directly splicing in the pages itself. This allows ->sendpage() to be replaced by something that can handle multiple multipage folios in a single transaction. Signed-off-by: David Howells cc: Tom Herbert cc: Tom Herbert cc: Jakub Kicinski cc: Eric Dumazet cc: "David S. Miller" cc: Paolo Abeni cc: Jens Axboe cc: Matthew Wilcox cc: netdev@vger.kernel.org --- net/kcm/kcmsock.c | 161 ++++++---------------------------------------- 1 file changed, 18 insertions(+), 143 deletions(-) diff --git a/net/kcm/kcmsock.c b/net/kcm/kcmsock.c index 411726d830c0..f6e0e017e3cc 100644 --- a/net/kcm/kcmsock.c +++ b/net/kcm/kcmsock.c @@ -761,149 +761,6 @@ static void kcm_push(struct kcm_sock *kcm) kcm_write_msgs(kcm); } -static ssize_t kcm_sendpage(struct socket *sock, struct page *page, - int offset, size_t size, int flags) - -{ - struct sock *sk = sock->sk; - struct kcm_sock *kcm = kcm_sk(sk); - struct sk_buff *skb = NULL, *head = NULL; - long timeo = sock_sndtimeo(sk, flags & MSG_DONTWAIT); - bool eor; - int err = 0; - int i; - - if (flags & MSG_SENDPAGE_NOTLAST) - flags |= MSG_MORE; - - /* No MSG_EOR from splice, only look at MSG_MORE */ - eor = !(flags & MSG_MORE); - - lock_sock(sk); - - sk_clear_bit(SOCKWQ_ASYNC_NOSPACE, sk); - - err = -EPIPE; - if (sk->sk_err) - goto out_error; - - if (kcm->seq_skb) { - /* Previously opened message */ - head = kcm->seq_skb; - skb = kcm_tx_msg(head)->last_skb; - i = skb_shinfo(skb)->nr_frags; - - if (skb_can_coalesce(skb, i, page, offset)) { - skb_frag_size_add(&skb_shinfo(skb)->frags[i - 1], size); - skb_shinfo(skb)->flags |= SKBFL_SHARED_FRAG; - goto coalesced; - } - - if (i >= MAX_SKB_FRAGS) { - struct sk_buff *tskb; - - tskb = alloc_skb(0, sk->sk_allocation); - while (!tskb) { - kcm_push(kcm); - err = sk_stream_wait_memory(sk, &timeo); - if (err) - goto out_error; - } - - if (head == skb) - skb_shinfo(head)->frag_list = tskb; - else - skb->next = tskb; - - skb = tskb; - skb->ip_summed = CHECKSUM_UNNECESSARY; - i = 0; - } - } else { - /* Call the sk_stream functions to manage the sndbuf mem. */ - if (!sk_stream_memory_free(sk)) { - kcm_push(kcm); - set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); - err = sk_stream_wait_memory(sk, &timeo); - if (err) - goto out_error; - } - - head = alloc_skb(0, sk->sk_allocation); - while (!head) { - kcm_push(kcm); - err = sk_stream_wait_memory(sk, &timeo); - if (err) - goto out_error; - } - - skb = head; - i = 0; - } - - get_page(page); - skb_fill_page_desc_noacc(skb, i, page, offset, size); - skb_shinfo(skb)->flags |= SKBFL_SHARED_FRAG; - -coalesced: - skb->len += size; - skb->data_len += size; - skb->truesize += size; - sk->sk_wmem_queued += size; - sk_mem_charge(sk, size); - - if (head != skb) { - head->len += size; - head->data_len += size; - head->truesize += size; - } - - if (eor) { - bool not_busy = skb_queue_empty(&sk->sk_write_queue); - - /* Message complete, queue it on send buffer */ - __skb_queue_tail(&sk->sk_write_queue, head); - kcm->seq_skb = NULL; - KCM_STATS_INCR(kcm->stats.tx_msgs); - - if (flags & MSG_BATCH) { - kcm->tx_wait_more = true; - } else if (kcm->tx_wait_more || not_busy) { - err = kcm_write_msgs(kcm); - if (err < 0) { - /* We got a hard error in write_msgs but have - * already queued this message. Report an error - * in the socket, but don't affect return value - * from sendmsg - */ - pr_warn("KCM: Hard failure on kcm_write_msgs\n"); - report_csk_error(&kcm->sk, -err); - } - } - } else { - /* Message not complete, save state */ - kcm->seq_skb = head; - kcm_tx_msg(head)->last_skb = skb; - } - - KCM_STATS_ADD(kcm->stats.tx_bytes, size); - - release_sock(sk); - return size; - -out_error: - kcm_push(kcm); - - err = sk_stream_error(sk, flags, err); - - /* make sure we wake any epoll edge trigger waiter */ - if (unlikely(skb_queue_len(&sk->sk_write_queue) == 0 && err == -EAGAIN)) - sk->sk_write_space(sk); - - release_sock(sk); - return err; -} - static int kcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) { struct sock *sk = sock->sk; @@ -1109,6 +966,24 @@ static int kcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) return err; } +static ssize_t kcm_sendpage(struct socket *sock, struct page *page, + int offset, size_t size, int flags) + +{ + struct bio_vec bvec; + struct msghdr msg = { .msg_flags = flags | MSG_SPLICE_PAGES, }; + + if (flags & MSG_SENDPAGE_NOTLAST) + msg.msg_flags |= MSG_MORE; + + if (flags & MSG_OOB) + return -EOPNOTSUPP; + + bvec_set_page(&bvec, page, size, offset); + iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, &bvec, 1, size); + return kcm_sendmsg(sock, &msg, size); +} + static int kcm_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, int flags) {