Message ID | 20230411160902.4134381-2-dhowells@redhat.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2690184vqo; Tue, 11 Apr 2023 09:11:16 -0700 (PDT) X-Google-Smtp-Source: AKy350Y1El1WceGlDMZQfdzP3Lhrl+Dm+M+DBJoNuxZ7mWnJfJOHuJYWefljhX5dWvsAgobkJGEK X-Received: by 2002:a17:906:ae41:b0:946:c1d2:8b5d with SMTP id lf1-20020a170906ae4100b00946c1d28b5dmr11167899ejb.17.1681229475830; Tue, 11 Apr 2023 09:11:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681229475; cv=none; d=google.com; s=arc-20160816; b=ls0q7ZRMJaAwmy+P847OEJT3yWPbyYXi6GZE3RdPI8Twk4jxwf2g/X3ZfNqRQvUob7 npEF2MSuiBsvMl4D5kjCz2pW7U0IU60gRomZy8kzNxsWVPKFzaAff4StBI9/EPY3In+f gafCekxSfzlVVVlNMPP/NpXBzxFbDHGkvODtYM2AtDNDy87LeJH/55wArNxj477XrTL+ BPF4AZv7AHtvM+D5K5J+gpCQS+ocEuTlHLlrNqvuDoSgzErp1z/RBpHp433ot/eea8gi LG0fKtxU2G7MmilVA2lV3C4O8WaQ6n4rz5Tngz1BzkBk9smtku2ydnuGOnB69oyGey+m aLRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=QAACn2mr7ooi1DdUlemHLPNq4itk2LGg3Qvic6fgj7U=; b=Gpj6hBtIzqkFVTPlrvRqcK3iVZj82gFGWGSeNx0TfYtn0tWJqr0wpkByBxkofX4jIl D2k4ly7VhyawPDdtOxCbdoK7OmvtrfJQCbyOGWl809kd35XrAsTvxCv2CX3oB41rynEv xU5fKSXErUYG2tZJriJXxLfINdfmAG9b4jS1Wmh2gyMidTIEAjbMmCgPyLC75ezbb9QR EfZZ7FQLwEjwopy+f25XRHtSd5rbNVm2ws4ZARD7EOAuNY10TA1OaEiQTUtpjv/Yd86F Oc91aoptC1p65XdJNFUYagXHWVliespAHgWX9smqbHTop7/EspgaitNAMkJX/zF5O+CR jHFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gzumbgHm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gt32-20020a1709072da000b0092351b1acdcsi11808722ejc.347.2023.04.11.09.10.50; Tue, 11 Apr 2023 09:11:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gzumbgHm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229611AbjDKQKD (ORCPT <rfc822;leviz.kernel.dev@gmail.com> + 99 others); Tue, 11 Apr 2023 12:10:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229924AbjDKQKA (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 11 Apr 2023 12:10:00 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85DC5212F for <linux-kernel@vger.kernel.org>; Tue, 11 Apr 2023 09:09:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681229355; 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=QAACn2mr7ooi1DdUlemHLPNq4itk2LGg3Qvic6fgj7U=; b=gzumbgHmorf0HW5QdF0HX3KdqkgU91GBuuSQnD2Fvb3MHJkHgD+RwqjPrHIURpQYlw6P7c uxM7NF3cyTTOdrhyi3YHYzSkzDlvtdrGXOjgxJL8Axk/m7rFCZdBSZPi2EU0pisv1DVAFa HYqq+lz70KUTEf1YTHnIE9oe8mZMYXI= 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-425-m3bGLW3zMRuPyvCVdlDU1g-1; Tue, 11 Apr 2023 12:09:11 -0400 X-MC-Unique: m3bGLW3zMRuPyvCVdlDU1g-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 77C5083DE48; Tue, 11 Apr 2023 16:09:10 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4197440C20FA; Tue, 11 Apr 2023 16:09:08 +0000 (UTC) From: David Howells <dhowells@redhat.com> To: netdev@vger.kernel.org Cc: David Howells <dhowells@redhat.com>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Willem de Bruijn <willemdebruijn.kernel@gmail.com>, David Ahern <dsahern@kernel.org>, Matthew Wilcox <willy@infradead.org>, Al Viro <viro@zeniv.linux.org.uk>, Christoph Hellwig <hch@infradead.org>, Jens Axboe <axboe@kernel.dk>, Jeff Layton <jlayton@kernel.org>, Christian Brauner <brauner@kernel.org>, Chuck Lever III <chuck.lever@oracle.com>, Linus Torvalds <torvalds@linux-foundation.org>, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Willem de Bruijn <willemb@google.com> Subject: [PATCH net-next v6 01/18] net: Declare MSG_SPLICE_PAGES internal sendmsg() flag Date: Tue, 11 Apr 2023 17:08:45 +0100 Message-Id: <20230411160902.4134381-2-dhowells@redhat.com> In-Reply-To: <20230411160902.4134381-1-dhowells@redhat.com> References: <20230411160902.4134381-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762896878463774377?= X-GMAIL-MSGID: =?utf-8?q?1762896878463774377?= |
Series |
splice, net: Replace sendpage with sendmsg(MSG_SPLICE_PAGES), part 1
|
|
Commit Message
David Howells
April 11, 2023, 4:08 p.m. UTC
Declare MSG_SPLICE_PAGES, an internal sendmsg() flag, that hints to a network protocol that it should splice pages from the source iterator rather than copying the data if it can. This flag is added to a list that is cleared by sendmsg syscalls on entry. This is intended as a replacement for the ->sendpage() op, allowing a way to splice in several multipage folios in one go. Signed-off-by: David Howells <dhowells@redhat.com> Reviewed-by: Willem de Bruijn <willemb@google.com> cc: "David S. Miller" <davem@davemloft.net> cc: Eric Dumazet <edumazet@google.com> cc: Jakub Kicinski <kuba@kernel.org> cc: Paolo Abeni <pabeni@redhat.com> cc: Jens Axboe <axboe@kernel.dk> cc: Matthew Wilcox <willy@infradead.org> cc: netdev@vger.kernel.org --- include/linux/socket.h | 3 +++ net/socket.c | 2 ++ 2 files changed, 5 insertions(+)
Comments
On Tue, Apr 11, 2023 at 05:08:45PM +0100, David Howells wrote: > @@ -2483,6 +2484,7 @@ static int ____sys_sendmsg(struct socket *sock, struct msghdr *msg_sys, > } > msg_sys->msg_flags = flags; > > + flags &= ~MSG_INTERNAL_SENDMSG_FLAGS; > if (sock->file->f_flags & O_NONBLOCK) > msg_sys->msg_flags |= MSG_DONTWAIT; A bit too late, innit? There's no users of 'flags' downstream of that assignment to ->msg_flags, so your &= is a no-op; it should be done *before* that assignment...
On Thu, Apr 13, 2023 at 01:51:29AM +0100, Al Viro wrote: > On Tue, Apr 11, 2023 at 05:08:45PM +0100, David Howells wrote: > > > @@ -2483,6 +2484,7 @@ static int ____sys_sendmsg(struct socket *sock, struct msghdr *msg_sys, > > } > > msg_sys->msg_flags = flags; > > > > + flags &= ~MSG_INTERNAL_SENDMSG_FLAGS; > > if (sock->file->f_flags & O_NONBLOCK) > > msg_sys->msg_flags |= MSG_DONTWAIT; > > A bit too late, innit? There's no users of 'flags' downstream of that > assignment to ->msg_flags, so your &= is a no-op; it should be done > *before* that assignment... While we are at it, io-uring has this: int io_sendmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) { struct io_sr_msg *sr = io_kiocb_to_cmd(req, struct io_sr_msg); ... sr->msg_flags = READ_ONCE(sqe->msg_flags) | MSG_NOSIGNAL; and int io_send(struct io_kiocb *req, unsigned int issue_flags) { struct sockaddr_storage __address; struct io_sr_msg *sr = io_kiocb_to_cmd(req, struct io_sr_msg); ... flags = sr->msg_flags; if (issue_flags & IO_URING_F_NONBLOCK) flags |= MSG_DONTWAIT; if (flags & MSG_WAITALL) min_ret = iov_iter_count(&msg.msg_iter); msg.msg_flags = flags; ret = sock_sendmsg(sock, &msg); Note that io_sendmsg_prep() handles both IORING_OP_SENDMSG and IORING_OP_SEND, so this pair of functions can hit the same request. And sqe->msg_flags is not sanitized at all - it comes straight from user buffer.
Al Viro <viro@zeniv.linux.org.uk> wrote: > Note that io_sendmsg_prep() handles both IORING_OP_SENDMSG and IORING_OP_SEND, > so this pair of functions can hit the same request. And sqe->msg_flags is > not sanitized at all - it comes straight from user buffer. Assuming ____sys_sendmsg() is fixed, I think it should be sufficient to make io_send() and io_send_zc(). io_sendmsg() and io_sendmsg_zc() will go through ____sys_sendmsg(). David
On Thu, Apr 13, 2023 at 09:39:22PM +0100, David Howells wrote: > Al Viro <viro@zeniv.linux.org.uk> wrote: > > > Note that io_sendmsg_prep() handles both IORING_OP_SENDMSG and IORING_OP_SEND, > > so this pair of functions can hit the same request. And sqe->msg_flags is > > not sanitized at all - it comes straight from user buffer. > > Assuming ____sys_sendmsg() is fixed, I think it should be sufficient to make > io_send() and io_send_zc(). io_sendmsg() and io_sendmsg_zc() will go through > ____sys_sendmsg(). Sure; what I wanted to point out was that despite the name, io_sendmsg_prep() gets used not only with io_sendmsg(). io_sendmsg() does go through ____sys_sendmsg(), but io_send() goes straight to sock_sendmsg() and evades all your checks...
On Thu, Apr 13, 2023 at 09:49:18PM +0100, Al Viro wrote: > On Thu, Apr 13, 2023 at 09:39:22PM +0100, David Howells wrote: > > Al Viro <viro@zeniv.linux.org.uk> wrote: > > > > > Note that io_sendmsg_prep() handles both IORING_OP_SENDMSG and IORING_OP_SEND, > > > so this pair of functions can hit the same request. And sqe->msg_flags is > > > not sanitized at all - it comes straight from user buffer. > > > > Assuming ____sys_sendmsg() is fixed, I think it should be sufficient to make > > io_send() and io_send_zc(). io_sendmsg() and io_sendmsg_zc() will go through > > ____sys_sendmsg(). > > Sure; what I wanted to point out was that despite the name, > io_sendmsg_prep() gets used not only with io_sendmsg(). io_sendmsg() > does go through ____sys_sendmsg(), but io_send() goes straight to > sock_sendmsg() and evades all your checks... Incidentally, having ____sendmsg and ___sendmsg in the same file is more than slightly antisocial - compiler can sort it out, but there are human readers as well. We have ____sys_sendmsg ___sys_sendmsg __sys_sendmsg __sys_sendmmsg next to each other. Maze of twisty little identifiers, all alike...
diff --git a/include/linux/socket.h b/include/linux/socket.h index 13c3a237b9c9..bd1cc3238851 100644 --- a/include/linux/socket.h +++ b/include/linux/socket.h @@ -327,6 +327,7 @@ struct ucred { */ #define MSG_ZEROCOPY 0x4000000 /* Use user data in kernel path */ +#define MSG_SPLICE_PAGES 0x8000000 /* Splice the pages from the iterator in sendmsg() */ #define MSG_FASTOPEN 0x20000000 /* Send data in TCP SYN */ #define MSG_CMSG_CLOEXEC 0x40000000 /* Set close_on_exec for file descriptor received through @@ -337,6 +338,8 @@ struct ucred { #define MSG_CMSG_COMPAT 0 /* We never have 32 bit fixups */ #endif +/* Flags to be cleared on entry by sendmsg and sendmmsg syscalls */ +#define MSG_INTERNAL_SENDMSG_FLAGS (MSG_SPLICE_PAGES) /* Setsockoptions(2) level. Thanks to BSD these must match IPPROTO_xxx */ #define SOL_IP 0 diff --git a/net/socket.c b/net/socket.c index 73e493da4589..b3fd3f7f7e03 100644 --- a/net/socket.c +++ b/net/socket.c @@ -2136,6 +2136,7 @@ int __sys_sendto(int fd, void __user *buff, size_t len, unsigned int flags, msg.msg_name = (struct sockaddr *)&address; msg.msg_namelen = addr_len; } + flags &= ~MSG_INTERNAL_SENDMSG_FLAGS; if (sock->file->f_flags & O_NONBLOCK) flags |= MSG_DONTWAIT; msg.msg_flags = flags; @@ -2483,6 +2484,7 @@ static int ____sys_sendmsg(struct socket *sock, struct msghdr *msg_sys, } msg_sys->msg_flags = flags; + flags &= ~MSG_INTERNAL_SENDMSG_FLAGS; if (sock->file->f_flags & O_NONBLOCK) msg_sys->msg_flags |= MSG_DONTWAIT; /*