Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88EBCC433E0 for ; Tue, 2 Mar 2021 14:09:03 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B3E7564EF0 for ; Tue, 2 Mar 2021 14:09:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B3E7564EF0 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=uniontech.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=amd-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7C3316E17E; Tue, 2 Mar 2021 14:09:01 +0000 (UTC) X-Greylist: delayed 439 seconds by postgrey-1.36 at gabe; Tue, 02 Mar 2021 06:50:09 UTC Received: from smtphy.263.net (sg-smtp01.263.net [54.255.195.220]) by gabe.freedesktop.org (Postfix) with ESMTPS id 947806E8BE for ; Tue, 2 Mar 2021 06:50:09 +0000 (UTC) Received: from smtp.263.net (unknown [211.157.147.162]) by smtphy.263.net (Postfix) with ESMTPS id 9CB04149 for ; Tue, 2 Mar 2021 14:42:46 +0800 (CST) Received: from regular1.263xmail.com (unknown [192.168.165.232]) by smtp.263.net (Postfix) with ESMTP id 0C3E025E for ; Tue, 2 Mar 2021 14:42:39 +0800 (CST) Received: from localhost (unknown [192.168.167.69]) by regular1.263xmail.com (Postfix) with ESMTP id EE0AB1B3F; Tue, 2 Mar 2021 14:42:34 +0800 (CST) X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-ADDR-CHECKED4: 1 X-ANTISPAM-LEVEL: 2 X-SKE-CHECKED: 1 X-ABS-CHECKED: 1 Received: from chenli.uniontech.com (unknown [58.246.122.242]) by smtp.263.net (postfix) whith ESMTP id P17138T139833548986112S1614667331678795_; Tue, 02 Mar 2021 14:42:34 +0800 (CST) X-IP-DOMAINF: 1 X-UNIQUE-TAG: <93bafa1daa56c20642d16d234fd61fd8> X-RL-SENDER: chenli@uniontech.com X-SENDER: chenli@uniontech.com X-LOGIN-NAME: chenli@uniontech.com X-FST-TO: amd-gfx@lists.freedesktop.org X-SENDER-IP: 58.246.122.242 X-ATTACHMENT-NUM: 0 X-System-Flag: 0 Date: Tue, 02 Mar 2021 14:42:12 +0800 Message-ID: <87wnuqt5tn.wl-chenli@uniontech.com> From: Chen Li To: amd-gfx@lists.freedesktop.org Subject: [PATCH] drm/radeon: Use kvmalloc for CS chunks User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?ISO-8859-4?Q?Goj=F2?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-Mailman-Approved-At: Tue, 02 Mar 2021 14:08:59 +0000 X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alex Deucher , =?ISO-8859-1?Q?=22Christian_K=F6nig=22?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: amd-gfx-bounces@lists.freedesktop.org Sender: "amd-gfx" The number of chunks/chunks_array may be passed in by userspace and can be large. It has been observed to cause kcalloc failures from trinity fuzzy test: ``` WARNING: CPU: 0 PID: 5487 at mm/page_alloc.c:4385 __alloc_pages_nodemask+0x2d8/0x14d0 ...... Trace: __warn.part.4+0x11c/0x174 __alloc_pages_nodemask+0x2d8/0x14d0 warn_slowpath_null+0x84/0xb0 __alloc_pages_nodemask+0x2d8/0x14d0 __alloc_pages_nodemask+0x2d8/0x14d0 alloc_pages_current+0xf0/0x1b0 free_buffer_head+0x88/0xf0 jbd2_journal_try_to_free_buffers+0x1e0/0x2a0 ext4_releasepage+0x84/0x140 release_pages+0x414/0x4c0 release_pages+0x42c/0x4c0 __find_get_block+0x1a4/0x5b0 alloc_pages_current+0xcc/0x1b0 kmalloc_order+0x30/0xb0 __kmalloc+0x300/0x390 kmalloc_order_trace+0x48/0x110 __kmalloc+0x300/0x390 radeon_cs_parser_init.part.1+0x74/0x670 [radeon] crypto_shash_update+0x5c/0x1c0 radeon_cs_parser_init.part.1+0x74/0x670 [radeon] __wake_up_common_lock+0xb8/0x210 radeon_cs_ioctl+0xc8/0xb80 [radeon] radeon_cs_ioctl+0x50/0xb80 [radeon] drm_ioctl_kernel+0xf4/0x160 radeon_cs_ioctl+0x0/0xb80 [radeon] drm_ioctl_kernel+0xa0/0x160 drm_ioctl+0x2dc/0x4f0 radeon_drm_ioctl+0x80/0xf0 [radeon] new_sync_write+0x120/0x1c0 timerqueue_add+0x88/0x140 do_vfs_ioctl+0xe4/0x990 ksys_ioctl+0xdc/0x110 ksys_ioctl+0x78/0x110 sys_ioctl+0x2c/0x50 entSys+0xa0/0xc0 ``` Obviously, the required order in this case is larger than MAX_ORDER. So, just use kvmalloc instead. Signed-off-by: Chen Li --- drivers/gpu/drm/radeon/radeon_cs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/radeon/radeon_cs.c b/drivers/gpu/drm/radeon/radeon_cs.c index 35e937d39b51..fb736ef9f9aa 100644 --- a/drivers/gpu/drm/radeon/radeon_cs.c +++ b/drivers/gpu/drm/radeon/radeon_cs.c @@ -288,7 +288,7 @@ int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data) p->chunk_relocs = NULL; p->chunk_flags = NULL; p->chunk_const_ib = NULL; - p->chunks_array = kcalloc(cs->num_chunks, sizeof(uint64_t), GFP_KERNEL); + p->chunks_array = kvmalloc_array(cs->num_chunks, sizeof(uint64_t), GFP_KERNEL); if (p->chunks_array == NULL) { return -ENOMEM; } @@ -299,7 +299,7 @@ int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data) } p->cs_flags = 0; p->nchunks = cs->num_chunks; - p->chunks = kcalloc(p->nchunks, sizeof(struct radeon_cs_chunk), GFP_KERNEL); + p->chunks = kvmalloc_array(p->nchunks, sizeof(struct radeon_cs_chunk), GFP_KERNEL); if (p->chunks == NULL) { return -ENOMEM; } @@ -452,8 +452,8 @@ static void radeon_cs_parser_fini(struct radeon_cs_parser *parser, int error, bo kvfree(parser->vm_bos); for (i = 0; i < parser->nchunks; i++) kvfree(parser->chunks[i].kdata); - kfree(parser->chunks); - kfree(parser->chunks_array); + kvfree(parser->chunks); + kvfree(parser->chunks_array); radeon_ib_free(parser->rdev, &parser->ib); radeon_ib_free(parser->rdev, &parser->const_ib); } -- 2.30.0 _______________________________________________ amd-gfx mailing list amd-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/amd-gfx