From patchwork Sat Sep 1 12:20:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia-Ju Bai X-Patchwork-Id: 10584721 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A303E139B for ; Sat, 1 Sep 2018 12:50:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9441E2A8FC for ; Sat, 1 Sep 2018 12:50:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 884652A913; Sat, 1 Sep 2018 12:50:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7E92F2A8FC for ; Sat, 1 Sep 2018 12:50:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 677266E04D; Sat, 1 Sep 2018 12:50:10 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3C0F26E07E for ; Sat, 1 Sep 2018 12:20:52 +0000 (UTC) Received: by mail-pg1-x544.google.com with SMTP id m4-v6so6608228pgv.12 for ; Sat, 01 Sep 2018 05:20:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=WtPEWrt9G9eyil6yu+3BOjNXbguLNPBLA+11spTOCHU=; b=VjC6jwNs+JFDiSwxdmXut11vc0l7ffy96CiEm4edBpqAEW30nI8NLqjFaMcFUSPvHg DcgRLWZsf24FGpvppc8JVbld9os4hS7OcF8aSG0PpiuLv03NA2SCrjBHAGYtJ3n6Mynu 8SlXYMVBVLLrWYMX1QGENDCp4CQ/QYbpEYRNBlTx19UxV+n9HWWLvitVw8WE218DNFyi XdUp314ecd2NmnC6P6N/x+B7b5tXoMKsGMmt8dWDGCd1V5OegmyywPnTmfx3XY+cePOl e6wQJ3TpGPWcE/nOwjaVShI7BtTIp5p2GF2wXdc1N0YF1Dci270hlwB/pqsT0d4DJUHM OU4g== X-Gm-Message-State: APzg51BFpOwa8f4yeWK0hkSvO0Vm54APaiTZrXQzGVZmbbyrHAPp721e G4EUEsW8PstDehxI5fmBO0g= X-Google-Smtp-Source: ANB0Vda/n/G1j8emWjQitJJsL1pXqdxCJ3CnKlHPM+sWAhgBuL8PsTVplA9TWW5eGW8IjE1Ujyo4FA== X-Received: by 2002:a62:b0b:: with SMTP id t11-v6mr16630632pfi.36.1535804451889; Sat, 01 Sep 2018 05:20:51 -0700 (PDT) Received: from localhost.localdomain ([2402:f000:1:4414:2913:cd09:aee0:380]) by smtp.gmail.com with ESMTPSA id r81-v6sm18441435pfa.18.2018.09.01.05.20.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Sep 2018 05:20:51 -0700 (PDT) From: Jia-Ju Bai To: gustavo@padovan.org, maarten.lankhorst@linux.intel.com, seanpaul@chromium.org, airlied@linux.ie Subject: [PATCH] gpu: drm: drm_mm: Fix a sleep-in-atomic-context bug in show_leaks() Date: Sat, 1 Sep 2018 20:20:41 +0800 Message-Id: <20180901122041.2357-1-baijiaju1990@gmail.com> X-Mailer: git-send-email 2.17.0 X-Mailman-Approved-At: Sat, 01 Sep 2018 12:50:09 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jia-Ju Bai , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP The driver may sleep with holding a spinlock. The function call paths (from bottom to top) in Linux-4.16 are: [FUNC] kmalloc(GFP_KERNEL) drivers/gpu/drm/drm_mm.c, 130: kmalloc in show_leaks drivers/gpu/drm/drm_mm.c, 913: show_leaks in drm_mm_takedown drivers/gpu/drm/drm_vma_manager.c, 107: drm_mm_takedown in drm_vma_offset_manager_destroy drivers/gpu/drm/drm_vma_manager.c, 106: _raw_write_lock in drm_vma_offset_manager_destroy [FUNC] kmalloc(GFP_KERNEL) drivers/gpu/drm/drm_mm.c, 130: kmalloc in show_leaks drivers/gpu/drm/drm_mm.c, 913: show_leaks in drm_mm_takedown drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c, 71: drm_mm_takedown in amdgpu_vram_mgr_fini drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c, 70: spin_lock in amdgpu_vram_mgr_fini [FUNC] kmalloc(GFP_KERNEL) drivers/gpu/drm/drm_mm.c, 130: kmalloc in show_leaks drivers/gpu/drm/drm_mm.c, 913: show_leaks in drm_mm_takedown drivers/gpu/drm/ttm/ttm_bo_manager.c, 128: drm_mm_takedown in ttm_bo_man_takedown drivers/gpu/drm/ttm/ttm_bo_manager.c, 126: spin_lock in ttm_bo_man_takedown To fix this bug, GFP_KERNEL is replaced with GFP_ATOMIC. This bug is found by my static analysis tool DSAC. Signed-off-by: Jia-Ju Bai --- drivers/gpu/drm/drm_mm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_mm.c b/drivers/gpu/drm/drm_mm.c index 3166026a1874..2486121a78d4 100644 --- a/drivers/gpu/drm/drm_mm.c +++ b/drivers/gpu/drm/drm_mm.c @@ -127,7 +127,7 @@ static void show_leaks(struct drm_mm *mm) unsigned long entries[STACKDEPTH]; char *buf; - buf = kmalloc(BUFSZ, GFP_KERNEL); + buf = kmalloc(BUFSZ, GFP_ATOMIC); if (!buf) return;