From patchwork Wed Jan 5 14:58:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Matthew Auld X-Patchwork-Id: 12704453 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id D0516C433F5 for ; Wed, 5 Jan 2022 15:00:12 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DD99610FAF0; Wed, 5 Jan 2022 15:00:11 +0000 (UTC) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4433E10FAEB; Wed, 5 Jan 2022 15:00:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641394811; x=1672930811; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=OSxIJSRSInhFk8kjwPPpiwS/B7Rev7Cucs264chyCVU=; b=iBbbdgpfI/fPuyQhAzyH94oZkioOIcEHR8Mh7z4/1OJIkPAGnCUobnHQ spTWygCUr2kpZqGBYeJt54PZOhRLB3XkcHwKRHLvqYxXhUXia5Y4E0WfH s0+tqzEOqpI2I5r6lpbiC52WQ+YMyyfqSHpFRvfqsdsmiIkUCIslPyjjN /+xHMyMeb3v4HF1l+MIGNhqodCojTsYav1jLYHnY6wK2a+2TmCVngAtaR 3ntWIjSVbm5WdVbqe2vScMkVdKprbFTq/6nGKCI70L4QCF1vD4/7FZi1T tEkudPt2pS324UDuE/Iz8+Xuhc3Mkfrv4pM/sxi1ukbX68dTnivKiTpeU w==; X-IronPort-AV: E=McAfee;i="6200,9189,10217"; a="239999783" X-IronPort-AV: E=Sophos;i="5.88,264,1635231600"; d="scan'208";a="239999783" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2022 07:00:10 -0800 X-IronPort-AV: E=Sophos;i="5.88,264,1635231600"; d="scan'208";a="512979153" Received: from unknown (HELO mwauld-desk1.intel.com) ([10.252.26.67]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2022 07:00:09 -0800 From: Matthew Auld To: intel-gfx@lists.freedesktop.org Subject: [PATCH 1/4] drm/i915: don't call free_mmap_offset when purging Date: Wed, 5 Jan 2022 14:58:32 +0000 Message-Id: <20220105145835.142950-1-matthew.auld@intel.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Thomas_Hellstr=C3=B6m?= , dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The TTM backend is in theory the only user here(also purge should only be called once we have dropped the pages), where it is setup at object creation and is only removed once the object is destroyed. Also resetting the node here might be iffy since the ttm fault handler uses the stored fake offset to determine the page offset within the pages array. This also blows up in the dontneed-before-mmap test, since the expectation is that the vma_node will live on, until the object is destroyed: <2> [749.062902] kernel BUG at drivers/gpu/drm/i915/gem/i915_gem_ttm.c:943! <4> [749.062923] invalid opcode: 0000 [#1] PREEMPT SMP NOPTI <4> [749.062928] CPU: 0 PID: 1643 Comm: gem_madvise Tainted: G U W 5.16.0-rc8-CI-CI_DRM_11046+ #1 <4> [749.062933] Hardware name: Gigabyte Technology Co., Ltd. GB-Z390 Garuda/GB-Z390 Garuda-CF, BIOS IG1c 11/19/2019 <4> [749.062937] RIP: 0010:i915_ttm_mmap_offset.cold.35+0x5b/0x5d [i915] <4> [749.063044] Code: 00 48 c7 c2 a0 23 4e a0 48 c7 c7 26 df 4a a0 e8 95 1d d0 e0 bf 01 00 00 00 e8 8b ec cf e0 31 f6 bf 09 00 00 00 e8 5f 30 c0 e0 <0f> 0b 48 c7 c1 24 4b 56 a0 ba 5b 03 00 00 48 c7 c6 c0 23 4e a0 48 <4> [749.063052] RSP: 0018:ffffc90002ab7d38 EFLAGS: 00010246 <4> [749.063056] RAX: 0000000000000240 RBX: ffff88811f2e61c0 RCX: 0000000000000006 <4> [749.063060] RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000009 <4> [749.063063] RBP: ffffc90002ab7e58 R08: 0000000000000001 R09: 0000000000000001 <4> [749.063067] R10: 000000000123d0f8 R11: ffffc90002ab7b20 R12: ffff888112a1a000 <4> [749.063071] R13: 0000000000000004 R14: ffff88811f2e61c0 R15: ffff888112a1a000 <4> [749.063074] FS: 00007f6e5fcad500(0000) GS:ffff8884ad600000(0000) knlGS:0000000000000000 <4> [749.063078] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 <4> [749.063081] CR2: 00007efd264e39f0 CR3: 0000000115fd6005 CR4: 00000000003706f0 <4> [749.063085] Call Trace: <4> [749.063087] <4> [749.063089] __assign_mmap_offset+0x41/0x300 [i915] <4> [749.063171] __assign_mmap_offset_handle+0x159/0x270 [i915] <4> [749.063248] ? i915_gem_dumb_mmap_offset+0x70/0x70 [i915] <4> [749.063325] drm_ioctl_kernel+0xae/0x140 <4> [749.063330] drm_ioctl+0x201/0x3d0 <4> [749.063333] ? i915_gem_dumb_mmap_offset+0x70/0x70 [i915] <4> [749.063409] ? do_user_addr_fault+0x200/0x670 <4> [749.063415] __x64_sys_ioctl+0x6d/0xa0 <4> [749.063419] do_syscall_64+0x3a/0xb0 <4> [749.063423] entry_SYSCALL_64_after_hwframe+0x44/0xae <4> [749.063428] RIP: 0033:0x7f6e5f100317 Testcase: igt@gem_madvise@dontneed-before-mmap Fixes: cf3e3e86d779 ("drm/i915: Use ttm mmap handling for ttm bo's.") Signed-off-by: Matthew Auld Cc: Thomas Hellström Reviewed-by: Thomas Hellström --- drivers/gpu/drm/i915/gem/i915_gem_pages.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_pages.c b/drivers/gpu/drm/i915/gem/i915_gem_pages.c index 89b70f5cde7a..9f429ed6e78a 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_pages.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_pages.c @@ -161,7 +161,6 @@ int i915_gem_object_pin_pages_unlocked(struct drm_i915_gem_object *obj) /* Immediately discard the backing storage */ int i915_gem_object_truncate(struct drm_i915_gem_object *obj) { - drm_gem_free_mmap_offset(&obj->base); if (obj->ops->truncate) return obj->ops->truncate(obj); From patchwork Wed Jan 5 14:58:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Matthew Auld X-Patchwork-Id: 12704454 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 7AC6AC433EF for ; Wed, 5 Jan 2022 15:00:18 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5278F10FAF3; Wed, 5 Jan 2022 15:00:14 +0000 (UTC) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by gabe.freedesktop.org (Postfix) with ESMTPS id 326D410FAF2; Wed, 5 Jan 2022 15:00:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641394812; x=1672930812; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=d9CCjHmx0U5wlstEKtVyc7kks/Y3219jrCGxjBw/lg4=; b=gz2W3zyvTP1bQIz6NfZcOxneL1JsKITthgTH4NSxDHP/s/TgHS+5rH5d otQX2R399cC6yiEwWUZUI15rbbIWjUqwBU0w4dOindKXxjq58IAa68Par KD/O6FzbhfNTgCggOuPQoljpWhm2NAd4FVrXosTajWfD8Oe1wROqta100 WUcl2cLNopAkOepq8J33IHSu7sUn8NImSvaHooY3imZmBPF0WcPuTcP0t kooolhG+DhnSHSOX5yyikqaftSr3KYuokWiWQ2H2s4cho8f6b8LuDgpux aGX+0I1y+WLs01NAxT4hPrF63ijiTq/VSgPii2NifwwIdQnSflMHWD1dg A==; X-IronPort-AV: E=McAfee;i="6200,9189,10217"; a="239999790" X-IronPort-AV: E=Sophos;i="5.88,264,1635231600"; d="scan'208";a="239999790" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2022 07:00:11 -0800 X-IronPort-AV: E=Sophos;i="5.88,264,1635231600"; d="scan'208";a="512979163" Received: from unknown (HELO mwauld-desk1.intel.com) ([10.252.26.67]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2022 07:00:10 -0800 From: Matthew Auld To: intel-gfx@lists.freedesktop.org Subject: [PATCH 2/4] drm/i915/ttm: only fault WILLNEED objects Date: Wed, 5 Jan 2022 14:58:33 +0000 Message-Id: <20220105145835.142950-2-matthew.auld@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220105145835.142950-1-matthew.auld@intel.com> References: <20220105145835.142950-1-matthew.auld@intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Thomas_Hellstr=C3=B6m?= , dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Don't attempt to fault and re-populate purged objects. By some fluke this passes the dontneed-after-mmap IGT, but for the wrong reasons. Fixes: cf3e3e86d779 ("drm/i915: Use ttm mmap handling for ttm bo's.") Signed-off-by: Matthew Auld Cc: Thomas Hellström Reviewed-by: Thomas Hellström --- drivers/gpu/drm/i915/gem/i915_gem_ttm.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c index 923cc7ad8d70..8d61d4538a64 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c @@ -883,6 +883,11 @@ static vm_fault_t vm_fault_ttm(struct vm_fault *vmf) if (ret) return ret; + if (obj->mm.madv != I915_MADV_WILLNEED) { + dma_resv_unlock(bo->base.resv); + return VM_FAULT_SIGBUS; + } + if (drm_dev_enter(dev, &idx)) { ret = ttm_bo_vm_fault_reserved(vmf, vmf->vma->vm_page_prot, TTM_BO_VM_NUM_PREFAULT); From patchwork Wed Jan 5 14:58:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Matthew Auld X-Patchwork-Id: 12704455 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 657A8C43217 for ; Wed, 5 Jan 2022 15:00:22 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B289B10FAF4; Wed, 5 Jan 2022 15:00:15 +0000 (UTC) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by gabe.freedesktop.org (Postfix) with ESMTPS id 828D810FAF8; Wed, 5 Jan 2022 15:00:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641394813; x=1672930813; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MTvPVnisEXbaMTys4ep5X2aJzUPbt+lEaOCT1g6iXCU=; b=OlXu504qbgtsuwJTsYXjw2hn8GkrT9i7KJuk/vfXGXey3QJV0AqgNHDX M4HQyNgtJCe9GFGl8VMr1AaduLCEXGK//sonR0yiHjz2RXwNzoQ/504u2 +0KL/daWlU8cg7mjV8cgcpKd5kazzchOMcJ+EqZwaX+5FtYhqOwH+MNY0 yEQEUXK/Q+IFzaNif2SbJ9pNZH9y7qdvZ17mFU4wAVtJk5HBIkTEVuveg KrjT6DT2JihWz0kYV6NNQsFlYYHTPgil3O+hKRYUobRj94n9acpWWUFYU y8g38LxJK/HaZIeCFXx4Kx6qN5Tt1s7jktsNwzsNV4B5t1pyGd3/2fxos g==; X-IronPort-AV: E=McAfee;i="6200,9189,10217"; a="239999792" X-IronPort-AV: E=Sophos;i="5.88,264,1635231600"; d="scan'208";a="239999792" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2022 07:00:13 -0800 X-IronPort-AV: E=Sophos;i="5.88,264,1635231600"; d="scan'208";a="512979184" Received: from unknown (HELO mwauld-desk1.intel.com) ([10.252.26.67]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2022 07:00:12 -0800 From: Matthew Auld To: intel-gfx@lists.freedesktop.org Subject: [PATCH 3/4] drm/i915/ttm: ensure we unmap when purging Date: Wed, 5 Jan 2022 14:58:34 +0000 Message-Id: <20220105145835.142950-3-matthew.auld@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220105145835.142950-1-matthew.auld@intel.com> References: <20220105145835.142950-1-matthew.auld@intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Thomas_Hellstr=C3=B6m?= , dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Purging can happen during swapping out, or directly invoked with the madvise ioctl. In such cases this doesn't involve a ttm move, which skips umapping the object. Fixes: cf3e3e86d779 ("drm/i915: Use ttm mmap handling for ttm bo's.") Signed-off-by: Matthew Auld Cc: Thomas Hellström --- drivers/gpu/drm/i915/gem/i915_gem_ttm.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c index 8d61d4538a64..f148e7e48f86 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c @@ -399,6 +399,8 @@ int i915_ttm_purge(struct drm_i915_gem_object *obj) if (obj->mm.madv == __I915_MADV_PURGED) return 0; + ttm_bo_unmap_virtual(bo); + ret = ttm_bo_validate(bo, &place, &ctx); if (ret) return ret; From patchwork Wed Jan 5 14:58:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Matthew Auld X-Patchwork-Id: 12704456 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 0F895C433FE for ; Wed, 5 Jan 2022 15:00:24 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 200D910FAF6; Wed, 5 Jan 2022 15:00:16 +0000 (UTC) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by gabe.freedesktop.org (Postfix) with ESMTPS id D9C0410FAF4; Wed, 5 Jan 2022 15:00:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641394814; x=1672930814; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FjouCVZXNKnIEryMdcxAdnjx4vGjZikfT2KUZrNzTiY=; b=Y0oztG4lRh8Mpbq3a3efcA3xZN/lnsbozy90N79SfL8DdPw0vg6l8Mqa 0+cvXt7PpDZOYva+Fo/QWmuBRgK0yhzLsRI323RQt/B8QZaA39IZ71cwi 8/lrxwjqnXpsdnQK0py101vGZBDAZ+pEs5dIeKVA1gT2ULZ330oGtxTSM w2nQvkza16jJATQDbEY5/qN3L+37+KhytOniRnvdxQa0xhL2scr0XHiLb QrTHjtuPIKdApHwVO9IJqxv7pDNok8CEx66OVOYyvDFgZEwJXcMUVeRgb OmeNINzoUh7oOWsC3g+JH/Yni523l9iucCHQ5nKywM8ebfRCS8PrbeuAT Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10217"; a="239999797" X-IronPort-AV: E=Sophos;i="5.88,264,1635231600"; d="scan'208";a="239999797" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2022 07:00:14 -0800 X-IronPort-AV: E=Sophos;i="5.88,264,1635231600"; d="scan'208";a="512979194" Received: from unknown (HELO mwauld-desk1.intel.com) ([10.252.26.67]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2022 07:00:13 -0800 From: Matthew Auld To: intel-gfx@lists.freedesktop.org Subject: [PATCH 4/4] drm/i915/ttm: ensure we unmap when shrinking Date: Wed, 5 Jan 2022 14:58:35 +0000 Message-Id: <20220105145835.142950-4-matthew.auld@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220105145835.142950-1-matthew.auld@intel.com> References: <20220105145835.142950-1-matthew.auld@intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Thomas_Hellstr=C3=B6m?= , dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Assuming we don't purge the pages, but instead swap them out then we need to ensure we also unmap the object. Fixes: 7ae034590cea ("drm/i915/ttm: add tt shmem backend") Signed-off-by: Matthew Auld Cc: Thomas Hellström --- drivers/gpu/drm/i915/gem/i915_gem_ttm.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c index f148e7e48f86..adbbd57bb9bf 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c @@ -462,6 +462,8 @@ static int i915_ttm_shrinker_release_pages(struct drm_i915_gem_object *obj, if (bo->ttm->page_flags & TTM_TT_FLAG_SWAPPED) return 0; + ttm_bo_unmap_virtual(bo); + bo->ttm->page_flags |= TTM_TT_FLAG_SWAPPED; ret = ttm_bo_validate(bo, &place, &ctx); if (ret) {