Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp28820797rwd; Wed, 5 Jul 2023 03:16:40 -0700 (PDT) X-Google-Smtp-Source: APBJJlEgiI1d8SwgiFjxfzdMQKrk6X1EA+4IUKD5hA6Am+pBHlJ1Q3KaGMoxMLt9/lLSoiB4eTRa X-Received: by 2002:a05:6a00:148b:b0:682:4c9f:aa0 with SMTP id v11-20020a056a00148b00b006824c9f0aa0mr20545533pfu.29.1688552200527; Wed, 05 Jul 2023 03:16:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688552200; cv=none; d=google.com; s=arc-20160816; b=WnUvFiCdrDclIzep/fH060zxfNAq98lgpbSzR3dsubMVqiOnUJyjNDp/W3GG7cXLnV 1DWRed2Zva7YW9LriSCLPmheyIz+F/D+y99Dfm2hiJfw7WQ4Hjwef7HhZ/m2g7wjEH2V +TFjI9te15Pk0sOAvCQJEuGNJaFUVZKdBV0H/tq40KCqxHkhWJg5JmBxwVJMAK09qvbj EG8KcLwwAlWqYwYS8duM23vRImzZFi/nZOpmNaAvmP8jGGvosWRirJVWy/rAahRNgweH 7aIVgivjNKZzDuW2Riyzw6Rop0eaO1WYGAiPnsRb6ABLbdmaIuooIedYKzpJc3rtOOMB yqkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-language:accept-language:message-id:date:thread-index :thread-topic:subject:cc:to:from; bh=ETP2cimZqXOyFP2SZDEP0ive+ymTdCEQ7SCZXWbdjnA=; fh=dgYhTw4MgCHTv1+vaeL+na91ircFHEA3vwQ8uVfX7yM=; b=j12GgaKIqgJNnb5Y73bAu6CFuHIPybj+K3CYQFKGC6gPxknk6KCtK3Qe7W7vgw0m3i toszbCWapG4UI4urIGh7FE2x6bXssUK/IjKKOqsAYd7Ra/hrocDl6P+bgMAZGvLN0002 X5PZ1QsYJbocAZnZci08La519HoOeVBoDj/gOnojyZvcM4dON0Ts+s2gXNORd8hUgVPn W/5hfLF13NFFf8nC+tsXGUyOY9Ky0JWN2NntqHRVh54iixDvLRTvfk95q8oyMUilncD9 ujJMZpTwFjkftCYdYzjJKDkFMTY+QR1MIUql2qeKLcTnCytIMdRmtN51dkxyaAlIQs9+ 46bA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=hihonor.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g9-20020a056a000b8900b0068240c29150si14153020pfj.227.2023.07.05.03.16.26; Wed, 05 Jul 2023 03:16:40 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=hihonor.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231479AbjGEJyK convert rfc822-to-8bit (ORCPT + 99 others); Wed, 5 Jul 2023 05:54:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231137AbjGEJyI (ORCPT ); Wed, 5 Jul 2023 05:54:08 -0400 X-Greylist: delayed 1202 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 05 Jul 2023 02:54:06 PDT Received: from mta22.hihonor.com (mta22.hihonor.com [81.70.192.198]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC5D6E41 for ; Wed, 5 Jul 2023 02:54:06 -0700 (PDT) Received: from w012.hihonor.com (unknown [10.68.27.189]) by mta22.hihonor.com (SkyGuard) with ESMTPS id 4QwvCS4ycXzYl0V5; Wed, 5 Jul 2023 17:15:48 +0800 (CST) Received: from a004.hihonor.com (10.68.27.131) by w012.hihonor.com (10.68.27.189) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.21; Wed, 5 Jul 2023 17:15:52 +0800 Received: from a001.hihonor.com (10.68.28.182) by a004.hihonor.com (10.68.27.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.21; Wed, 5 Jul 2023 17:15:52 +0800 Received: from a001.hihonor.com ([fe80::d540:a176:80f8:5fcf]) by a001.hihonor.com ([fe80::d540:a176:80f8:5fcf%8]) with mapi id 15.02.1118.021; Wed, 5 Jul 2023 17:15:52 +0800 From: gaoming To: Namjae Jeon , Sungjong Seo CC: "open list:EXFAT FILE SYSTEM" , open list , fengbaopeng , gaoxu , wangfei 00014658 , "shenchen 00013118" Subject: [PATCH] exfat: use kvmalloc_array/kvfree instead of kmalloc_array/kfree Thread-Topic: [PATCH] exfat: use kvmalloc_array/kvfree instead of kmalloc_array/kfree Thread-Index: AdmvHl4gs76xLNH6Sd+soB17KujxsA== Date: Wed, 5 Jul 2023 09:15:52 +0000 Message-ID: <4cec63dcd3c0443c928800ffeec9118c@hihonor.com> Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.164.15.53] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 The call stack shown below is a scenario in the Linux 4.19 kernel. Allocating memory failed where exfat fs use kmalloc_array due to system memory fragmentation, while the u-disk was inserted without recognition. Devices such as u-disk using the exfat file system are pluggable and may be insert into the system at any time. However, long-term running systems cannot guarantee the continuity of physical memory. Therefore, it's necessary to address this issue. Binder:2632_6: page allocation failure: order:4, mode:0x6040c0(GFP_KERNEL|__GFP_COMP), nodemask=(null) Call trace: [242178.097582] dump_backtrace+0x0/0x4 [242178.097589] dump_stack+0xf4/0x134 [242178.097598] warn_alloc+0xd8/0x144 [242178.097603] __alloc_pages_nodemask+0x1364/0x1384 [242178.097608] kmalloc_order+0x2c/0x510 [242178.097612] kmalloc_order_trace+0x40/0x16c [242178.097618] __kmalloc+0x360/0x408 [242178.097624] load_alloc_bitmap+0x160/0x284 [242178.097628] exfat_fill_super+0xa3c/0xe7c [242178.097635] mount_bdev+0x2e8/0x3a0 [242178.097638] exfat_fs_mount+0x40/0x50 [242178.097643] mount_fs+0x138/0x2e8 [242178.097649] vfs_kern_mount+0x90/0x270 [242178.097655] do_mount+0x798/0x173c [242178.097659] ksys_mount+0x114/0x1ac [242178.097665] __arm64_sys_mount+0x24/0x34 [242178.097671] el0_svc_common+0xb8/0x1b8 [242178.097676] el0_svc_handler+0x74/0x90 [242178.097681] el0_svc+0x8/0x340 By analyzing the exfat code,we found that continuous physical memory is not required here,so kvmalloc_array is used can solve this problem. Signed-off-by: gaoming --- fs/exfat/balloc.c | 4 ++-- fs/exfat/dir.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/exfat/balloc.c b/fs/exfat/balloc.c index 9f42f25fab92..a183558cb7a0 100644 --- a/fs/exfat/balloc.c +++ b/fs/exfat/balloc.c @@ -69,7 +69,7 @@ static int exfat_allocate_bitmap(struct super_block *sb, } sbi->map_sectors = ((need_map_size - 1) >> (sb->s_blocksize_bits)) + 1; - sbi->vol_amap = kmalloc_array(sbi->map_sectors, + sbi->vol_amap = kvmalloc_array(sbi->map_sectors, sizeof(struct buffer_head *), GFP_KERNEL); if (!sbi->vol_amap) return -ENOMEM; @@ -84,7 +84,7 @@ static int exfat_allocate_bitmap(struct super_block *sb, while (j < i) brelse(sbi->vol_amap[j++]); - kfree(sbi->vol_amap); + kvfree(sbi->vol_amap); sbi->vol_amap = NULL; return -EIO; } diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c index 957574180a5e..5cbb78d0a2a2 100644 --- a/fs/exfat/dir.c +++ b/fs/exfat/dir.c @@ -649,7 +649,7 @@ int exfat_put_dentry_set(struct exfat_entry_set_cache *es, int sync) brelse(es->bh[i]); if (IS_DYNAMIC_ES(es)) - kfree(es->bh); + kvfree(es->bh); return err; } @@ -888,7 +888,7 @@ int exfat_get_dentry_set(struct exfat_entry_set_cache *es, num_bh = EXFAT_B_TO_BLK_ROUND_UP(off + num_entries * DENTRY_SIZE, sb); if (num_bh > ARRAY_SIZE(es->__bh)) { - es->bh = kmalloc_array(num_bh, sizeof(*es->bh), GFP_KERNEL); + es->bh = kvmalloc_array(num_bh, sizeof(*es->bh), GFP_KERNEL); if (!es->bh) { brelse(bh); return -ENOMEM; -- 2.17.1