Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp7462669rdb; Wed, 3 Jan 2024 17:57:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IHDeMOKFxJ8n6IhFe74lEGV6xmHG0b1fuG7s1YSdNIuAlETJtfw1n8kitWY7Vwqf/AuBasV X-Received: by 2002:a05:6e02:1e05:b0:35f:fe74:2ca4 with SMTP id g5-20020a056e021e0500b0035ffe742ca4mr24969002ila.26.1704333443404; Wed, 03 Jan 2024 17:57:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704333443; cv=none; d=google.com; s=arc-20160816; b=BplqJyLmc//RlSuRScMerGUMmpv1vSiLRwudpIwQN71EGcBI+zPhWZVXY4bnh3ktS8 bGzVCY8xDfMwWRFgd+v5+veRdukHs3e4+KOoTXgKqB9DhtpHSsfmshIYknCEzMXhJSnx ViBOWfZIxQD3U4I6/NPbbI1hXBRF89ifmmzN+A2EgOn83DKX7E//6LgFAofEJ1I1ZLB+ Nnhwc3yUuT4SKvoGYAcPO883F5sns3RzZLVIcocbW0u8Y5Lhjpx7/pfKcwK68IMVNd8B UnHYDI45niSyv2rdwiQguB91fu9aNKEm9OuTd76heRl5oizP78wbFIpzvmpG7VVKqrl/ ZmgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=XwwEhwyauQxTj++nbDEWVPdtZihzbAcFuprtpaz1ZYg=; fh=fIYlrcnyuRQiLOnCPgGCxl4lm4yLpc0cfCjFUTwNX3Y=; b=BvghUTboha7ubnE471ENgQdX0H4OcaDgn0qZW4FH4OKMzFmLG6kvzzEikD+dp+ZIl6 cx9Uz0CpwMoP3RCzGCWHJdvjZADVJTnvOGLWgTNUqCzOxoa4+4YrHXE35+vTTpfWl0vi BAvk8LZcICwp3fN3GDpkm/7bm92OW1xtlx3eIy/xCvKV4K3N5ewZbW4okQnn28KDyI// HWWLnT7dk8AlVtjy9+SeU0coqy36Ds2whOevvlowbXXDOPT6MkCID+0MOSbFO8rIbYNA aYhYiDMK1y4UV58RB1A+DEbGUmENYfYEisc0b5i5BsjMNQTQtt54SF7gJ4EFGX1KlD7V gEcQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-16191-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16191-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id e12-20020a65688c000000b005b95ccd1b4dsi19668024pgt.82.2024.01.03.17.57.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 17:57:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-16191-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-16191-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16191-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id C7EA72877F0 for ; Thu, 4 Jan 2024 01:57:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9CD1A1E4B1; Thu, 4 Jan 2024 01:57:11 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (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 0F58A1DDE7; Thu, 4 Jan 2024 01:57:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4T58pk2WMMz4f3jXV; Thu, 4 Jan 2024 09:57:02 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id A13D61A09FF; Thu, 4 Jan 2024 09:57:05 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.124.27]) by APP1 (Coremail) with SMTP id cCh0CgAneA5vEJZlOVnbFQ--.23128S4; Thu, 04 Jan 2024 09:57:05 +0800 (CST) From: Hou Tao To: linux-fsdevel@vger.kernel.org Cc: Miklos Szeredi , Vivek Goyal , Stefan Hajnoczi , linux-kernel@vger.kernel.org, virtualization@lists.linux.dev, houtao1@huawei.com Subject: [PATCH] virtiofs: use GFP_NOFS when enqueuing request through kworker Date: Thu, 4 Jan 2024 09:58:05 +0800 Message-Id: <20240104015805.2103766-1-houtao@huaweicloud.com> X-Mailer: git-send-email 2.29.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:cCh0CgAneA5vEJZlOVnbFQ--.23128S4 X-Coremail-Antispam: 1UD129KBjvJXoWxGF4kXryDZr4rCw1DXF45GFg_yoWrGr15pr WUta15GFZ5JFW2gF95JF4UCw1Yk3sakFW7Ga4fWa4akr15Xw47uFy8ZFy0qrsavrykCF1x Jr4FqF4DuF47uaUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUgKb4IE77IF4wAFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x 0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG 6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFV Cjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCj c4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4 CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1x MIIF0xvE2Ix0cI8IcVCY1x0267AKxVWUJVW8JwCI42IY6xAIw20EY4v20xvaj40_WFyUJV Cq3wCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r1j6r4UYxBI daVFxhVjvjDU0xZFpf9x07UWE__UUUUU= X-CM-SenderInfo: xkrx3t3r6k3tpzhluzxrxghudrp/ From: Hou Tao When invoking virtio_fs_enqueue_req() through kworker, both the allocation of the sg array and the bounce buffer still use GFP_ATOMIC. Considering the size of both the sg array and the bounce buffer may be greater than PAGE_SIZE, use GFP_NOFS instead of GFP_ATOMIC to lower the possibility of memory allocation failure. Signed-off-by: Hou Tao --- fs/fuse/virtio_fs.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c index 3aac31d45198..ec4d0d81a5e2 100644 --- a/fs/fuse/virtio_fs.c +++ b/fs/fuse/virtio_fs.c @@ -87,7 +87,8 @@ struct virtio_fs_req_work { }; static int virtio_fs_enqueue_req(struct virtio_fs_vq *fsvq, - struct fuse_req *req, bool in_flight); + struct fuse_req *req, bool in_flight, + bool in_atomic); static const struct constant_table dax_param_enums[] = { {"always", FUSE_DAX_ALWAYS }, @@ -383,7 +384,7 @@ static void virtio_fs_request_dispatch_work(struct work_struct *work) list_del_init(&req->list); spin_unlock(&fsvq->lock); - ret = virtio_fs_enqueue_req(fsvq, req, true); + ret = virtio_fs_enqueue_req(fsvq, req, true, false); if (ret < 0) { if (ret == -ENOMEM || ret == -ENOSPC) { spin_lock(&fsvq->lock); @@ -488,7 +489,7 @@ static void virtio_fs_hiprio_dispatch_work(struct work_struct *work) } /* Allocate and copy args into req->argbuf */ -static int copy_args_to_argbuf(struct fuse_req *req) +static int copy_args_to_argbuf(struct fuse_req *req, gfp_t gfp) { struct fuse_args *args = req->args; unsigned int offset = 0; @@ -502,7 +503,7 @@ static int copy_args_to_argbuf(struct fuse_req *req) len = fuse_len_args(num_in, (struct fuse_arg *) args->in_args) + fuse_len_args(num_out, args->out_args); - req->argbuf = kmalloc(len, GFP_ATOMIC); + req->argbuf = kmalloc(len, gfp); if (!req->argbuf) return -ENOMEM; @@ -1119,7 +1120,8 @@ static unsigned int sg_init_fuse_args(struct scatterlist *sg, /* Add a request to a virtqueue and kick the device */ static int virtio_fs_enqueue_req(struct virtio_fs_vq *fsvq, - struct fuse_req *req, bool in_flight) + struct fuse_req *req, bool in_flight, + bool in_atomic) { /* requests need at least 4 elements */ struct scatterlist *stack_sgs[6]; @@ -1128,6 +1130,7 @@ static int virtio_fs_enqueue_req(struct virtio_fs_vq *fsvq, struct scatterlist *sg = stack_sg; struct virtqueue *vq; struct fuse_args *args = req->args; + gfp_t gfp = in_atomic ? GFP_ATOMIC : GFP_NOFS; unsigned int argbuf_used = 0; unsigned int out_sgs = 0; unsigned int in_sgs = 0; @@ -1140,8 +1143,8 @@ static int virtio_fs_enqueue_req(struct virtio_fs_vq *fsvq, /* Does the sglist fit on the stack? */ total_sgs = sg_count_fuse_req(req); if (total_sgs > ARRAY_SIZE(stack_sgs)) { - sgs = kmalloc_array(total_sgs, sizeof(sgs[0]), GFP_ATOMIC); - sg = kmalloc_array(total_sgs, sizeof(sg[0]), GFP_ATOMIC); + sgs = kmalloc_array(total_sgs, sizeof(sgs[0]), gfp); + sg = kmalloc_array(total_sgs, sizeof(sg[0]), gfp); if (!sgs || !sg) { ret = -ENOMEM; goto out; @@ -1149,7 +1152,7 @@ static int virtio_fs_enqueue_req(struct virtio_fs_vq *fsvq, } /* Use a bounce buffer since stack args cannot be mapped */ - ret = copy_args_to_argbuf(req); + ret = copy_args_to_argbuf(req, gfp); if (ret < 0) goto out; @@ -1245,7 +1248,7 @@ __releases(fiq->lock) fuse_len_args(req->args->out_numargs, req->args->out_args)); fsvq = &fs->vqs[queue_id]; - ret = virtio_fs_enqueue_req(fsvq, req, false); + ret = virtio_fs_enqueue_req(fsvq, req, false, true); if (ret < 0) { if (ret == -ENOMEM || ret == -ENOSPC) { /* -- 2.29.2