From patchwork Tue Oct 7 17:11:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michel Thierry X-Patchwork-Id: 5047841 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C05CCC11AB for ; Tue, 7 Oct 2014 17:12:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B2D3A20220 for ; Tue, 7 Oct 2014 17:12:32 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 9B1BC201F7 for ; Tue, 7 Oct 2014 17:12:31 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CD6896E0DA; Tue, 7 Oct 2014 10:12:29 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by gabe.freedesktop.org (Postfix) with ESMTP id 655926E1C9 for ; Tue, 7 Oct 2014 10:12:28 -0700 (PDT) Received: from azsmga001.ch.intel.com ([10.2.17.19]) by orsmga102.jf.intel.com with ESMTP; 07 Oct 2014 10:05:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.04,671,1406617200"; d="scan'208";a="482578236" Received: from michelth-linux.isw.intel.com ([10.102.226.151]) by azsmga001.ch.intel.com with ESMTP; 07 Oct 2014 10:11:59 -0700 From: Michel Thierry To: intel-gfx@lists.freedesktop.org Date: Tue, 7 Oct 2014 18:11:32 +0100 Message-Id: <1412701894-28905-37-git-send-email-michel.thierry@intel.com> X-Mailer: git-send-email 2.0.3 In-Reply-To: <1412701894-28905-1-git-send-email-michel.thierry@intel.com> References: <1412701894-28905-1-git-send-email-michel.thierry@intel.com> Subject: [Intel-gfx] [RFC 36/38] drm/i915/bdw: begin bitmap tracking X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Ben Widawsky Like with gen6/7, we can enable bitmap tracking with all the preallocations to make sure things actually don't blow up. Signed-off-by: Ben Widawsky Signed-off-by: Michel Thierry --- drivers/gpu/drm/i915/i915_gem_gtt.c | 101 +++++++++++++++++++++++++++++++----- drivers/gpu/drm/i915/i915_gem_gtt.h | 12 +++++ 2 files changed, 99 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c index 9403c60..6703721 100644 --- a/drivers/gpu/drm/i915/i915_gem_gtt.c +++ b/drivers/gpu/drm/i915/i915_gem_gtt.c @@ -352,8 +352,12 @@ err_out: static void __free_pd_single(struct i915_pagedir *pd, struct drm_device *dev) { + WARN(!bitmap_empty(pd->used_pdes, I915_PDES_PER_PD), + "Free page directory with %d used pages\n", + bitmap_weight(pd->used_pdes, I915_PDES_PER_PD)); i915_dma_unmap_single(pd, dev); __free_page(pd->page); + kfree(pd->used_pdes); kfree(pd); } @@ -366,26 +370,35 @@ static void __free_pd_single(struct i915_pagedir *pd, struct drm_device *dev) static struct i915_pagedir *alloc_pd_single(struct drm_device *dev) { struct i915_pagedir *pd; - int ret; + int ret = -ENOMEM; pd = kzalloc(sizeof(*pd), GFP_KERNEL); if (!pd) return ERR_PTR(-ENOMEM); + pd->used_pdes = kcalloc(BITS_TO_LONGS(I915_PDES_PER_PD), + sizeof(*pd->used_pdes), GFP_KERNEL); + if (!pd->used_pdes) + goto free_pd; + pd->page = alloc_page(GFP_KERNEL | __GFP_ZERO); - if (!pd->page) { - kfree(pd); - return ERR_PTR(-ENOMEM); - } + if (!pd->page) + goto free_bitmap; ret = i915_dma_map_px_single(pd, dev); - if (ret) { - __free_page(pd->page); - kfree(pd); - return ERR_PTR(ret); - } + if (ret) + goto free_page; return pd; + +free_page: + __free_page(pd->page); +free_bitmap: + kfree(pd->used_pdes); +free_pd: + kfree(pd); + + return ERR_PTR(ret); } /* Broadwell Page Directory Pointer Descriptors */ @@ -566,12 +579,48 @@ static void gen8_teardown_va_range(struct i915_address_space *vm, gen8_for_each_pdpe(pd, &ppgtt->pdp, start, length, temp, pdpe) { uint64_t pd_len = gen8_clamp_pd(start, length); uint64_t pd_start = start; + + /* Page directories might not be present since the macro rounds + * down, and up. + */ + if (!pd) { + WARN(test_bit(pdpe, ppgtt->pdp.used_pdpes), + "PDPE %d is not allocated, but is reserved (%p)\n", + pdpe, vm); + continue; + } else { + WARN(!test_bit(pdpe, ppgtt->pdp.used_pdpes), + "PDPE %d not reserved, but is allocated (%p)", + pdpe, vm); + } + gen8_for_each_pde(pt, pd, pd_start, pd_len, temp, pde) { - free_pt_single(pt, vm->dev); - pd->page_tables[pde] = NULL; + if (!pt) { + WARN(test_bit(pde, pd->used_pdes), + "PDE %d is not allocated, but is reserved (%p)\n", + pde, vm); + continue; + } else + WARN(!test_bit(pde, pd->used_pdes), + "PDE %d not reserved, but is allocated (%p)", + pde, vm); + + bitmap_clear(pt->used_ptes, + gen8_pte_index(pd_start), + gen8_pte_count(pd_start, pd_len)); + + if (bitmap_empty(pt->used_ptes, GEN8_PTES_PER_PT)) { + free_pt_single(pt, vm->dev); + pd->page_tables[pde] = NULL; + WARN_ON(!test_and_clear_bit(pde, pd->used_pdes)); + } + } + + if (bitmap_empty(pd->used_pdes, I915_PDES_PER_PD)) { + free_pd_single(pd, vm->dev); + ppgtt->pdp.pagedirs[pdpe] = NULL; + WARN_ON(!test_and_clear_bit(pdpe, ppgtt->pdp.used_pdpes)); } - free_pd_single(pd, vm->dev); - ppgtt->pdp.pagedirs[pdpe] = NULL; } } @@ -614,6 +663,7 @@ unwind_out: return -ENOMEM; } +/* bitmap of new pagedirs */ static int gen8_ppgtt_alloc_pagedirs(struct i915_pagedirpo *pdp, uint64_t start, uint64_t length, @@ -629,6 +679,7 @@ static int gen8_ppgtt_alloc_pagedirs(struct i915_pagedirpo *pdp, gen8_for_each_pdpe(unused, pdp, start, length, temp, pdpe) { BUG_ON(unused); pdp->pagedirs[pdpe] = alloc_pd_single(dev); + if (IS_ERR(pdp->pagedirs[pdpe])) goto unwind_out; } @@ -650,10 +701,12 @@ static int gen8_alloc_va_range(struct i915_address_space *vm, container_of(vm, struct i915_hw_ppgtt, base); struct i915_pagedir *pd; const uint64_t orig_start = start; + const uint64_t orig_length = length; uint64_t temp; uint32_t pdpe; int ret; + /* Do the allocations first so we can easily bail out */ ret = gen8_ppgtt_alloc_pagedirs(&ppgtt->pdp, start, length, ppgtt->base.dev); if (ret) @@ -666,6 +719,26 @@ static int gen8_alloc_va_range(struct i915_address_space *vm, goto err_out; } + /* Now mark everything we've touched as used. This doesn't allow for + * robust error checking, but it makes the code a hell of a lot simpler. + */ + start = orig_start; + length = orig_length; + + gen8_for_each_pdpe(pd, &ppgtt->pdp, start, length, temp, pdpe) { + struct i915_pagetab *pt; + uint64_t pd_len = gen8_clamp_pd(start, length); + uint64_t pd_start = start; + uint32_t pde; + gen8_for_each_pde(pt, &ppgtt->pd, pd_start, pd_len, temp, pde) { + bitmap_set(pd->page_tables[pde]->used_ptes, + gen8_pte_index(start), + gen8_pte_count(start, length)); + set_bit(pde, pd->used_pdes); + } + set_bit(pdpe, ppgtt->pdp.used_pdpes); + } + return 0; err_out: diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.h b/drivers/gpu/drm/i915/i915_gem_gtt.h index da27cc4..120f213 100644 --- a/drivers/gpu/drm/i915/i915_gem_gtt.h +++ b/drivers/gpu/drm/i915/i915_gem_gtt.h @@ -193,11 +193,13 @@ struct i915_pagedir { dma_addr_t daddr; }; + unsigned long *used_pdes; struct i915_pagetab *page_tables[I915_PDES_PER_PD]; }; struct i915_pagedirpo { /* struct page *page; */ + DECLARE_BITMAP(used_pdpes, GEN8_LEGACY_PDPES); struct i915_pagedir *pagedirs[GEN8_LEGACY_PDPES]; }; @@ -459,6 +461,16 @@ static inline uint32_t gen8_pml4e_index(uint64_t address) BUG(); } +static inline size_t gen8_pte_count(uint64_t addr, uint64_t length) +{ + return i915_pte_count(addr, length, GEN8_PDE_SHIFT); +} + +static inline size_t gen8_pde_count(uint64_t addr, uint64_t length) +{ + return i915_pde_count(addr, length, GEN8_PDE_SHIFT); +} + int i915_gem_gtt_init(struct drm_device *dev); void i915_gem_init_global_gtt(struct drm_device *dev); int i915_gem_setup_global_gtt(struct drm_device *dev, unsigned long start,