From patchwork Mon Aug 19 16:12:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring \(Arm\)" X-Patchwork-Id: 171650 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp3197714ily; Mon, 19 Aug 2019 09:12:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqy+PH0nDmwELMkVCSmscOHZwpXIApKJ2n5zFpZLF6TVdXrZ2lxiqi6koKa9gyv2ymYyEavQ X-Received: by 2002:a17:90a:2667:: with SMTP id l94mr21954867pje.74.1566231134616; Mon, 19 Aug 2019 09:12:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566231134; cv=none; d=google.com; s=arc-20160816; b=rZeUm8hjMrVOMZVCQPJLDIz2Rq30PKKfWF1oFl6dx1ftn8tBxFafTVTiyKYc7a5ivk Hai5wosR/yoWcDTt4ZZUCn+rGfw1Ig/OlgJky3eWww5QuW0rxmvHoMQd8og5wwQ6zCly qXWO0F/H8FRD6J+SMlCZvhau8Gw+vW9s40BtKuPQ/xEvsS6ky+enlxaOMGZ/uwTUbkNh Co9s6sRwBfNDDe6pkDT/J2czb3Cwy0RWQ483NHhetqoaUbkiPavArRbFADF+txK7bwmA rJqxUnIfTAQXvigFE2zxEnsdtN/MS1U6pKuaXInNk5PVduzCBOXaRsgEri1qJmE3LM+Q Ru5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:references:in-reply-to:message-id:date :subject:to:from:delivered-to; bh=V7+1xF6dy6cWs1bmecUfGyZyiK8GYSYbT+A8+msRwBo=; b=qQMIqdm5A4YKjhPAkAIvxsGI358Jbg2IqDrMGgOlf9hizDCxI6THV1oqBukM6Cd+dP Pf1AouFBjIJOsDrweccuyTj2mw9wJ/I3KunC4n6DTBjEpECFgilJtmNpKkLSd706b6gP hGBogkEZYNRkuq4/qQBErgKRLnGRXABsG1OPZG9cOObudjWqmnQ+fCSBlefnlWu3u0Hd It+2aJPigYbYCPE51K/lJcfL4B2NqRSH2gw1HE57rOCv8ZWKf6fHrPTusbgppWkaashS fIuw4ZkgNsQZrtHo7pfd0u/zgG1JDX/9iQJ4KOfThrykZZuXVe75IREPecgil0DEiVD8 fdiw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [2610:10:20:722:a800:ff:fe36:1795]) by mx.google.com with ESMTPS id s6si9737242plq.213.2019.08.19.09.12.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 19 Aug 2019 09:12:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) client-ip=2610:10:20:722:a800:ff:fe36:1795; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 039F16E1F4; Mon, 19 Aug 2019 16:12:13 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-io1-f65.google.com (mail-io1-f65.google.com [209.85.166.65]) by gabe.freedesktop.org (Postfix) with ESMTPS id C0EC96E1F4 for ; Mon, 19 Aug 2019 16:12:08 +0000 (UTC) Received: by mail-io1-f65.google.com with SMTP id t3so5443144ioj.12 for ; Mon, 19 Aug 2019 09:12:08 -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:in-reply-to :references:mime-version:content-transfer-encoding; bh=2ERJN1GBgWTOkhGXTq7TvmTjNbzQcD6oPAmY5Gi0OlY=; b=XhXan/kYDLplHunnjGfv1QT7yrmdk7yPPKsa3rM4DyjsmQNhpOWKCKtssto8V0DZqo T5Mp1vNBwTqA2kmMC/3Z442DaTl9kSu5REuBG+f+P5TFdZDfZtglBWYY4Ks6Fjj1CP25 D2v6KIv5K5UKHaFmCw1q8o4E8YHLHvG1mslYOB5mLLaJ2fUj0Kymw5CIQQ6E/n0kfQyP Z9W4Bt+zuxWIZ/eNYoOa8Rd/Xpl89qEKeD5TV20IiEOwUjx5OlAT0DQor8oqKPiEymzK M1vUpDSBjWctiTjX7lWioy2FUFkbcaXwnsmF0dZtXUxEr7+fkxREhkBoF1xuvRv0xiEK pzBw== X-Gm-Message-State: APjAAAV1c5eUH96+nQHyBMgEfHBSR/i6Q8rSYXpXYwRAY7Os3DEIItXV hO8mRH+h2aQw5CPvpr0tTN1cZno= X-Received: by 2002:a02:cc6c:: with SMTP id j12mr27128141jaq.29.1566231127730; Mon, 19 Aug 2019 09:12:07 -0700 (PDT) Received: from xps15.herring.priv (24-155-109-49.dyn.grandenetworks.net. [24.155.109.49]) by smtp.googlemail.com with ESMTPSA id c19sm4770584ioi.22.2019.08.19.09.12.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2019 09:12:07 -0700 (PDT) From: Rob Herring To: dri-devel@lists.freedesktop.org Subject: [PATCH 1/4] drm/shmem: Do dma_unmap_sg before purging pages Date: Mon, 19 Aug 2019 11:12:01 -0500 Message-Id: <20190819161204.3106-2-robh@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190819161204.3106-1-robh@kernel.org> References: <20190819161204.3106-1-robh@kernel.org> MIME-Version: 1.0 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: Maxime Ripard , Tomeu Vizoso , David Airlie , Sean Paul , Steven Price , Boris Brezillon , Robin Murphy Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Calling dma_unmap_sg() in drm_gem_shmem_free_object() is too late if the backing pages have already been released by the shrinker. The result is the following abort: Unable to handle kernel paging request at virtual address ffff8000098ed000 Mem abort info: ESR = 0x96000147 Exception class = DABT (current EL), IL = 32 bits SET = 0, FnV = 0 EA = 0, S1PTW = 0 Data abort info: ISV = 0, ISS = 0x00000147 CM = 1, WnR = 1 swapper pgtable: 4k pages, 48-bit VAs, pgdp=0000000002f51000 [ffff8000098ed000] pgd=00000000401f8003, pud=00000000401f7003, pmd=00000000401b1003, pte=00e80000098ed712 Internal error: Oops: 96000147 [#1] SMP Modules linked in: panfrost gpu_sched CPU: 5 PID: 902 Comm: gnome-shell Not tainted 5.3.0-rc1+ #95 Hardware name: 96boards Rock960 (DT) pstate: 40000005 (nZcv daif -PAN -UAO) pc : __dma_inv_area+0x40/0x58 lr : arch_sync_dma_for_cpu+0x28/0x30 sp : ffff00001321ba30 x29: ffff00001321ba30 x28: ffff00001321bd08 x27: 0000000000000000 x26: 0000000000000009 x25: 0000ffffc1f86170 x24: 0000000000000000 x23: 0000000000000000 x22: 0000000000000000 x21: 0000000000021000 x20: ffff80003bb2d810 x19: 00000000098ed000 x18: 0000000000000000 x17: 0000000000000000 x16: ffff800023fd9480 x15: 0000000000000000 x14: 0000000000000000 x13: 0000000000000000 x12: 0000000000000000 x11: 00000000fffb9fff x10: 0000000000000000 x9 : 0000000000000000 x8 : ffff800023fd9c18 x7 : 0000000000000000 x6 : 00000000ffffffff x5 : 0000000000000000 x4 : 0000000000021000 Purging 5693440 bytes x3 : 000000000000003f x2 : 0000000000000040 x1 : ffff80000990e000 x0 : ffff8000098ed000 Call trace: __dma_inv_area+0x40/0x58 dma_direct_sync_single_for_cpu+0x7c/0x80 dma_direct_unmap_page+0x80/0x88 dma_direct_unmap_sg+0x54/0x80 drm_gem_shmem_free_object+0xfc/0x108 panfrost_gem_free_object+0x118/0x128 [panfrost] drm_gem_object_free+0x18/0x90 drm_gem_object_put_unlocked+0x58/0x80 drm_gem_object_handle_put_unlocked+0x64/0xb0 drm_gem_object_release_handle+0x70/0x98 drm_gem_handle_delete+0x64/0xb0 drm_gem_close_ioctl+0x28/0x38 drm_ioctl_kernel+0xb8/0x110 drm_ioctl+0x244/0x3f0 do_vfs_ioctl+0xbc/0x910 ksys_ioctl+0x78/0xa8 __arm64_sys_ioctl+0x1c/0x28 el0_svc_common.constprop.0+0x88/0x150 el0_svc_handler+0x28/0x78 el0_svc+0x8/0xc Code: 8a230000 54000060 d50b7e20 14000002 (d5087620) Fixes: 17acb9f35ed7 ("drm/shmem: Add madvise state and purge helpers") Cc: Maarten Lankhorst Cc: Maxime Ripard Cc: Sean Paul Cc: David Airlie Cc: Daniel Vetter Signed-off-by: Rob Herring Reviewed-by: Steven Price --- drivers/gpu/drm/drm_gem_shmem_helper.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c index df8f2c8adb2b..5423ec56b535 100644 --- a/drivers/gpu/drm/drm_gem_shmem_helper.c +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c @@ -390,6 +390,12 @@ void drm_gem_shmem_purge_locked(struct drm_gem_object *obj) WARN_ON(!drm_gem_shmem_is_purgeable(shmem)); + dma_unmap_sg(obj->dev->dev, shmem->sgt->sgl, + shmem->sgt->nents, DMA_BIDIRECTIONAL); + sg_free_table(shmem->sgt); + kfree(shmem->sgt); + shmem->sgt = NULL; + drm_gem_shmem_put_pages_locked(shmem); shmem->madv = -1; From patchwork Mon Aug 19 16:12:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring \(Arm\)" X-Patchwork-Id: 171651 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp3197766ily; Mon, 19 Aug 2019 09:12:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqwk0TCyi9a5n3jqxdokkMDFOwIVq1MbxsIBpzV3xk4+7rtq/8pV//SmAhEdPt2bYvbr2y9T X-Received: by 2002:a63:d23:: with SMTP id c35mr20583240pgl.376.1566231136857; Mon, 19 Aug 2019 09:12:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566231136; cv=none; d=google.com; s=arc-20160816; b=m4ZiK1ujXbRq7pnMCtWeVJPv/2Zd5RRMX7tou2IXHj1mVp+3RnN4O+8l6hwM6bk7Qc dx1dM7BljvaghjaJEDLHNMuLjUE0eviSGnALsCKqz8zdalNab5VVFV9jJwdaSyRiTBYq 0fyQSkEmAJi3tTN3sdITx0lXQ1lx//7p5CuiFeNQcugaSVI4YX2TUVDM+82qzsSyf3VX S9pCr4ZZ6sjK9736kTvxc+6PcUOUMbithojXKiRf40v20rhi2iPCQv6ih+Aootix+SMs rJ5xGbZ6gfleWaZ3og7mxYWsw9wBhKbUhewjaHGjzrKRm3ckQereG798IpR7m513hO/9 KMqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:references:in-reply-to:message-id:date :subject:to:from:delivered-to; bh=orjn687kFN+3UrdYU6vYK2sAeYYXRrZEdH4DP6Vlkkc=; b=IE4GvSsuTD3B8/8tf11qk6oy8jv00tYlys2E+dO9CBF9b6nIbxzCih5iP4aSa/07Af 4ldwqsNoeG/Bi1XczKKwp+EjhwK5jt7V4N+8ZWafYcJKF7AJNGsEPHVCdJ57Z499QrSv 0DTB1owG1WD+PTm6CuID5jRhUgf30fNTpLZULCOGoZ593CgxbuKReaPeSEKusI3Dbnyf KhBdntDeloqRBZRLR4SOk+7fG/NVsHqaKxfm4/u2XgczzuuSgDsL6xD+lzNX6JU34MRr 6Ab7EXVzj3RFWavZ/SEX++jFXwadT8DWxE8AMLeDLYMkOWC1XkhZUU6dDs3ZYw1OT16Y FRBw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [2610:10:20:722:a800:ff:fe36:1795]) by mx.google.com with ESMTPS id r185si10927503pfc.105.2019.08.19.09.12.16 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 19 Aug 2019 09:12:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) client-ip=2610:10:20:722:a800:ff:fe36:1795; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5E85B6E20D; Mon, 19 Aug 2019 16:12:13 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-io1-f66.google.com (mail-io1-f66.google.com [209.85.166.66]) by gabe.freedesktop.org (Postfix) with ESMTPS id 058F76E1F4 for ; Mon, 19 Aug 2019 16:12:10 +0000 (UTC) Received: by mail-io1-f66.google.com with SMTP id q22so5488972iog.4 for ; Mon, 19 Aug 2019 09:12:09 -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:in-reply-to :references:mime-version:content-transfer-encoding; bh=PierwHszPjoIfoYM+aQ/lMW44n7AHzmYyHh9ldDk9CQ=; b=X5079FD3uFUD6hm3bBh2J3JeljnCZl8aYNwody9vPGv/qmhvwhSguwROzoB6HeWiu2 qUjY1UL1IG17m1+d+BKIkGlMHKGPDod6892h8LWCSjahloJWi2MQjiULiUeZCDf3XwKT BdSHndYSZtAmD8PBXaVIM64W5Bs+imNOMFklBYvIu5GLQ37SA/6MZh/N9agVmud3KBo4 fv55cfazZrbTyH3VtHp62g6Mh6eNphkmRfuxycNNTQ4GQX3OkkkwqG8RN4ok4qlrnSqQ lcGe52AZFMEvaOx+PyPZq2Fbnw9iK7dAxX7aR07LXc/Mbau71rmywoTnoKt1Ff4D8sZ/ WVSg== X-Gm-Message-State: APjAAAXrvPiqT+kbmRnV0lJ8B7EOfEay+AWbkWZENW7mE919/7quZ2KY WQdlNvURHVgBe9UYXpQopynQ8wU= X-Received: by 2002:a02:3e86:: with SMTP id s128mr25842700jas.14.1566231128961; Mon, 19 Aug 2019 09:12:08 -0700 (PDT) Received: from xps15.herring.priv (24-155-109-49.dyn.grandenetworks.net. [24.155.109.49]) by smtp.googlemail.com with ESMTPSA id c19sm4770584ioi.22.2019.08.19.09.12.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2019 09:12:08 -0700 (PDT) From: Rob Herring To: dri-devel@lists.freedesktop.org Subject: [PATCH 2/4] drm/shmem: Use mutex_trylock in drm_gem_shmem_purge Date: Mon, 19 Aug 2019 11:12:02 -0500 Message-Id: <20190819161204.3106-3-robh@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190819161204.3106-1-robh@kernel.org> References: <20190819161204.3106-1-robh@kernel.org> MIME-Version: 1.0 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: Maxime Ripard , Tomeu Vizoso , David Airlie , Sean Paul , Steven Price , Boris Brezillon , Robin Murphy Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Lockdep reports a circular locking dependency with pages_lock taken in the shrinker callback. The deadlock can't actually happen with current users at least as a BO will never be purgeable when pages_lock is held. To be safe, let's use mutex_trylock() instead and bail if a BO is locked already. WARNING: possible circular locking dependency detected 5.3.0-rc1+ #100 Tainted: G L ------------------------------------------------------ kswapd0/171 is trying to acquire lock: 000000009b9823fd (&shmem->pages_lock){+.+.}, at: drm_gem_shmem_purge+0x20/0x40 but task is already holding lock: 00000000f82369b6 (fs_reclaim){+.+.}, at: __fs_reclaim_acquire+0x0/0x40 which lock already depends on the new lock. the existing dependency chain (in reverse order) is: -> #1 (fs_reclaim){+.+.}: fs_reclaim_acquire.part.18+0x34/0x40 fs_reclaim_acquire+0x20/0x28 __kmalloc_node+0x6c/0x4c0 kvmalloc_node+0x38/0xa8 drm_gem_get_pages+0x80/0x1d0 drm_gem_shmem_get_pages+0x58/0xa0 drm_gem_shmem_get_pages_sgt+0x48/0xd0 panfrost_mmu_map+0x38/0xf8 [panfrost] panfrost_gem_open+0xc0/0xe8 [panfrost] drm_gem_handle_create_tail+0xe8/0x198 drm_gem_handle_create+0x3c/0x50 panfrost_gem_create_with_handle+0x70/0xa0 [panfrost] panfrost_ioctl_create_bo+0x48/0x80 [panfrost] drm_ioctl_kernel+0xb8/0x110 drm_ioctl+0x244/0x3f0 do_vfs_ioctl+0xbc/0x910 ksys_ioctl+0x78/0xa8 __arm64_sys_ioctl+0x1c/0x28 el0_svc_common.constprop.0+0x90/0x168 el0_svc_handler+0x28/0x78 el0_svc+0x8/0xc -> #0 (&shmem->pages_lock){+.+.}: __lock_acquire+0xa2c/0x1d70 lock_acquire+0xdc/0x228 __mutex_lock+0x8c/0x800 mutex_lock_nested+0x1c/0x28 drm_gem_shmem_purge+0x20/0x40 panfrost_gem_shrinker_scan+0xc0/0x180 [panfrost] do_shrink_slab+0x208/0x500 shrink_slab+0x10c/0x2c0 shrink_node+0x28c/0x4d8 balance_pgdat+0x2c8/0x570 kswapd+0x22c/0x638 kthread+0x128/0x130 ret_from_fork+0x10/0x18 other info that might help us debug this: Possible unsafe locking scenario: CPU0 CPU1 ---- ---- lock(fs_reclaim); lock(&shmem->pages_lock); lock(fs_reclaim); lock(&shmem->pages_lock); *** DEADLOCK *** 3 locks held by kswapd0/171: #0: 00000000f82369b6 (fs_reclaim){+.+.}, at: __fs_reclaim_acquire+0x0/0x40 #1: 00000000ceb37808 (shrinker_rwsem){++++}, at: shrink_slab+0xbc/0x2c0 #2: 00000000f31efa81 (&pfdev->shrinker_lock){+.+.}, at: panfrost_gem_shrinker_scan+0x34/0x180 [panfrost] Fixes: 17acb9f35ed7 ("drm/shmem: Add madvise state and purge helpers") Cc: Maarten Lankhorst Cc: Maxime Ripard Cc: Sean Paul Cc: David Airlie Cc: Daniel Vetter Signed-off-by: Rob Herring Reviewed-by: Steven Price --- drivers/gpu/drm/drm_gem_shmem_helper.c | 7 +++++-- include/drm/drm_gem_shmem_helper.h | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c index 5423ec56b535..f5918707672f 100644 --- a/drivers/gpu/drm/drm_gem_shmem_helper.c +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c @@ -415,13 +415,16 @@ void drm_gem_shmem_purge_locked(struct drm_gem_object *obj) } EXPORT_SYMBOL(drm_gem_shmem_purge_locked); -void drm_gem_shmem_purge(struct drm_gem_object *obj) +bool drm_gem_shmem_purge(struct drm_gem_object *obj) { struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj); - mutex_lock(&shmem->pages_lock); + if (!mutex_trylock(&shmem->pages_lock)) + return false; drm_gem_shmem_purge_locked(obj); mutex_unlock(&shmem->pages_lock); + + return true; } EXPORT_SYMBOL(drm_gem_shmem_purge); diff --git a/include/drm/drm_gem_shmem_helper.h b/include/drm/drm_gem_shmem_helper.h index ce1600fdfc3e..01f514521687 100644 --- a/include/drm/drm_gem_shmem_helper.h +++ b/include/drm/drm_gem_shmem_helper.h @@ -134,7 +134,7 @@ static inline bool drm_gem_shmem_is_purgeable(struct drm_gem_shmem_object *shmem } void drm_gem_shmem_purge_locked(struct drm_gem_object *obj); -void drm_gem_shmem_purge(struct drm_gem_object *obj); +bool drm_gem_shmem_purge(struct drm_gem_object *obj); struct drm_gem_shmem_object * drm_gem_shmem_create_with_handle(struct drm_file *file_priv, From patchwork Mon Aug 19 16:12:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring \(Arm\)" X-Patchwork-Id: 171652 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp3197862ily; Mon, 19 Aug 2019 09:12:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqwhPbPG12TDceSgw5MRT5IMibETrKDs+KIFMaNF8YaG1QOqpcM6xVrCJnMHEn+ukqedPqC2 X-Received: by 2002:a65:64c6:: with SMTP id t6mr21114085pgv.323.1566231140943; Mon, 19 Aug 2019 09:12:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566231140; cv=none; d=google.com; s=arc-20160816; b=y8ttjsXJhEGlWpgRjEzgBSNXzMv65gKy8+pikPAU6v5whI3aE1xEjH3JZfMu1bNrj7 SNWqh1cQ2Rmyjq1wh8xvd56V8RGeH012j2Q0cJWxm7Z4gfLAj3uBPqr5YZfOnGE9QDCG WGYJ0ltdJ2CAUOD9U+fRrW0v5R6fjvms3dodssc00ubYy41ElUnAeXM64EmoJdYnL4b2 YqTB4p05lYb6Hlo6hbEcj0vNWJTwDWs5tRviK5w8q+kJNWDDNB40PF4nxd0BnLkxB2uX ikdHSjLVYVhQkX2QQqq9e1+r7MHw/jqlBVU0BGa9LMyx47tlgsTfDvhpLBcDvmkLfpkx X1ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:references:in-reply-to:message-id:date :subject:to:from:delivered-to; bh=7Ce3kzC82tAZE6f54QsKetZJI0N1gyHe5Az0grWSsy4=; b=0v7QNI2JMejvf5aTxe/U+ud40F+acON+0nY4JTLwF1IvPm19PcFcnBzdwCE5HY1+Bx WZa6xajU4BJCkU1oOqOgzbYpElnxU0+SLG3iMpgcolT12C+1VX2GcMzheHP5MX0V+s/w OZlTUHmOFoUl4BmuBKaYjX/qq3f7YVmvRYHAOZykU/+6mkFFa00ruq8kTjytBTVO20J0 kVr22vgF0t17X1HIXypiIzA1cKi56ixDs2QqTqo+ntcxQQ5P59rYszgR5JKMCtQQEVJ5 85G8yfcpwKP6fnK6WF90NhJp7774xxJeB9TZlChF3Sr7FUZTVF2cXzHiwuqV/+16Yllf kBkQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [2610:10:20:722:a800:ff:fe36:1795]) by mx.google.com with ESMTPS id x10si11019362pfj.274.2019.08.19.09.12.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 19 Aug 2019 09:12:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) client-ip=2610:10:20:722:a800:ff:fe36:1795; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E34976E201; Mon, 19 Aug 2019 16:12:19 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-io1-f67.google.com (mail-io1-f67.google.com [209.85.166.67]) by gabe.freedesktop.org (Postfix) with ESMTPS id 418236E1F4 for ; Mon, 19 Aug 2019 16:12:11 +0000 (UTC) Received: by mail-io1-f67.google.com with SMTP id j5so5470058ioj.8 for ; Mon, 19 Aug 2019 09:12:11 -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:in-reply-to :references:mime-version:content-transfer-encoding; bh=lAPAq7xSxjjLTecPqKAR65l3wBupYMfUEeatXDRr6eM=; b=VbJtlTjzG2FH89+pXrfpjLYXOlLkXSmA50hDaNc2AnzG9+YD50bK5RJxDCIvAC4NFo LZuwrM93BX8O9vs6EH9i4alCXHAiw+ufprHFPggbXCu8ix421Cw0P9K2p+3Kx1ajfVhB E7CYfR9Q9uM31x7Z53CKjK9Qm9/vWI+jO7BJC7JX4N2sSNJG5hG3rAPR8dWc4h7lgaXC KKPsP0w/N6uY3mgtf9Bjh2Pvkjqum/XlvAIyEFbRzLIYILQT6Pl5z7Es0tpy1Lwgm+vC KGrnOMR2eH75SuvUR9zOdk7/5JLitqYKjHGdAwrbm4da2kW7EaAB0AGmIdElmT6D+VEz Khug== X-Gm-Message-State: APjAAAVKVN9OZYbOds3oBKb9ahUUhxtckcLoJVBQOwKIyBm4eIKkn0I4 HJIpXZZJbCQy/sDT9lFjFGL0Lmg= X-Received: by 2002:a02:9644:: with SMTP id c62mr27156363jai.45.1566231130158; Mon, 19 Aug 2019 09:12:10 -0700 (PDT) Received: from xps15.herring.priv (24-155-109-49.dyn.grandenetworks.net. [24.155.109.49]) by smtp.googlemail.com with ESMTPSA id c19sm4770584ioi.22.2019.08.19.09.12.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2019 09:12:09 -0700 (PDT) From: Rob Herring To: dri-devel@lists.freedesktop.org Subject: [PATCH 3/4] drm/panfrost: Fix shrinker lockdep issues using drm_gem_shmem_purge() Date: Mon, 19 Aug 2019 11:12:03 -0500 Message-Id: <20190819161204.3106-4-robh@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190819161204.3106-1-robh@kernel.org> References: <20190819161204.3106-1-robh@kernel.org> MIME-Version: 1.0 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: Maxime Ripard , Tomeu Vizoso , David Airlie , Sean Paul , Steven Price , Boris Brezillon , Robin Murphy Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This fixes 2 issues found by lockdep. First, drm_gem_shmem_purge() now uses mutex_trylock for the pages_lock to avoid a circular dependency. Second, it drops the call to panfrost_mmu_unmap() which takes several locks due to runtime PM calls. The call is not necessary because the unmapping is also called in panfrost_gem_close() already. Fixes: 013b65101315 ("drm/panfrost: Add madvise and shrinker support") Cc: Tomeu Vizoso Cc: David Airlie Cc: Daniel Vetter Signed-off-by: Rob Herring --- drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c b/drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c index d191632b6197..cc15005dc68f 100644 --- a/drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c +++ b/drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c @@ -36,17 +36,6 @@ panfrost_gem_shrinker_count(struct shrinker *shrinker, struct shrink_control *sc return count; } -static void panfrost_gem_purge(struct drm_gem_object *obj) -{ - struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj); - mutex_lock(&shmem->pages_lock); - - panfrost_mmu_unmap(to_panfrost_bo(obj)); - drm_gem_shmem_purge_locked(obj); - - mutex_unlock(&shmem->pages_lock); -} - static unsigned long panfrost_gem_shrinker_scan(struct shrinker *shrinker, struct shrink_control *sc) { @@ -61,8 +50,8 @@ panfrost_gem_shrinker_scan(struct shrinker *shrinker, struct shrink_control *sc) list_for_each_entry_safe(shmem, tmp, &pfdev->shrinker_list, madv_list) { if (freed >= sc->nr_to_scan) break; - if (drm_gem_shmem_is_purgeable(shmem)) { - panfrost_gem_purge(&shmem->base); + if (drm_gem_shmem_is_purgeable(shmem) && + drm_gem_shmem_purge(&shmem->base)) { freed += shmem->base.size >> PAGE_SHIFT; list_del_init(&shmem->madv_list); } From patchwork Mon Aug 19 16:12:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring \(Arm\)" X-Patchwork-Id: 171653 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp3197909ily; Mon, 19 Aug 2019 09:12:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqwkrW0qHo3EweUQ0Hv2Ev3C5EjVInAZDkLmUmZ1VzFSlps5IS1+I8twNGj2c9fJHV6XrdbI X-Received: by 2002:a65:68c8:: with SMTP id k8mr20392199pgt.192.1566231142804; Mon, 19 Aug 2019 09:12:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566231142; cv=none; d=google.com; s=arc-20160816; b=gI4N6Jbrk12F6fpYIhq0zpXgx5/yMVTj8Nu3Z4wTKDWqvOjrJlRtmFtmGJwcOilKs1 mN+kCeiVWleM6xZZIhlhH0vYqXdPxnJ6M0bD3gECQz/w9rPcbpXGDQbw+ewOx+fAPGF+ LSXsYNQx6oZeHon0Z3CK+hu7/g84XT4XnoHt3QfooDA74/9L+XDmdcRgk/iWtUH8hTR0 nWOH+AJsqgN0oHhP5svuNxcesidi34emcMBkslKD36x1Qu2PcgPjECUJyghUTqwivwOi xM62nYYNjaZAMoDPbpNxuuq/33UZCtXL4yu7YEqaTjScJ6C20s+KFtRZG+0gX9sG9hAK xJZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:references:in-reply-to:message-id:date :subject:to:from:delivered-to; bh=Hehf3WGywgA9PHGL1xpGcS8tgW3ouqPmyGZAoFEYEEY=; b=WOxY00aOOEuYPu+emaoRFydmRF+2w6aPuIFGDvn0HsnCjzn1VGsUEBcAspudKiGNvd vPPX4HTh0usIiRDCSTEopKQ+DKxj2VQpeEKC/DRAg9M7rtzycL746qFGAp6gpwInK0Nq 6CFS+SXbOCvq4reItcJRAYV5eAWiA6vnMDKvMpuCXJf7cbTSjyDTKaVGNY7fT1CQo+zf QiT/J6DiBGih5Ctia2Op7RE3iZysuR2vKx8IfF7FRGvgUAGdRW8Yr6tHjOUWI8iaWTIh 1R0ke9Nbx/ASxBv4QVv3bh9fjF55JQcsKT/WyeECl2KCXypk9WnHz0oEkws+4tEdm1ZW IaHg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTPS id c10si9968845pgw.174.2019.08.19.09.12.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 19 Aug 2019 09:12:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 26B446E216; Mon, 19 Aug 2019 16:12:20 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-io1-f68.google.com (mail-io1-f68.google.com [209.85.166.68]) by gabe.freedesktop.org (Postfix) with ESMTPS id 913276E1F4 for ; Mon, 19 Aug 2019 16:12:12 +0000 (UTC) Received: by mail-io1-f68.google.com with SMTP id z3so5506617iog.0 for ; Mon, 19 Aug 2019 09:12:12 -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:in-reply-to :references:mime-version:content-transfer-encoding; bh=FNgMoUuANjdtngNMgikfiFN/8UrV/9wNLIuF2chDYhI=; b=q9lXDIUP7RUhEAZWqyJolNk1SSOrD+BAJCUDdffTYI9nTzjFki8mVp58vZ5+RGR4iT 90Hqknvg2jWW7prj+4AufSI7RSKnccT1FcbLKHo93D57lGkMmIw8Yry18Qsjls7Jb9TQ 7nN+dCUh2yYCTVDPkA/+K1hwyI3rkSwtCjaOizIpY6HIgWV97za0k/A+YVOKZ7ZtbLpR bUUrn1TrNI/XosdcNg8Z6WFC2f3OsQrF1PrKi6PZikSYt27rQn5i9g6vKiSTPUHvPUFz 4qJSQ2z8k9bH4gzaJLM2g+sNPjLTtOkrGQDHqajrv1ePumxE5GBTxdOPsjaG7CERmQSe /tPQ== X-Gm-Message-State: APjAAAXDAhTYWurdHXWj2LXg3JO3f2QGU98tLy4WEJUKzF4cpyUKcmSX DsMEhEe7aaLdUWWfp6RQXxHCVvw= X-Received: by 2002:a5d:980d:: with SMTP id a13mr23539456iol.240.1566231131600; Mon, 19 Aug 2019 09:12:11 -0700 (PDT) Received: from xps15.herring.priv (24-155-109-49.dyn.grandenetworks.net. [24.155.109.49]) by smtp.googlemail.com with ESMTPSA id c19sm4770584ioi.22.2019.08.19.09.12.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2019 09:12:10 -0700 (PDT) From: Rob Herring To: dri-devel@lists.freedesktop.org Subject: [PATCH 4/4] drm/panfrost: Fix sleeping while atomic in panfrost_gem_open Date: Mon, 19 Aug 2019 11:12:04 -0500 Message-Id: <20190819161204.3106-5-robh@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190819161204.3106-1-robh@kernel.org> References: <20190819161204.3106-1-robh@kernel.org> MIME-Version: 1.0 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: Maxime Ripard , Tomeu Vizoso , David Airlie , Sean Paul , Steven Price , Boris Brezillon , Robin Murphy Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" We can't hold the mm_lock spinlock as panfrost_mmu_map() can sleep: BUG: sleeping function called from invalid context at kernel/locking/mutex.c:909 in_atomic(): 1, irqs_disabled(): 0, pid: 974, name: glmark2-es2-drm 1 lock held by glmark2-es2-drm/974: CPU: 5 PID: 974 Comm: glmark2-es2-drm Tainted: G W L 5.3.0-rc1+ #94 Hardware name: 96boards Rock960 (DT) Call trace: dump_backtrace+0x0/0x130 show_stack+0x14/0x20 dump_stack+0xc4/0x10c ___might_sleep+0x158/0x228 __might_sleep+0x50/0x88 __mutex_lock+0x58/0x800 mutex_lock_interruptible_nested+0x1c/0x28 drm_gem_shmem_get_pages+0x24/0xa0 drm_gem_shmem_get_pages_sgt+0x48/0xd0 panfrost_mmu_map+0x38/0xf8 [panfrost] panfrost_gem_open+0xc0/0xd8 [panfrost] drm_gem_handle_create_tail+0xe8/0x198 drm_gem_handle_create+0x3c/0x50 panfrost_gem_create_with_handle+0x70/0xa0 [panfrost] panfrost_ioctl_create_bo+0x48/0x80 [panfrost] drm_ioctl_kernel+0xb8/0x110 drm_ioctl+0x244/0x3f0 do_vfs_ioctl+0xbc/0x910 ksys_ioctl+0x78/0xa8 __arm64_sys_ioctl+0x1c/0x28 el0_svc_common.constprop.0+0x90/0x168 el0_svc_handler+0x28/0x78 el0_svc+0x8/0xc Fixes: 68337d0b8644 ("drm/panfrost: Restructure the GEM object creation") Cc: Tomeu Vizoso Cc: David Airlie Cc: Daniel Vetter Signed-off-by: Rob Herring Reviewed-by: Steven Price --- drivers/gpu/drm/panfrost/panfrost_gem.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/panfrost/panfrost_gem.c b/drivers/gpu/drm/panfrost/panfrost_gem.c index e084bc4e9083..acb07fe06580 100644 --- a/drivers/gpu/drm/panfrost/panfrost_gem.c +++ b/drivers/gpu/drm/panfrost/panfrost_gem.c @@ -65,16 +65,18 @@ static int panfrost_gem_open(struct drm_gem_object *obj, struct drm_file *file_p spin_lock(&priv->mm_lock); ret = drm_mm_insert_node_generic(&priv->mm, &bo->node, size >> PAGE_SHIFT, align, color, 0); + spin_unlock(&priv->mm_lock); if (ret) - goto out; + return ret; if (!bo->is_heap) { ret = panfrost_mmu_map(bo); - if (ret) + if (ret) { + spin_lock(&priv->mm_lock); drm_mm_remove_node(&bo->node); + spin_unlock(&priv->mm_lock); + } } -out: - spin_unlock(&priv->mm_lock); return ret; }