From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 472B1C001B0 for ; Mon, 24 Jul 2023 01:29:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231695AbjGXB3X (ORCPT ); Sun, 23 Jul 2023 21:29:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231808AbjGXB2U (ORCPT ); Sun, 23 Jul 2023 21:28:20 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A4B1173C; Sun, 23 Jul 2023 18:25:34 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5CA4360F56; Mon, 24 Jul 2023 01:24:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1CC49C433C7; Mon, 24 Jul 2023 01:24:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690161878; bh=m+ncsUvO7yTWyHWyuGbLyy8EzHW6iarjjrqbOYH4rM0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NyfZgtINPPhrkZUm1VdP5bTJQXVtjIteWrxr6YANQjU/pSU/K+RcnvrwoCb3NEgB/ RkZI4tOg2ErRXOl4kLvd0VEqEdpj9mBWpYAZxsOGw9lQfMkNpksBsgJJ9SLyMlseY8 s26B/VoKM0FzqcBwpoNT3zti6NcO0YUAVoQyWuGLBZbzpnkdfcSWPa1TN/BYdP3Xxn YpjYMNOBnNrqdL72HQ/LNU9W4kOP2a70yVaFm6aWYPKRqB3zSiNWcMmCpj2SZP/34g OqDOuifKLLsLqokMvdZNp3kvCZOHFHaSJVB3iOmJcOoO/JgHY3VhSsO0fLVE9mCp8n rCrmexU4F34iQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: gaoxu , Suren Baghdasaryan , Christoph Hellwig , Sasha Levin Subject: [PATCH AUTOSEL 5.10 12/22] dma-remap: use kvmalloc_array/kvfree for larger dma memory remap Date: Sun, 23 Jul 2023 21:24:09 -0400 Message-Id: <20230724012419.2317649-12-sashal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230724012419.2317649-1-sashal@kernel.org> References: <20230724012419.2317649-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 5.10.186 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: gaoxu [ Upstream commit 51ff97d54f02b4444dfc42e380ac4c058e12d5dd ] If dma_direct_alloc() alloc memory in size of 64MB, the inner function dma_common_contiguous_remap() will allocate 128KB memory by invoking the function kmalloc_array(). and the kmalloc_array seems to fail to try to allocate 128KB mem. Call trace: [14977.928623] qcrosvm: page allocation failure: order:5, mode:0x40cc0 [14977.928638] dump_backtrace.cfi_jt+0x0/0x8 [14977.928647] dump_stack_lvl+0x80/0xb8 [14977.928652] warn_alloc+0x164/0x200 [14977.928657] __alloc_pages_slowpath+0x9f0/0xb4c [14977.928660] __alloc_pages+0x21c/0x39c [14977.928662] kmalloc_order+0x48/0x108 [14977.928666] kmalloc_order_trace+0x34/0x154 [14977.928668] __kmalloc+0x548/0x7e4 [14977.928673] dma_direct_alloc+0x11c/0x4f8 [14977.928678] dma_alloc_attrs+0xf4/0x138 [14977.928680] gh_vm_ioctl_set_fw_name+0x3c4/0x610 [gunyah] [14977.928698] gh_vm_ioctl+0x90/0x14c [gunyah] [14977.928705] __arm64_sys_ioctl+0x184/0x210 work around by doing kvmalloc_array instead. Signed-off-by: Gao Xu Reviewed-by: Suren Baghdasaryan Signed-off-by: Christoph Hellwig Signed-off-by: Sasha Levin --- kernel/dma/remap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/dma/remap.c b/kernel/dma/remap.c index 905c3fa005f10..5bff061993102 100644 --- a/kernel/dma/remap.c +++ b/kernel/dma/remap.c @@ -43,13 +43,13 @@ void *dma_common_contiguous_remap(struct page *page, size_t size, void *vaddr; int i; - pages = kmalloc_array(count, sizeof(struct page *), GFP_KERNEL); + pages = kvmalloc_array(count, sizeof(struct page *), GFP_KERNEL); if (!pages) return NULL; for (i = 0; i < count; i++) pages[i] = nth_page(page, i); vaddr = vmap(pages, count, VM_DMA_COHERENT, prot); - kfree(pages); + kvfree(pages); return vaddr; } -- 2.39.2