From patchwork Wed Jul 19 00:50:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bobby Eshleman X-Patchwork-Id: 122337 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2111808vqt; Tue, 18 Jul 2023 17:53:04 -0700 (PDT) X-Google-Smtp-Source: APBJJlFp5SXX5VprvhsygJBJlEX2/YxAaK2DInR+aGB6noGDeqggl6hWWnm6kUXk/5lDcJDYzubi X-Received: by 2002:a17:90b:3689:b0:263:312:611f with SMTP id mj9-20020a17090b368900b002630312611fmr14212817pjb.3.1689727983666; Tue, 18 Jul 2023 17:53:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689727983; cv=none; d=google.com; s=arc-20160816; b=wZsVeE8pMYkuLPYdpgJitBvzgQuKQDLGV5GY+RqV1AkzKb8XTrhjBpWbGQ2tBnZAV4 UWBjj7iPDaryu0ag7+PPvLrR2RxkVIHxf1OmsGE5MJVVRZL/T3rCuKiTypdw0of7zXn1 p2hWInd2tH1aM8DAu+QefqRX6a5fYIkj9DlyzK0hUZX9rlREYaTbm3DX55gAX3w0xw+T Q8Ws0k+CIdX0GRLgvEqN3hvzduFcYNKjVeecu1IGEKjCdOMXsTNEc4E/8osXwuA1nnSY L8DZA3DvTb9fFT5hOJEocDqQ4OS3yfvRIfW+oKWQf/rVl2Bu2y8IDpEAjL8bs50VixzH W/aQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=obFj4SuWwNEDydCXYPra7zizeyW2jR3T9h3NMhd9EHc=; fh=jejeGpHkr9vVlEyvdVBCSLFut92eNP6vAI+O1tx9vp4=; b=OGXxt3txtrTyre/QwvIMFZ7zVoje/rF18YH8cRjzUQTP/uaVBRdHns4qBqDLK1MMaw NsMC7lSBNO9MKeCCzHyAdz0qWO99lac6PQ369gQg2tL2yWYV2xTEyw3VAuOIdSF6kS0f +9mrT4/CU9JqMrJr8Sn9101cwSv7oQx6Xcetv3oca5MU2h3O1lxc/WEhHvQ26x2t0Ir5 dd1myQTbBwWIU2NToxDGBI+CzhMxsgYykY7UmNEL6lQiHIEVz99c3xq7tw4iF5yPZgoZ G+qFZREfpZeL/VT7Fu4yQrAaweCTDo0bgFjS8mgpKo/GqOvcagFBwCj8e41zwTngUr8p PfCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=NUyO+OfS; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 82-20020a630155000000b0055c8f4a56d5si2343609pgb.600.2023.07.18.17.52.50; Tue, 18 Jul 2023 17:53:03 -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=@bytedance.com header.s=google header.b=NUyO+OfS; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230259AbjGSAvS (ORCPT + 99 others); Tue, 18 Jul 2023 20:51:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229823AbjGSAvA (ORCPT ); Tue, 18 Jul 2023 20:51:00 -0400 Received: from mail-qk1-x72f.google.com (mail-qk1-x72f.google.com [IPv6:2607:f8b0:4864:20::72f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C66B19AD for ; Tue, 18 Jul 2023 17:50:16 -0700 (PDT) Received: by mail-qk1-x72f.google.com with SMTP id af79cd13be357-7679ea01e16so574801485a.2 for ; Tue, 18 Jul 2023 17:50:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1689727815; x=1692319815; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=obFj4SuWwNEDydCXYPra7zizeyW2jR3T9h3NMhd9EHc=; b=NUyO+OfSBwygJujqqAlusnhc8WL36GpDGlOSMNLrUMALVwy9C+eLf/gmADp5e2Cvdl RoxYMjnlm9to1SPFtrXu1eRiaDKIaHRn7U5Gw43KRFon2ohnUGIbnHrzI+y6hPywKwij PiwDJMc0PYE43Lp01hG48NJP7F9ojPjgzzPHD3GdMUhU4sCPOclubU6J2xW3pyzue4rk 7dMq/WYhfHxufcyjzThwQER4VlREp4hqAwyKaHW090tW2j8ZZ0/TwaXZNxzIJ7uHUpR8 wDT/venpG53iqv+C/PcE08F+s25Nk5YqUK+0bFTbp2Zw7AX18c2/2bHEiJ+3+x2r4T3m iRbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689727815; x=1692319815; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=obFj4SuWwNEDydCXYPra7zizeyW2jR3T9h3NMhd9EHc=; b=bOspej9igf1ltNkKUkZL0yGWuvYmyoRr01JOFhOAs5vwi0eZfKOqzYJoESRzAzfoae 28OAIn41lvNTxPVk6pJ1yL4n21yWsNTdqe0xHeZwsoKrry441N7SJm+R2+H/qtwe0qkh rd/XwLbeKzZxER/Kz++Ed41h5LEtbR6p76qa7d4pUZWLCq5fxr7nqGE8KgAKCguYjLYu k/189w+Be86P5zjQ2jZiMFgSJbjhCcEVdSI4cOn8bk8bD8xZS3rQmhsAVhz8wdwWAlLe JEKJH6pMRD8zUdcNCIQNPjk9+2kczqvyEw5Ag/89tdk1QeasW95w+Qp2DoTe/oGwRaCE q30w== X-Gm-Message-State: ABy/qLYe5UTmz2LJlRbZ/P+7BKnx80E6lGyF5QCn2WDZLrzPMq3ez8cK QfJNYwhF/HA5ORykahk46fbLng== X-Received: by 2002:a05:620a:2686:b0:767:32cd:5fe8 with SMTP id c6-20020a05620a268600b0076732cd5fe8mr19266292qkp.14.1689727815276; Tue, 18 Jul 2023 17:50:15 -0700 (PDT) Received: from [172.17.0.7] ([130.44.212.112]) by smtp.gmail.com with ESMTPSA id c5-20020a05620a11a500b0076738337cd1sm968696qkk.1.2023.07.18.17.50.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jul 2023 17:50:14 -0700 (PDT) From: Bobby Eshleman Date: Wed, 19 Jul 2023 00:50:11 +0000 Subject: [PATCH RFC net-next v5 07/14] virtio/vsock: add common datagram send path MIME-Version: 1.0 Message-Id: <20230413-b4-vsock-dgram-v5-7-581bd37fdb26@bytedance.com> References: <20230413-b4-vsock-dgram-v5-0-581bd37fdb26@bytedance.com> In-Reply-To: <20230413-b4-vsock-dgram-v5-0-581bd37fdb26@bytedance.com> To: Stefan Hajnoczi , Stefano Garzarella , "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Bryan Tan , Vishnu Dasa , VMware PV-Drivers Reviewers Cc: Dan Carpenter , Simon Horman , Krasnov Arseniy , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, bpf@vger.kernel.org, Bobby Eshleman X-Mailer: b4 0.12.2 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_PASS,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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771808210191710657 X-GMAIL-MSGID: 1771808210191710657 This commit implements the common function virtio_transport_dgram_enqueue for enqueueing datagrams. It does not add usage in either vhost or virtio yet. Signed-off-by: Bobby Eshleman --- net/vmw_vsock/virtio_transport_common.c | 76 ++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c index ffcbdd77feaa..3bfaff758433 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -819,7 +819,81 @@ virtio_transport_dgram_enqueue(struct vsock_sock *vsk, struct msghdr *msg, size_t dgram_len) { - return -EOPNOTSUPP; + /* Here we are only using the info struct to retain style uniformity + * and to ease future refactoring and merging. + */ + struct virtio_vsock_pkt_info info_stack = { + .op = VIRTIO_VSOCK_OP_RW, + .msg = msg, + .vsk = vsk, + .type = VIRTIO_VSOCK_TYPE_DGRAM, + }; + const struct virtio_transport *t_ops; + struct virtio_vsock_pkt_info *info; + struct sock *sk = sk_vsock(vsk); + struct virtio_vsock_hdr *hdr; + u32 src_cid, src_port; + struct sk_buff *skb; + void *payload; + int noblock; + int err; + + info = &info_stack; + + if (dgram_len > VIRTIO_VSOCK_MAX_PKT_BUF_SIZE) + return -EMSGSIZE; + + t_ops = virtio_transport_get_ops(vsk); + if (unlikely(!t_ops)) + return -EFAULT; + + /* Unlike some of our other sending functions, this function is not + * intended for use without a msghdr. + */ + if (WARN_ONCE(!msg, "vsock dgram bug: no msghdr found for dgram enqueue\n")) + return -EFAULT; + + noblock = msg->msg_flags & MSG_DONTWAIT; + + /* Use sock_alloc_send_skb to throttle by sk_sndbuf. This helps avoid + * triggering the OOM. + */ + skb = sock_alloc_send_skb(sk, dgram_len + VIRTIO_VSOCK_SKB_HEADROOM, + noblock, &err); + if (!skb) + return err; + + skb_reserve(skb, VIRTIO_VSOCK_SKB_HEADROOM); + + src_cid = t_ops->transport.get_local_cid(); + src_port = vsk->local_addr.svm_port; + + hdr = virtio_vsock_hdr(skb); + hdr->type = cpu_to_le16(info->type); + hdr->op = cpu_to_le16(info->op); + hdr->src_cid = cpu_to_le64(src_cid); + hdr->dst_cid = cpu_to_le64(remote_addr->svm_cid); + hdr->src_port = cpu_to_le32(src_port); + hdr->dst_port = cpu_to_le32(remote_addr->svm_port); + hdr->flags = cpu_to_le32(info->flags); + hdr->len = cpu_to_le32(dgram_len); + + skb_set_owner_w(skb, sk); + + payload = skb_put(skb, dgram_len); + err = memcpy_from_msg(payload, msg, dgram_len); + if (err) + return err; + + trace_virtio_transport_alloc_pkt(src_cid, src_port, + remote_addr->svm_cid, + remote_addr->svm_port, + dgram_len, + info->type, + info->op, + 0); + + return t_ops->send_pkt(skb); } EXPORT_SYMBOL_GPL(virtio_transport_dgram_enqueue);