Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2940530lqt; Tue, 23 Apr 2024 06:25:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVxMBLrLVW1JjyY/8A/mhEt4E+O+oJP6kyVKUPcttuvadg6175fr5LL3vZdGK+t3h1/Q5NdfDv4a/DpOdAx7rJnDla3bPEDumSiUucTiw== X-Google-Smtp-Source: AGHT+IFBhymbIsQ+0JK/7hzRdXfQgHb1Jg8IRfbvzkGullq8vriPHM6nU9PeMYQyQ++NkjJjbSLy X-Received: by 2002:a50:9f22:0:b0:56e:2e10:7dad with SMTP id b31-20020a509f22000000b0056e2e107dadmr8958338edf.35.1713878755756; Tue, 23 Apr 2024 06:25:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713878755; cv=pass; d=google.com; s=arc-20160816; b=IQJnKOOxaBQurSrHR+n1w7xdtzvvWthyceiioZK6CqYOMyUfvosxB5bdzRInwShj9P uISeVKvs0IvspONW/p8UCRAXuZQoLIH11Rw0W2AJFYU/02GAboerw5fkJ2AhVLdIqakc 1Jap2v1awt18ObZr/nVbcGzsbDQ4Iw/qAsvNnbm4Ny28Y9KKFnQiNq+jBtVkpvXY9D4/ bX32v7TjqbUcykMgtCRqiqbrxpLVghX2NAQKcrVATUlh+lel2TAAt8vU9JPwm/yDxtfZ w4jdqZc2QAUoy/EB2L5nekIpDwmuFVhTPHM9JMuDs5hZrgTz6TldDxc9usDRgxlKQ/eH myxw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-language:content-transfer-encoding:in-reply-to:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:user-agent:date :message-id:from:references:cc:to:subject; bh=N33+Y0+41pJlmsNcPSEBZ8KkK5JmFgsJisD4OFSShCw=; fh=B13uBUlllhB0ECr4ySwpmH9VYu8F1CJh8upY3m083ls=; b=beAs4jJoXBeRnBWMTfJLh4SI1Y4OIjoBF/l23ciRPwpGhqPTcvS/BIZvYCI6cJ9yDl 2MkjdQxUnS3pxu6xJx4PQVOHC1apKXWQfvss+AEyciZoNSszJs0D94Vke4B31BF6h6ZP 2XpsGpGhvTwN0ILkaAnHlAGAKRwrlM/W1pPgHWW/DSkCVO8/q3upxSwzZ5z3GhCw9uB4 6Ew87ZVfDX83qMx4RvUK3lVPLoWXGcByp9LWrP5kF0hrfqVIGcTasnLKZoEejCzRheRY dV29Attq5Lq5PnmMUwQ37s2JLmLJKnt7sFm771hHLVryf7iBw7taCddnHB3GKUwQq7Cz igMg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-155279-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-155279-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id l21-20020a056402345500b00572154064f1si1655609edc.299.2024.04.23.06.25.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 06:25:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-155279-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-155279-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-155279-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 51DB21F21F5B for ; Tue, 23 Apr 2024 13:25:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AE77E135A73; Tue, 23 Apr 2024 13:25:44 +0000 (UTC) Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 414D4135A40; Tue, 23 Apr 2024 13:25:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713878744; cv=none; b=mObamySBxAgG/AGVKffpEueud4+Rvn1OakNPqtiI557jPbPBUyUS0lY0kA4gZn5DHCJ+t3xz2IIHwM8IKJKsOIeiOCcHmoAWIkb2F0dO27HaTjyd6SDh5QDYga3Trawjnu5zwUZCoA1Qd5ebItg79R2j6g6J9YhvBKXV+s4AevY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713878744; c=relaxed/simple; bh=5a4bb9B//8XIDmTV7hGB8eIJiBmSaKE7suGLchtgKZU=; h=Subject:To:Cc:References:From:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=P+uacGBWZinr7gIC3vU5TG95OZVW0fjkUP7xiBmg6VCPibJWNdem4s35x0bY+d9kfogWWDqV5C9Uf5V1qeBHWx6DBAOgA1Gz+7HaagBR0WBZYswYrPd+6r/9++rl8YvepTNe5sYYUgo+eMmg1bDKiARfaIIFq1o0OIM4QegMEnI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VP2tK4gz5z4f3nTY; Tue, 23 Apr 2024 21:25:29 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id CBA661A016E; Tue, 23 Apr 2024 21:25:38 +0800 (CST) Received: from [10.174.176.117] (unknown [10.174.176.117]) by APP2 (Coremail) with SMTP id Syh0CgCH6v3NtidmQDz9Kw--.51257S2; Tue, 23 Apr 2024 21:25:37 +0800 (CST) Subject: Re: [PATCH v2 0/6] virtiofs: fix the warning for ITER_KVEC dio To: "Michael S. Tsirkin" Cc: linux-fsdevel@vger.kernel.org, Miklos Szeredi , Vivek Goyal , Stefan Hajnoczi , Bernd Schubert , Matthew Wilcox , Benjamin Coddington , linux-kernel@vger.kernel.org, virtualization@lists.linux.dev, houtao1@huawei.com References: <20240228144126.2864064-1-houtao@huaweicloud.com> <20240408034514-mutt-send-email-mst@kernel.org> <413bd868-a16b-f024-0098-3c70f7808d3c@huaweicloud.com> <20240422160615-mutt-send-email-mst@kernel.org> From: Hou Tao Message-ID: <3a287e9b-55ad-dda9-5f53-c12536bad31d@huaweicloud.com> Date: Tue, 23 Apr 2024 21:25:33 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: <20240422160615-mutt-send-email-mst@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US X-CM-TRANSID:Syh0CgCH6v3NtidmQDz9Kw--.51257S2 X-Coremail-Antispam: 1UD129KBjvJXoWxGryfKrWUZFy7GFWDWFy5twb_yoWrXry5pr Wftan8trsr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2024 at 09:48:08AM +0800, Hou Tao wrote: >> Hi, >> >> On 4/8/2024 3:45 PM, Michael S. Tsirkin wrote: >>> On Wed, Feb 28, 2024 at 10:41:20PM +0800, Hou Tao wrote: >>>> From: Hou Tao >>>> >>>> Hi, >>>> >>>> The patch set aims to fix the warning related to an abnormal size >>>> parameter of kmalloc() in virtiofs. The warning occurred when attempting >>>> to insert a 10MB sized kernel module kept in a virtiofs with cache >>>> disabled. As analyzed in patch #1, the root cause is that the length of >>>> the read buffer is no limited, and the read buffer is passed directly to >>>> virtiofs through out_args[0].value. Therefore patch #1 limits the >>>> length of the read buffer passed to virtiofs by using max_pages. However >>>> it is not enough, because now the maximal value of max_pages is 256. >>>> Consequently, when reading a 10MB-sized kernel module, the length of the >>>> bounce buffer in virtiofs will be 40 + (256 * 4096), and kmalloc will >>>> try to allocate 2MB from memory subsystem. The request for 2MB of >>>> physically contiguous memory significantly stress the memory subsystem >>>> and may fail indefinitely on hosts with fragmented memory. To address >>>> this, patch #2~#5 use scattered pages in a bio_vec to replace the >>>> kmalloc-allocated bounce buffer when the length of the bounce buffer for >>>> KVEC_ITER dio is larger than PAGE_SIZE. The final issue with the >>>> allocation of the bounce buffer and sg array in virtiofs is that >>>> GFP_ATOMIC is used even when the allocation occurs in a kworker context. >>>> Therefore the last patch uses GFP_NOFS for the allocation of both sg >>>> array and bounce buffer when initiated by the kworker. For more details, >>>> please check the individual patches. >>>> >>>> As usual, comments are always welcome. >>>> >>>> Change Log: >>> Bernd should I just merge the patchset as is? >>> It seems to fix a real problem and no one has the >>> time to work on a better fix .... WDYT? >> Sorry for the long delay. I am just start to prepare for v3. In v3, I >> plan to avoid the unnecessary memory copy between fuse args and bio_vec. >> Will post it before next week. > Didn't happen before this week apparently. Sorry for failing to make it this week. Being busy these two weeks. Hope to send v3 out before the end of April. > >>> >>>> v2: >>>> * limit the length of ITER_KVEC dio by max_pages instead of the >>>> newly-introduced max_nopage_rw. Using max_pages make the ITER_KVEC >>>> dio being consistent with other rw operations. >>>> * replace kmalloc-allocated bounce buffer by using a bounce buffer >>>> backed by scattered pages when the length of the bounce buffer for >>>> KVEC_ITER dio is larger than PAG_SIZE, so even on hosts with >>>> fragmented memory, the KVEC_ITER dio can be handled normally by >>>> virtiofs. (Bernd Schubert) >>>> * merge the GFP_NOFS patch [1] into this patch-set and use >>>> memalloc_nofs_{save|restore}+GFP_KERNEL instead of GFP_NOFS >>>> (Benjamin Coddington) >>>> >>>> v1: https://lore.kernel.org/linux-fsdevel/20240103105929.1902658-1-houtao@huaweicloud.com/ >>>> >>>> [1]: https://lore.kernel.org/linux-fsdevel/20240105105305.4052672-1-houtao@huaweicloud.com/ >>>> >>>> Hou Tao (6): >>>> fuse: limit the length of ITER_KVEC dio by max_pages >>>> virtiofs: move alloc/free of argbuf into separated helpers >>>> virtiofs: factor out more common methods for argbuf >>>> virtiofs: support bounce buffer backed by scattered pages >>>> virtiofs: use scattered bounce buffer for ITER_KVEC dio >>>> virtiofs: use GFP_NOFS when enqueuing request through kworker >>>> >>>> fs/fuse/file.c | 12 +- >>>> fs/fuse/virtio_fs.c | 336 +++++++++++++++++++++++++++++++++++++------- >>>> 2 files changed, 296 insertions(+), 52 deletions(-) >>>> >>>> -- >>>> 2.29.2