Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp5878774rwb; Tue, 1 Aug 2023 09:05:38 -0700 (PDT) X-Google-Smtp-Source: APBJJlGSdQHuWNG2B9xzCX366W9cRnWd7NVkC+XqtzfBkA5my4Hja9Eb7rCu5gR/Ku79LtCmz3GS X-Received: by 2002:a17:903:2449:b0:1bc:1189:17f with SMTP id l9-20020a170903244900b001bc1189017fmr6709245pls.42.1690905937980; Tue, 01 Aug 2023 09:05:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690905937; cv=none; d=google.com; s=arc-20160816; b=TyhQmHNfsGaJMWJk8WisLA07FIS3T+HxhX3kb1B/Cmegy60faBL8/hdxpeIbOTkC+3 3x1hqgQK3XHWz4ZD6AIESRege/HWtHhpBn57Grb97ReEnbvY0iw7K2WKX70tZtV1qB5L B8srTUA48qx1uJZNIJTCxEHu67yGtLF7MpllEbEJ9lHtSngnZaZKFw+kHsipohx0f+qk tvrXU7lbJYFk+pwD0fMnuuczsKe5ajj24uKRAR4aWQfG54XF3zU6yAbXhNbpoG9SCmz7 tOYsKI5Nwfn77gSBrehsGxPO1+wtjLSyRUBleArFEf6hziW6Dt/FWLcF5d3hGbQn2f1X F63Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature:dkim-filter; bh=leUECNb8m0aTy27Ms8IWUwmaM7nT+VfrQeB1YRQ7PRE=; fh=E808pAgvqCe1VD194zetEttmB6uBQZBowbix1mSo+hU=; b=N56/9cRKE+acKZeF+3AjX8RHMvFyT2OeOqoaG18RnjnsLxm3yvI3/ampFHsipLeYu2 8o4MYyAY+6fBmuvJ56EalYGPePOzuJ7Ebl7lorhHwErUoEs2lvSDviFxdKJLKRx/cj7T sQgYvce0DBZNtFU1LX9GlTsDUAWrU2I+QGchqGN/66Bfxu/ALfp5yUbSUiJiS+hOU/cG tiO+Ib2i/Q7rGEc1yXenJw42+G2N24G1dwsFG0iFrVv0lFMFNPxGpBY+7h5z4PJQpaC1 uvNTsI1J3dbWWB4SKADMwM3yCnJyS+I28NsrJr50m5nDkDwm0BEpZ4ntdzsHzSfMnr49 xnPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=UyvC5thz; 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=sberdevices.ru Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w16-20020a1709026f1000b001b88cae209esi8883105plk.250.2023.08.01.09.05.13; Tue, 01 Aug 2023 09:05:37 -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=@sberdevices.ru header.s=mail header.b=UyvC5thz; 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=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234401AbjHANmn (ORCPT + 99 others); Tue, 1 Aug 2023 09:42:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230472AbjHANmm (ORCPT ); Tue, 1 Aug 2023 09:42:42 -0400 Received: from mx1.sberdevices.ru (mx2.sberdevices.ru [45.89.224.132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A90E10DB; Tue, 1 Aug 2023 06:42:40 -0700 (PDT) Received: from p-infra-ksmg-sc-msk02 (localhost [127.0.0.1]) by mx1.sberdevices.ru (Postfix) with ESMTP id 6C225120015; Tue, 1 Aug 2023 16:42:38 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.sberdevices.ru 6C225120015 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1690897358; bh=leUECNb8m0aTy27Ms8IWUwmaM7nT+VfrQeB1YRQ7PRE=; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type:From; b=UyvC5thzyDUMbLNyNgezSMelIBa4AdyRq33D36Oz2MgRg7aZtgsruG9uNAKNxyvGp KizF7dCVBi+ANgYqRF7qLhQQ65Da6ZfW7rnz9beyjFyhMdhQoE06Q3YatpNzx9KblD 731+VtzcdyptnsKUp3UACtbZDcJtoTrHDwVP0e4KP/MLJbs9PdMC/vKkHQSz6xPcPE arGWV/hO+P2j8d4y2hkHliNA3dHIgo4TXt/GfGTzviTaQDi3Y9XYKWtewo1E8xJDxU u0VcAp14ZD+Kgp9zbeevgEiR5TuUXKU6QGdTzSBCJ3WV/mq5K7Kg1s10r9wpCS7/u3 sNk+Twy36uCeA== Received: from p-i-exch-sc-m01.sberdevices.ru (p-i-exch-sc-m01.sberdevices.ru [172.16.192.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.sberdevices.ru (Postfix) with ESMTPS; Tue, 1 Aug 2023 16:42:38 +0300 (MSK) Received: from [192.168.0.106] (100.64.160.123) by p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.30; Tue, 1 Aug 2023 16:42:34 +0300 Message-ID: <1c9f9851-2228-c92b-ce3d-6a84d44e6628@sberdevices.ru> Date: Tue, 1 Aug 2023 16:36:55 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Subject: Re: [PATCH net-next v5 4/4] vsock/virtio: MSG_ZEROCOPY flag support Content-Language: en-US To: Paolo Abeni , Stefan Hajnoczi , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , "Michael S. Tsirkin" , Jason Wang , Bobby Eshleman CC: , , , , , References: <20230730085905.3420811-1-AVKrasnov@sberdevices.ru> <20230730085905.3420811-5-AVKrasnov@sberdevices.ru> <8a7772a50a16fbbcb82fc0c5e09f9e31f3427e3d.camel@redhat.com> From: Arseniy Krasnov In-Reply-To: <8a7772a50a16fbbcb82fc0c5e09f9e31f3427e3d.camel@redhat.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [100.64.160.123] X-ClientProxiedBy: p-i-exch-sc-m02.sberdevices.ru (172.16.192.103) To p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) X-KSMG-Rule-ID: 10 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Lua-Profiles: 178796 [Jul 22 2023] X-KSMG-AntiSpam-Version: 5.9.59.0 X-KSMG-AntiSpam-Envelope-From: AVKrasnov@sberdevices.ru X-KSMG-AntiSpam-Rate: 0 X-KSMG-AntiSpam-Status: not_detected X-KSMG-AntiSpam-Method: none X-KSMG-AntiSpam-Auth: dkim=none X-KSMG-AntiSpam-Info: LuaCore: 525 525 723604743bfbdb7e16728748c3fa45e9eba05f7d, {Tracking_from_domain_doesnt_match_to}, FromAlignment: s, ApMailHostAddress: 100.64.160.123 X-MS-Exchange-Organization-SCL: -1 X-KSMG-AntiSpam-Interceptor-Info: scan successful X-KSMG-AntiPhishing: Clean X-KSMG-LinksScanning: Clean X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.0.1.6960, bases: 2023/07/23 08:49:00 #21663637 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,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 On 01.08.2023 16:34, Paolo Abeni wrote: > On Sun, 2023-07-30 at 11:59 +0300, Arseniy Krasnov wrote: >> +static int virtio_transport_fill_skb(struct sk_buff *skb, >> + struct virtio_vsock_pkt_info *info, >> + size_t len, >> + bool zcopy) >> +{ >> + if (zcopy) { >> + return __zerocopy_sg_from_iter(info->msg, NULL, skb, >> + &info->msg->msg_iter, >> + len); >> + } else { > > > No need for an else statement after 'return' > >> + void *payload; >> + int err; >> + >> + payload = skb_put(skb, len); >> + err = memcpy_from_msg(payload, info->msg, len); >> + if (err) >> + return -1; >> + >> + if (msg_data_left(info->msg)) >> + return 0; >> + > > This path does not update truesize, evem if it increases the skb len... Thanks, I'll fix it. > >> + return 0; >> + } >> +} > > [...] > >> @@ -214,6 +251,70 @@ static u16 virtio_transport_get_type(struct sock *sk) >> return VIRTIO_VSOCK_TYPE_SEQPACKET; >> } >> >> +static struct sk_buff *virtio_transport_alloc_skb(struct vsock_sock *vsk, >> + struct virtio_vsock_pkt_info *info, >> + size_t payload_len, >> + bool zcopy, >> + u32 src_cid, >> + u32 src_port, >> + u32 dst_cid, >> + u32 dst_port) >> +{ >> + struct sk_buff *skb; >> + size_t skb_len; >> + >> + skb_len = VIRTIO_VSOCK_SKB_HEADROOM; >> + >> + if (!zcopy) >> + skb_len += payload_len; >> + >> + skb = virtio_vsock_alloc_skb(skb_len, GFP_KERNEL); >> + if (!skb) >> + return NULL; >> + >> + virtio_transport_init_hdr(skb, info, src_cid, src_port, >> + dst_cid, dst_port, >> + payload_len); >> + >> + /* Set owner here, because '__zerocopy_sg_from_iter()' uses >> + * owner of skb without check to update 'sk_wmem_alloc'. >> + */ >> + if (vsk) >> + skb_set_owner_w(skb, sk_vsock(vsk)); > > ... which can lead to bad things(TM) if the skb goes trough some later > non trivial processing, due to the above skb_set_owner_w(). > > Additionally can be the following condition be true: > > vsk == NULL && (info->msg && payload_len > 0) && zcopy > > ??? No, vsk == NULL only when we reset connection, in that case both info->msg == NULL and payload_len == 0, as this is control message without any data. > > If so it looks like skb can go through __zerocopy_sg_from_iter() even > without a prior skb_set_owner_w()... > > > Cheers, > > Paolo > Thanks, Arseniy