Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp6697487iob; Wed, 11 May 2022 03:28:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyWTMO0M9m6YCO3EbNVdT4wUFwaimCqihcqSOpTMzaE+AEIjn069mizdziI8KQtbGuJREyU X-Received: by 2002:a05:6402:1913:b0:427:ba16:179d with SMTP id e19-20020a056402191300b00427ba16179dmr27734153edz.174.1652264901538; Wed, 11 May 2022 03:28:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652264901; cv=none; d=google.com; s=arc-20160816; b=aFTE/T/qdfJvN1BCDsYefZcLTBEBl8sgdJzq8iRLZDwasFznL0JcJo4DmVpgzXMCLL eMsiXGzDzUpZRnHBJJ3yGEGPaZEtqbLtj7VWgd6UfGTadNlijFJ5y4wJCr9b4Pa9dkNd jqfvZojDxqoe/XVSfhKtPF0VCj4BfCcQSs7f/Ewrb82gPjkXjgFmTw4OcRusgPVXxJfY +O88RYjDpX+Ku+7w8pbpnI0V5NbrRrx6ecVL4wdmTstcRm6vXcEys2Q6p4ODG6IbuPR5 qmHBmeKi82/Inrhnx9hCA8xq5rwGkS8LupBtT/hYQUJKJyKNT3GFKczEaYxVvTtEqFgl nwMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=8Oj5fYgOyP9r6j4Oo2YFgfJ89J2j62xWeof0Jo9AY3w=; b=vHaf9Iohgc2TBAuPCqflf1aUsePlN8zF5/8Aot5WtBqDQcR+/bAaYxj6yRkE7vKVD3 kyqYnE3S4xcF6zo2vOJgckdchbAtmoyxQlV/awz2BAbhde66BHbTmc5UczYUjJyGCbuN 4EOrUnZzF6B6di3iODvkFPQWfQx3mMX83yppNl5ti/I8xydEpCRpqPB7DUWB+6b3+rBQ 3bZP4lmJd61TVMveZH0Q7oZ4Z6dfRyE5SEdxNmn1M6wtrEPWXPyCdB1JSoNzwFZp1oeW bMxTQ0Wjv1IWk/3rhQAxjJOLtHf0yWfjM5p65AYdGWDYTfI35HWHHgq5nTCW8DulgloB VqMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fastly.com header.s=google header.b=v9w+8OSo; 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=REJECT sp=REJECT dis=NONE) header.from=fastly.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id go44-20020a1709070dac00b006e878a53334si2429919ejc.363.2022.05.11.03.27.55; Wed, 11 May 2022 03:28:21 -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=@fastly.com header.s=google header.b=v9w+8OSo; 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=REJECT sp=REJECT dis=NONE) header.from=fastly.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241955AbiEKDz5 (ORCPT + 99 others); Tue, 10 May 2022 23:55:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241882AbiEKDzp (ORCPT ); Tue, 10 May 2022 23:55:45 -0400 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 126CD4CD55 for ; Tue, 10 May 2022 20:55:39 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id q4so653297plr.11 for ; Tue, 10 May 2022 20:55:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8Oj5fYgOyP9r6j4Oo2YFgfJ89J2j62xWeof0Jo9AY3w=; b=v9w+8OSo8NSVmDmBQbc8obXr4Wi1nhD7MIDl5mmowMNt72/kNMxqluqzW8jS3Kp7UB /7VISt6MIJKtVD9o0A7m6LzNO5Lqp9ow+x5B9kBGB7t7PtEZGsvXfcXksfmbNr4z51g2 LTzKHBx8TvH8VwSw5qQxFSvqLW2aYGDGcyTCY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=8Oj5fYgOyP9r6j4Oo2YFgfJ89J2j62xWeof0Jo9AY3w=; b=gKBNlz3W4ErVwNaV1LBEXKfjk7dCw+kncT24w8YgNAZMfksrnNqLEjZ6DORKeShwBx igHWdzB+GyTeyq3If4B9nthhjFGz8ia39GQvuynsCyFmOB9gp3L+uiMaSzYYUSlW8oNe H1Rqca0uRaQ2eWCKttcrrSujNy+gCXXgCUGHNDbTJLWfZAU5v82Y62LRfoDRJqhd4nFo 3vDgYJDJzsdOpgMYNeYUIMsu0MHBFmFAFhZViA+r7rxNqjYZnIvVCg532GpOiVWa2DxX nU5IgyQI5uhCqMmqqLNTJ/BP2zVE4v1ft5xeW4ZFm4wyw5SiwP8MbrrJNbakXW81IorF 1rSA== X-Gm-Message-State: AOAM531dBxzYBmWuyzNcoVP/2nYXsVki2W4LEXf29DifWLr2XuKxWIpJ VCYA9InzH8te8LaODbwvlJAJLA== X-Received: by 2002:a17:902:8644:b0:153:9f01:2090 with SMTP id y4-20020a170902864400b001539f012090mr22917397plt.101.1652241338601; Tue, 10 May 2022 20:55:38 -0700 (PDT) Received: from localhost.localdomain (c-73-223-190-181.hsd1.ca.comcast.net. [73.223.190.181]) by smtp.gmail.com with ESMTPSA id d7-20020a170903230700b0015e8d4eb1f7sm442789plh.65.2022.05.10.20.55.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 May 2022 20:55:38 -0700 (PDT) From: Joe Damato To: netdev@vger.kernel.org, davem@davemloft.net, kuba@kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org, Eric Dumazet , Paolo Abeni Cc: Joe Damato Subject: [RFC,net-next 6/6] net: unix: Add MSG_NTCOPY Date: Tue, 10 May 2022 20:54:27 -0700 Message-Id: <1652241268-46732-7-git-send-email-jdamato@fastly.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1652241268-46732-1-git-send-email-jdamato@fastly.com> References: <1652241268-46732-1-git-send-email-jdamato@fastly.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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: X-Mailing-List: linux-kernel@vger.kernel.org Add a new sendmsg flag, MSG_NTCOPY, which user programs can use to signal to the kernel that data copied into the kernel during sendmsg should be done so using nontemporal copies, if it is supported by the architecture. Signed-off-by: Joe Damato --- include/linux/socket.h | 1 + net/unix/af_unix.c | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/include/linux/socket.h b/include/linux/socket.h index 12085c9..c9b10aa 100644 --- a/include/linux/socket.h +++ b/include/linux/socket.h @@ -318,6 +318,7 @@ struct ucred { * plain text and require encryption */ +#define MSG_NTCOPY 0x2000000 /* Use a non-temporal copy */ #define MSG_ZEROCOPY 0x4000000 /* Use user data in kernel path */ #define MSG_FASTOPEN 0x20000000 /* Send data in TCP SYN */ #define MSG_CMSG_CLOEXEC 0x40000000 /* Set close_on_exec for file diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index e1dd9e9..ccbd643 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -1907,7 +1907,11 @@ static int unix_dgram_sendmsg(struct socket *sock, struct msghdr *msg, skb_put(skb, len - data_len); skb->data_len = data_len; skb->len = len; - err = skb_copy_datagram_from_iter(skb, 0, &msg->msg_iter, len); + if (msg->msg_flags & MSG_NTCOPY) + err = skb_copy_datagram_from_iter_nocache(skb, 0, &msg->msg_iter, len); + else + err = skb_copy_datagram_from_iter(skb, 0, &msg->msg_iter, len); + if (err) goto out_free; @@ -2167,7 +2171,12 @@ static int unix_stream_sendmsg(struct socket *sock, struct msghdr *msg, skb_put(skb, size - data_len); skb->data_len = data_len; skb->len = size; - err = skb_copy_datagram_from_iter(skb, 0, &msg->msg_iter, size); + + if (msg->msg_flags & MSG_NTCOPY) + err = skb_copy_datagram_from_iter_nocache(skb, 0, &msg->msg_iter, size); + else + err = skb_copy_datagram_from_iter(skb, 0, &msg->msg_iter, size); + if (err) { kfree_skb(skb); goto out_err; -- 2.7.4