From patchwork Fri Aug 23 02:12:12 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: 172080 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1786ily; Thu, 22 Aug 2019 19:12:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqx2BSHv1h28Bc/PBVlHAA6Ko6dLbXfI1N3q2yAWvo8o+NqklvEt6uNJ0pGvFpXQ/MPfghNF X-Received: by 2002:a65:6904:: with SMTP id s4mr1858324pgq.33.1566526360924; Thu, 22 Aug 2019 19:12:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566526360; cv=none; d=google.com; s=arc-20160816; b=D7iESdV1kcoBENtpneVApSspunhFZ3M6vFGfBbPr5vJ0dHxPhqik7T1PAJI4W2BhQn OCF6wXWXxSvQsoLolD1ino1osvkwE+IGUwEJWLFwdyieVo0zDpHL0PxTba4axcKAiaUE p8awMIQ/ADVcxvNnL1Oi31AB4wYYIsTBbcvF4M61kEv6CZg9kP/b5X7NDI0aCsMUOcXZ mGapKLHHVGC9ARzRw4ros3io4rsGUGgD4pIJ8uAbuo4MKOv5tysI0eAWxP9QPfMv89I4 kCQJWruGzttfSz3InKT3lN5bwccxLVTqIDXtT4dsaz2qt+zMiuUXuFJmBXMn4AhVrY3B 1FbQ== 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=mpBLPkZIj951jHj6RXGuPCGzvi8zgVhic1rAYiAcQ4I=; b=Yqch9MOiTNqw80Cb7iyi+NEIrCh0NJz0S+j3spIV+/Mz1clBxFEHlcjig1aH6xGSjj HWC3KjdVhBks7OOOciWMUOKNXGAKtZk1K4W2N6Nr9NmXg1JSNtQkyH6ScW/38D+3fA07 nuT08v+4LFcT/kAk40ohOtfioHwcCNfQWxQ7OwikoLR/LAerTQe7R96teifVzu7D9Urk PhkwwmM0ISj4GfBrab9FCh+NaTxp8rFmw4q7E8L8MPZSLuM2021Fwsvy6EqnX4kG2viA qnlZ9+1PlU2D24AGI+UIy5WFzuLNiAVLKa51H98uzygfucuNluQqOdx2mbgVPuNWWTul Bh4w== 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 h21si1095720pjq.19.2019.08.22.19.12.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 22 Aug 2019 19:12:40 -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 DB5906EBA9; Fri, 23 Aug 2019 02:12:38 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ot1-f66.google.com (mail-ot1-f66.google.com [209.85.210.66]) by gabe.freedesktop.org (Postfix) with ESMTPS id A02A76EBA3 for ; Fri, 23 Aug 2019 02:12:24 +0000 (UTC) Received: by mail-ot1-f66.google.com with SMTP id b1so7390873otp.6 for ; Thu, 22 Aug 2019 19:12:24 -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=LH1bRwy5I9A+NDROM4NYf/ieDn59EUywDqCfaAShmXM=; b=dbTajU5D2Fjsr/WUIIuiRvwyJeTmOfD9XCz3lJTpQbR9x1FWRuJyVNF07GIlriPqfu R7NwVpkAv2vu2Td+x6N1DZxsxwE6foT45uGR+nNgfx1lkLd22ByMUTobHksc2vEl3f6v wopihC6eL+ih+Hslk8pqoIVTIoSNdKb1USYm7IgLA1lbGehI6d4Ky5UCMvvGVVvtgvM/ H0DsERutzQXWv5KhkSm1agdWSPHvqROyKdcZyIU9pxwjBoul2qyW6if79vHnIR7eh7DB 9QrPNDq9KN8aEzyv9RSWgUBMdcKU6PZVFY1WHY02lYWPe9Hyf3osz35juqXFDqK/9fLL 6UFw== X-Gm-Message-State: APjAAAV9/OWvGQOVZudYjDBKUA83Quy6Jmyc3ys1oxFECTpp0PQG47/V BcsmHwsahRAQnmfggjafEF/haUA= X-Received: by 2002:a9d:645a:: with SMTP id m26mr2091155otl.211.1566526343528; Thu, 22 Aug 2019 19:12:23 -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 c1sm457747oic.31.2019.08.22.19.12.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2019 19:12:22 -0700 (PDT) From: Rob Herring To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 4/8] drm/shmem: Do dma_unmap_sg before purging pages Date: Thu, 22 Aug 2019 21:12:12 -0500 Message-Id: <20190823021216.5862-5-robh@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190823021216.5862-1-robh@kernel.org> References: <20190823021216.5862-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 , Alyssa Rosenzweig , 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 Reviewed-by: Steven Price Signed-off-by: Rob Herring --- 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;