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;