Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp281085rwb; Wed, 28 Sep 2022 02:36:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5QrFmLeFcKhefu64xligt4MlOXHUUIhq0DLpzem1Tgi+X68y0C9N9B5A/SwMiUgNrWkGkj X-Received: by 2002:a17:906:9bdc:b0:77e:1ed1:b12 with SMTP id de28-20020a1709069bdc00b0077e1ed10b12mr26437605ejc.661.1664357772756; Wed, 28 Sep 2022 02:36:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664357772; cv=none; d=google.com; s=arc-20160816; b=bFxpLoigRcS5pqPyJ0UWtWeBJZQpq/SA36BKedRaVEy95fcQ94/o4yvO0tKKEbnL+v m2ikN4oMSxIekfOPgse0aurFFfANowGlYbBuH0WjTt6LalMIVYoIrVNZpiPXyQWVKWsn Qa9FAdiVaRtqikWERlvfXarZz9csHYYBqBTr0+yVgGsQ/4zVVwGLx9on34zIYVPZOpFw 3GkdqPx7zPTmDYTLfPDZv8mBSlNrfFtwUYw/0q1wPqNiQNgfP8fJeoVHpt/q8c9Dk/J6 REUU2RbMJTrWIRAHbFidA9kxLcneEruC79E57NE3Venp5I5CpQrWgvN42IcK3z/bPRpZ yxAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=RKWhiaA5Wv0V2eMraFNdl4jrLjbjCkjEq9//t8SsrB0=; b=NIzXlt3pQaoiuVTgR/TxdBrcSzLwTQShLKiy6pJEssz7Goj95gfgUHqjxo6nfOuyVp s1/KnM/2HZobTkCyE5vjxQCHiLdPjAt/SFhTT4QE+mqJCnLWZP3c62e97W08fK3MYlsj bOL71UJ8L+HtziNBxWFnkUt75DSg8dBU6tun1k0CngFme+jYYz60xGegfq9yg9QxlZaM FmNDBgK3ATUC0iFEtp+12BFO9nth0bIc6Rwp2YJXRCqyt1jYS5ecDQq+KmDIRiD71jZh AKCHt8YE0W+ureICtmA7vQIhGRdJMAAg4ZwCGfI7Mm4xamVJ/KmSMuFKtQk8Srj1iiHK 1ytQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MaqAMnuJ; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z9-20020a509e09000000b00454290f2ff9si4371200ede.178.2022.09.28.02.35.46; Wed, 28 Sep 2022 02:36:12 -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=MaqAMnuJ; 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 S233844AbiI1Jc2 (ORCPT + 99 others); Wed, 28 Sep 2022 05:32:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233778AbiI1JcI (ORCPT ); Wed, 28 Sep 2022 05:32:08 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35784558E3 for ; Wed, 28 Sep 2022 02:32:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664357526; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=RKWhiaA5Wv0V2eMraFNdl4jrLjbjCkjEq9//t8SsrB0=; b=MaqAMnuJ8BfdaGqo8ndBWNxw78+hQCQsiFgmXxAwYLNRzWcOb98N3WmgvpkE2Qme3jPDO0 giPzci2pXqJUzJHL2Hrm1Cd7vuN03XxS7lzDoQ0+925+ZJtfqjSMMVb3aDcuids1gTrI77 vX2lb0r2fdkyy6l//LBoa8/JB49EdAA= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-222-Rq_wVGY8NwmPu9TayD2SCw-1; Wed, 28 Sep 2022 05:32:05 -0400 X-MC-Unique: Rq_wVGY8NwmPu9TayD2SCw-1 Received: by mail-wr1-f72.google.com with SMTP id r22-20020adfa156000000b0022cc3018fbaso917356wrr.2 for ; Wed, 28 Sep 2022 02:32:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date; bh=RKWhiaA5Wv0V2eMraFNdl4jrLjbjCkjEq9//t8SsrB0=; b=TKvgkayO/vS5lxAWi7EgQj2IQvdTtMbhMW6A56CdqXHUOsPc1AQskIAFA0YYr5LNG0 oWNWYSEm2DMgfoZwBA5+8OknKp5QjHawRztZgFBEna4IaYfit8Uhs5Vd2DIcsI9RlPpQ xWSgRG5UMJhws7rC9xdqnIlL8t1uYjnOgU+q4EZ4Sbn34QxI56yLZvnnROpGbBPGIDZU sJw3CXCj0aVaFdaTezc2WlpsNvzizqaErXlwR2AXSKno4JQrqb6DsbULscXGYCmFlQNx PIWTO+FQev8LTFG0qWjMm668SCrJp8qtA5FKOlkN07KWJbPfJyOP4dTv0UaO0QrXwOp4 725Q== X-Gm-Message-State: ACrzQf1YKMcD64HSGtmH8EWsOHgL6YEPoBrKDcmSXp9NDQigtGQ+uMk+ hjoRQb8nhv4854KeLolwQJILD1fX4KVUxvHIDxE9XtDGSZdJEqYIEzU2kNvq7/xnsEMSZqDuZbg SxNjLDN7L6VQfVRzrcHtAWg9H X-Received: by 2002:adf:ec09:0:b0:22c:c81b:b76a with SMTP id x9-20020adfec09000000b0022cc81bb76amr1504082wrn.302.1664357522968; Wed, 28 Sep 2022 02:32:02 -0700 (PDT) X-Received: by 2002:adf:ec09:0:b0:22c:c81b:b76a with SMTP id x9-20020adfec09000000b0022cc81bb76amr1504062wrn.302.1664357522722; Wed, 28 Sep 2022 02:32:02 -0700 (PDT) Received: from redhat.com ([2.55.47.213]) by smtp.gmail.com with ESMTPSA id l13-20020a5d410d000000b0022cbcfa8447sm3829691wrp.87.2022.09.28.02.32.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Sep 2022 02:32:02 -0700 (PDT) Date: Wed, 28 Sep 2022 05:31:58 -0400 From: "Michael S. Tsirkin" To: Stefano Garzarella Cc: Junichi Uekawa , Stefan Hajnoczi , Jason Wang , Eric Dumazet , davem@davemloft.net, netdev@vger.kernel.org, Jakub Kicinski , virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, Paolo Abeni , linux-kernel@vger.kernel.org, Bobby Eshleman Subject: Re: [PATCH] vhost/vsock: Use kvmalloc/kvfree for larger packets. Message-ID: <20220928052738-mutt-send-email-mst@kernel.org> References: <20220928064538.667678-1-uekawa@chromium.org> <20220928082823.wyxplop5wtpuurwo@sgarzare-redhat> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220928082823.wyxplop5wtpuurwo@sgarzare-redhat> X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE 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 Wed, Sep 28, 2022 at 10:28:23AM +0200, Stefano Garzarella wrote: > On Wed, Sep 28, 2022 at 03:45:38PM +0900, Junichi Uekawa wrote: > > When copying a large file over sftp over vsock, data size is usually 32kB, > > and kmalloc seems to fail to try to allocate 32 32kB regions. > > > > Call Trace: > > [] dump_stack+0x97/0xdb > > [] warn_alloc_failed+0x10f/0x138 > > [] ? __alloc_pages_direct_compact+0x38/0xc8 > > [] __alloc_pages_nodemask+0x84c/0x90d > > [] alloc_kmem_pages+0x17/0x19 > > [] kmalloc_order_trace+0x2b/0xdb > > [] __kmalloc+0x177/0x1f7 > > [] ? copy_from_iter+0x8d/0x31d > > [] vhost_vsock_handle_tx_kick+0x1fa/0x301 [vhost_vsock] > > [] vhost_worker+0xf7/0x157 [vhost] > > [] kthread+0xfd/0x105 > > [] ? vhost_dev_set_owner+0x22e/0x22e [vhost] > > [] ? flush_kthread_worker+0xf3/0xf3 > > [] ret_from_fork+0x4e/0x80 > > [] ? flush_kthread_worker+0xf3/0xf3 > > > > Work around by doing kvmalloc instead. > > > > Signed-off-by: Junichi Uekawa My worry here is that this in more of a work around. It would be better to not allocate memory so aggressively: if we are so short on memory we should probably process packets one at a time. Is that very hard to implement? > > --- > > > > drivers/vhost/vsock.c | 2 +- > > net/vmw_vsock/virtio_transport_common.c | 2 +- > > 2 files changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c > > index 368330417bde..5703775af129 100644 > > --- a/drivers/vhost/vsock.c > > +++ b/drivers/vhost/vsock.c > > @@ -393,7 +393,7 @@ vhost_vsock_alloc_pkt(struct vhost_virtqueue *vq, > > return NULL; > > } > > > > - pkt->buf = kmalloc(pkt->len, GFP_KERNEL); > > + pkt->buf = kvmalloc(pkt->len, GFP_KERNEL); > > if (!pkt->buf) { > > kfree(pkt); > > return NULL; > > diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c > > index ec2c2afbf0d0..3a12aee33e92 100644 > > --- a/net/vmw_vsock/virtio_transport_common.c > > +++ b/net/vmw_vsock/virtio_transport_common.c > > @@ -1342,7 +1342,7 @@ EXPORT_SYMBOL_GPL(virtio_transport_recv_pkt); > > > > void virtio_transport_free_pkt(struct virtio_vsock_pkt *pkt) > > { > > - kfree(pkt->buf); > > + kvfree(pkt->buf); > > virtio_transport_free_pkt() is used also in virtio_transport.c and > vsock_loopback.c where pkt->buf is allocated with kmalloc(), but IIUC > kvfree() can be used with that memory, so this should be fine. > > > kfree(pkt); > > } > > EXPORT_SYMBOL_GPL(virtio_transport_free_pkt); > > -- > > 2.37.3.998.g577e59143f-goog > > > > This issue should go away with the Bobby's work about introducing sk_buff > [1], but we can queue this for now. > > I'm not sure if we should do the same also in the virtio-vsock driver > (virtio_transport.c). Here in vhost-vsock the buf allocated is only used in > the host, while in the virtio-vsock driver the buffer is exposed to the > device emulated in the host, so it should be physically contiguous (if not, > maybe we need to adjust virtio_vsock_rx_fill()). More importantly it needs to support DMA API which IIUC kvmalloc memory does not. > So for now I think is fine to use kvmalloc only on vhost-vsock (eventually > we can use it also in vsock_loopback), since the Bobby's patch should rework > this code: > > Reviewed-by: Stefano Garzarella > > [1] https://lore.kernel.org/lkml/65d117ddc530d12a6d47fcc45b38891465a90d9f.1660362668.git.bobby.eshleman@bytedance.com/ > > Thanks, > Stefano