From patchwork Wed May 31 11:04: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: 13261974 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 B7C48C77B7A for ; Wed, 31 May 2023 11:04:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 288A28E0006; Wed, 31 May 2023 07:04:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 238BA8E0001; Wed, 31 May 2023 07:04:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1024B8E0006; Wed, 31 May 2023 07:04:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 0205F8E0001 for ; Wed, 31 May 2023 07:04:40 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id C8DABADDD8 for ; Wed, 31 May 2023 11:04:39 +0000 (UTC) X-FDA: 80850267078.23.B4F636B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf16.hostedemail.com (Postfix) with ESMTP id 23127180013 for ; Wed, 31 May 2023 11:04:37 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YfMSWwiw; spf=pass (imf16.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685531078; a=rsa-sha256; cv=none; b=EQTQqXffLa5oVRSE0x/spb0VdLk/iq+4mBTt8XYBluhx9/jnD3GpxPs460VkcvghfRY9D5 01wlGxneMBda4Cp6fTPQ6CQo/n02Z7WvHyZRif9Fzysz+obbtB5LVS2jx+9G0nCDYOc1f4 se+wNtT3gLsfO3GAGF1MSQROZZUVeT8= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YfMSWwiw; spf=pass (imf16.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685531078; 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=oo2uxP/MzmHd10a5KbN5Oq58DgcC9fhPDz9XsE6LWiI=; b=z/d5Iimw1aPnotdrrjA3S6YImJkXjy9T4cUzhp0rPmMfNTfzM2CeZbVwhYmiYKiyugL6SA yQaTFfBoEN9uynEk47sDQFqu2V4TT7NJbepJ/jqT0UXFyJAfX9p9ZS1vDYknwpFNN0s5OJ GD36nup44U0DGTdkT5rzlFLybeegjI4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685531077; 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=oo2uxP/MzmHd10a5KbN5Oq58DgcC9fhPDz9XsE6LWiI=; b=YfMSWwiwQxidFtx4JlBej38Xwjc4BZ+2VRpNT+rsxzEhgrUMNBZvgWCBVgt/ACt3iB0as8 Q7rITR1UvvbxPoMCHGwYbO7JmwHA39UlNidaFdszU6dsWnHHhgIFWEMW6x0LLTUwW1i4JP txpv2UBL/G0V3qIDdf6PyCFCPzAa01o= 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-210-5MnFPOU1Pei6bNTHzvR1rw-1; Wed, 31 May 2023 07:04:32 -0400 X-MC-Unique: 5MnFPOU1Pei6bNTHzvR1rw-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 015F4185A78B; Wed, 31 May 2023 11:04:32 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id 48C7A112132D; Wed, 31 May 2023 11:04:29 +0000 (UTC) From: David Howells To: netdev@vger.kernel.org Cc: David Howells , Tom Herbert , Tom Herbert , Cong Wang , "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 Subject: [PATCH net-next v2 1/2] kcm: Support MSG_SPLICE_PAGES Date: Wed, 31 May 2023 12:04:21 +0100 Message-ID: <20230531110423.643196-2-dhowells@redhat.com> In-Reply-To: <20230531110423.643196-1-dhowells@redhat.com> References: <20230531110423.643196-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 23127180013 X-Stat-Signature: gq3scne3h4qknoqtma755rix6cs5a8jr X-Rspam-User: X-HE-Tag: 1685531077-46262 X-HE-Meta: U2FsdGVkX18p5f/QVIo3tDvc7MahcfohL3hUy/PMOg6IABxJyKJS0g3QVWcKLkGzOq/xG8fAR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Xmb3BDdO2xX5I3boAI+9XbwucatDpOrIGXJRi3EugW0h93vaZ0fsHgwSq+2mbaZcq5dTYAiFBqhJtaFWTbTe5YGFWUVkKey3+ZgYGRJSTcvs+N3QtNZBkpVFZrJk4o37V/UjgEkNhc8j0XmuRaOJ7u82BDct4GhISqkphqbGVQKw9J1NDw/c0OrCHE5RRMU5qytRaLbecBJNQy4mHbcBlMqI26oxmQGNpVyZEm0xaxCfY4a3GELkAFY3kLmWuFwamJsWmO4hv4QO1JFG35jDRRuvXHPgmdVU5NVJw3jXiZb/E07jIKvllXrMDk+mKy6WDTbRdY2or+rUPUdZuKVYjfJnW/A2pbZSkJdxXul3poosuC6aYVEqbdBjNugeMmqkRwc1aQNCOkgfzAUO9Wmnz1OqlOaNvCL1YfEHwj/RObeGUnbE8XYu7PrnQj8YtbHLAJqASqcgwLycdZLVJ19Imfe5hud4K9QXQfGeKQR3ev3yTGbOtKMCmSl4CCn0 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 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: Cong Wang cc: Jakub Kicinski cc: Eric Dumazet cc: "David S. Miller" cc: Paolo Abeni cc: Jens Axboe cc: Matthew Wilcox cc: netdev@vger.kernel.org --- Notes: ver #2) - Only account the amount actually copied. - Wrap at 80 chars. net/kcm/kcmsock.c | 57 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/net/kcm/kcmsock.c b/net/kcm/kcmsock.c index cfe828bd7fc6..8555ede66333 100644 --- a/net/kcm/kcmsock.c +++ b/net/kcm/kcmsock.c @@ -989,29 +989,52 @@ 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; + copy = err; + 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 31 11:04: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: 13261975 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 B3741C77B7A for ; Wed, 31 May 2023 11:04:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4D28D8E0007; Wed, 31 May 2023 07:04:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 483398E0001; Wed, 31 May 2023 07:04:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 34ABB8E0007; Wed, 31 May 2023 07:04:44 -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 2657E8E0001 for ; Wed, 31 May 2023 07:04:44 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id EF4181A0228 for ; Wed, 31 May 2023 11:04:43 +0000 (UTC) X-FDA: 80850267246.20.4DB42F7 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf08.hostedemail.com (Postfix) with ESMTP id 3B9E4160008 for ; Wed, 31 May 2023 11:04:42 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=d0pO4Vje; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.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=1685531082; 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=Lspjk3nUuuzKHM/LR2nBU2AWpiVJh3beRxHXZXIuEZs=; b=zjbKDkvcHBL6MZczyFhnPYnxMzwrRoHKtn104WZJGy2RG0lBNmiR3op8vDDw+gOEV36HTc nITvwt+41qdcRVduwaIupu6zKZ6XumISKAsGLXM//RSUVqfbtpOJHiUZu5Hjvffst8COGK 4yYW7E/uKE/5k/txEnOuSK84GEingiE= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=d0pO4Vje; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.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=1685531082; a=rsa-sha256; cv=none; b=rXC6703x41ojFbRt33mXXWqudK80TzRW9qLVGIGw4v1sTV2OwijPALBVRyC1ZT2qEjNsNQ /FPPT/ZiT4AaK/2cMFStYPxBi0covpaHwmMWhqzoDwTRRiYtVHJ02CcB2+oHLAt7CFhCYw LpNwIbTFjisfSxhNzLTL3yIOgPwoZZU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685531081; 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=Lspjk3nUuuzKHM/LR2nBU2AWpiVJh3beRxHXZXIuEZs=; b=d0pO4VjeTW/iEq/su1fX/7oJTJEPboNSymEdzL2LKJHJoz9DCeZuQ9yx3/lll86eId1WeG JQVesdKCKxTkE98kK2lYLFcztVuahIapKa5wlrQyWwCLnztTYqbwZm/L4oWlJOCCaotC+w 0XJx99ZCD3YYY6Ncqh6YAxeKhxxN5BQ= 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-395-ksUvxhdGOC6sRfiW3m6cCg-1; Wed, 31 May 2023 07:04:35 -0400 X-MC-Unique: ksUvxhdGOC6sRfiW3m6cCg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9CB101019C86; Wed, 31 May 2023 11:04:34 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id C706B2166B25; Wed, 31 May 2023 11:04:32 +0000 (UTC) From: David Howells To: netdev@vger.kernel.org Cc: David Howells , Tom Herbert , Tom Herbert , Cong Wang , "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 Subject: [PATCH net-next v2 2/2] kcm: Convert kcm_sendpage() to use MSG_SPLICE_PAGES Date: Wed, 31 May 2023 12:04:22 +0100 Message-ID: <20230531110423.643196-3-dhowells@redhat.com> In-Reply-To: <20230531110423.643196-1-dhowells@redhat.com> References: <20230531110423.643196-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 3B9E4160008 X-Stat-Signature: pxex6mm59atmqkg8gu4soe17cuppqi6f X-Rspam-User: X-HE-Tag: 1685531082-163134 X-HE-Meta: U2FsdGVkX19sOiJHvgUk83wPssLf98fwuqD0XHAmUeYyiXbgYzdEH1iCRPCwCsdfCmDjT6Bjtp704sa0PrXx8H1TceaOjhMo+Y4HRmgZe9a7j5h79Sz2LAcTmR+Q+TV/8JxJZ5QMa97hE0CW2cyUE1oEoYrsovYfZvlQEtfGED85RiTlPbx9h05pLZu0DB3SAcO4mVK6Ahz6pFfXoyRLqnfbvfuoQVhPb0uNovrfM8GDBNVIsHucrRpuDRHj8/caSxLihxsHajyZKP/jxCBLMvNX3IBXDRhY0zNrWOdmawb1ZkiNZ22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2Nbu0jsH9Rp+FXcSguhdU7/sC782Mz02YN30yh/3WBgFbvEQ514tfRhQwySTuMCX608ugivg6BFcKuY369eUN7TQhaBd/X2mo5x0Abe6OenqhFiWru5kBmRdeBkZMXL4QAJKUKJeRjieGwXFZFxCF1FjMFlEdOwNWEFS9204RctRNhmG+PE9uaNj3IKQpgbC/G9b8pxdXCtCsTDdXUykDc0BY+aNqpUG5aL+hHDMwYdgAxfKVY3Eq1nO8Mr7tzHCTXhWgjvHdcPHortwQRjxUQIq7k654WX9f5mmkjoAsB 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: Cong Wang 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 8555ede66333..ba22af16b96d 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; @@ -1111,6 +968,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) {