Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp712537rwb; Sun, 6 Nov 2022 12:31:46 -0800 (PST) X-Google-Smtp-Source: AMsMyM6edOMKTtsbGg+ixk/u8TRVEUbMa02YVdcu3Dz5ZDRM+y4P1tK63htsLkaQ8960D1x3Voyb X-Received: by 2002:a17:907:80d:b0:73d:1e3f:3d83 with SMTP id wv13-20020a170907080d00b0073d1e3f3d83mr43156694ejb.372.1667766706009; Sun, 06 Nov 2022 12:31:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667766706; cv=none; d=google.com; s=arc-20160816; b=AU3XKRpffWZ7xAswspGyPoxC2lL92Z8wH6ysp4G5VqNreaZZv9mg2pH7vna9qA6y/K o1qnYdp52oMsldjabkVdevYHSUSVA6eVo6ZjU6eVI0t8no0KXaFR769t9ur/6WTBnzTp Fi2/3RmxdPE2CvB8WCxhKo3TRRu6iwwVgcTE3Uk/uCDSGivwVNIVGwwJz/R0EXwPyBaP NDSuuaytNiS9emz/xuNYe/qYh24j43HO+KsxSfd/PtX0z1TLQlOElEVTxKzQYIVQqTdZ J8wWi9ZUPbWUBacUIxcR4zJAVRWzlb4k/VlxScSiBX1zfrXY+c6ifK1cuu0c6LFYqFy5 0huQ== 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; bh=KqWEU9jx2Er/g4IS4K24x8en8DYOyhQzCxs9CmK0XW4=; b=BbDt0BY29s8oagqq9ycZC0L+UX0uErcx50h+XjflsnRe+KXSVSX08p8mL7u1Yo72sk GwmqMt6k3lXC7Drc9YxqVXfk9cFdHrR1ys8EHeMrdhMxOfA95MiVzcD3SG5BfqPH96Ku PKX2ftVbbmVw7eMnqypa+2kgG4F8vDKezuXmUpKOoCDmRJAy0RBVZbI7FVyKSSJAqKZG 3p65NvwaHFt8RiwdSbkig14bRpBOo+eAGrc+UVLZDzYTuKFmwHDxZQo3qb5HjKPw+k1+ 9oWzteDYXmxk1lSF99RTRrB576xJJDw2RdYMXOpU1n5D4eb0INp2SEWkmgXCZV3DHHIq mzlA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k25-20020a17090627d900b00781d302d5e9si5300757ejc.166.2022.11.06.12.31.23; Sun, 06 Nov 2022 12:31:45 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230269AbiKFTut (ORCPT + 95 others); Sun, 6 Nov 2022 14:50:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230260AbiKFTus (ORCPT ); Sun, 6 Nov 2022 14:50:48 -0500 Received: from smtp.smtpout.orange.fr (smtp-21.smtpout.orange.fr [80.12.242.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AFFB11144 for ; Sun, 6 Nov 2022 11:50:46 -0800 (PST) Received: from [192.168.1.18] ([86.243.100.34]) by smtp.orange.fr with ESMTPA id rlfGomASfTyourlfGoj7AS; Sun, 06 Nov 2022 20:50:45 +0100 X-ME-Helo: [192.168.1.18] X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sun, 06 Nov 2022 20:50:45 +0100 X-ME-IP: 86.243.100.34 Message-ID: <3c6de80a-8fc1-0c63-6d2d-3eee294fe0a7@wanadoo.fr> Date: Sun, 6 Nov 2022 20:50:42 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: [RFC PATCH v3 01/11] virtio/vsock: rework packet allocation logic Content-Language: fr To: Arseniy Krasnov , Stefano Garzarella , Stefan Hajnoczi , "Michael S. Tsirkin" , Jason Wang , "David S. Miller" , "edumazet@google.com" , Jakub Kicinski , Paolo Abeni , Krasnov Arseniy Cc: "linux-kernel@vger.kernel.org" , "kvm@vger.kernel.org" , "virtualization@lists.linux-foundation.org" , "netdev@vger.kernel.org" , kernel References: From: Christophe JAILLET In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS 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 Le 06/11/2022 à 20:36, Arseniy Krasnov a écrit : > To support zerocopy receive, packet's buffer allocation is changed: for > buffers which could be mapped to user's vma we can't use 'kmalloc()'(as > kernel restricts to map slab pages to user's vma) and raw buddy > allocator now called. But, for tx packets(such packets won't be mapped > to user), previous 'kmalloc()' way is used, but with special flag in > packet's structure which allows to distinguish between 'kmalloc()' and > raw pages buffers. > > Signed-off-by: Arseniy Krasnov > --- > drivers/vhost/vsock.c | 1 + > include/linux/virtio_vsock.h | 1 + > net/vmw_vsock/virtio_transport.c | 8 ++++++-- > net/vmw_vsock/virtio_transport_common.c | 10 +++++++++- > 4 files changed, 17 insertions(+), 3 deletions(-) > > diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c > index 5703775af129..65475d128a1d 100644 > --- a/drivers/vhost/vsock.c > +++ b/drivers/vhost/vsock.c > @@ -399,6 +399,7 @@ vhost_vsock_alloc_pkt(struct vhost_virtqueue *vq, > return NULL; > } > > + pkt->slab_buf = true; > pkt->buf_len = pkt->len; > > nbytes = copy_from_iter(pkt->buf, pkt->len, &iov_iter); > diff --git a/include/linux/virtio_vsock.h b/include/linux/virtio_vsock.h > index 35d7eedb5e8e..d02cb7aa922f 100644 > --- a/include/linux/virtio_vsock.h > +++ b/include/linux/virtio_vsock.h > @@ -50,6 +50,7 @@ struct virtio_vsock_pkt { > u32 off; > bool reply; > bool tap_delivered; > + bool slab_buf; > }; > > struct virtio_vsock_pkt_info { > diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c > index ad64f403536a..19909c1e9ba3 100644 > --- a/net/vmw_vsock/virtio_transport.c > +++ b/net/vmw_vsock/virtio_transport.c > @@ -255,16 +255,20 @@ static void virtio_vsock_rx_fill(struct virtio_vsock *vsock) > vq = vsock->vqs[VSOCK_VQ_RX]; > > do { > + struct page *buf_page; > + > pkt = kzalloc(sizeof(*pkt), GFP_KERNEL); > if (!pkt) > break; > > - pkt->buf = kmalloc(buf_len, GFP_KERNEL); > - if (!pkt->buf) { > + buf_page = alloc_page(GFP_KERNEL); > + > + if (!buf_page) { > virtio_transport_free_pkt(pkt); > break; > } > > + pkt->buf = page_to_virt(buf_page); > pkt->buf_len = buf_len; > pkt->len = buf_len; > > diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c > index a9980e9b9304..37e8dbfe2f5d 100644 > --- a/net/vmw_vsock/virtio_transport_common.c > +++ b/net/vmw_vsock/virtio_transport_common.c > @@ -69,6 +69,7 @@ virtio_transport_alloc_pkt(struct virtio_vsock_pkt_info *info, > if (!pkt->buf) > goto out_pkt; > > + pkt->slab_buf = true; > pkt->buf_len = len; > > err = memcpy_from_msg(pkt->buf, info->msg, len); > @@ -1339,7 +1340,14 @@ EXPORT_SYMBOL_GPL(virtio_transport_recv_pkt); > > void virtio_transport_free_pkt(struct virtio_vsock_pkt *pkt) > { > - kvfree(pkt->buf); > + if (pkt->buf_len) { > + if (pkt->slab_buf) > + kvfree(pkt->buf); Hi, kfree()? (according to virtio_transport_alloc_pkt() in -next) or something else need to be changed. > + else > + free_pages((unsigned long)pkt->buf, > + get_order(pkt->buf_len)); In virtio_vsock_rx_fill(), only alloc_page() is used. Should this be alloc_pages(.., get_order(buf_len)) or free_page() (without an 's') here? Just my 2c, CJ > + } > + > kfree(pkt); > } > EXPORT_SYMBOL_GPL(virtio_transport_free_pkt);