Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp745065imm; Thu, 13 Sep 2018 07:09:03 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZQJQNtLKh/SRmrqqp66GlTtaiF0GYWn4pOEM4b6Z/Ey/hW2X6kM4ffPwyT9XHAUE0hpFgX X-Received: by 2002:a63:344b:: with SMTP id b72-v6mr7430362pga.184.1536847743358; Thu, 13 Sep 2018 07:09:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536847743; cv=none; d=google.com; s=arc-20160816; b=nXxhf4KuKz6k0HBPd879fuiAEtZpcZ9NPVbD2HTCIeeamESDl+XMHL/eevPNLLtTAt RywAS6RFT5s1RQNnj8ErqR3BE7LdfUy/nvVuCkVbl23R/Sf020pGKTTJuSyjR5nNIBSa 1DUB1hAkTzj/ipRW+mUX8M53fYI7AJlPF3wszIUYKqgxwg3IwCOYPleR36ruOxyoUeYf 9txTitUh8qVaJxkhwiNOJTuJ5+XI6ynBWMrY6Kr/He2og0paqlkzzhUmF4sqoI+gAThX Oi7bSsiJyHalQnvpx9MmHZ9i6awgKdMz3cnHwoIpBZNp7rsn5D6OLn4IhoM/hfyOZ2X9 IIWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=/sZdLwIx43OY+wwvBk4HkmlekCgn8fVTV+rfDO05SH0=; b=kHFi+wgVo7EntCM61HriKsDV+pt43lOi5F5YLZiQhye+XWy/yLohx/qypX5ZbyQaqH dSpYF7ZGAHXm02d3efziJCHgtbXsSn9jZtAgLXMo7ql3U9aQyYQdXXSEXsCX/SXeZ6vN BVPAzLkysn5umICHxG82S1YAY+1EbYEgeLnBmCG9023cu7/9peAsxLmywoJp15lM3rJL 1FWpzdluE5SOnSWM39z+NtH23ZkCJpFUF1siUj/NYwPBNqVA5yLN0QDL24oSR1wEnGDH o4hYNYVa3vCGyOQ5s6FXPcOMWGkZsfDsyOEoxzwBClVoSZmISiqaH+i7ZnrAU/Hy3mT0 Zqog== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y8-v6si3456971pll.74.2018.09.13.07.08.23; Thu, 13 Sep 2018 07:09:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732248AbeIMTQ3 (ORCPT + 99 others); Thu, 13 Sep 2018 15:16:29 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:35650 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731408AbeIMTQ2 (ORCPT ); Thu, 13 Sep 2018 15:16:28 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 588DCD36; Thu, 13 Sep 2018 14:06:48 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Christian=20K=C3=B6nig?= , =?UTF-8?q?Michel=20D=C3=A4nzer?= , Alex Deucher Subject: [PATCH 4.18 188/197] drm/amdgpu: Warn and update pin_size values when destroying a pinned BO Date: Thu, 13 Sep 2018 15:32:17 +0200 Message-Id: <20180913131849.079965041@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180913131841.568116777@linuxfoundation.org> References: <20180913131841.568116777@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Michel Dänzer commit 15e6b76880e65be24250e30986084b5569b7a06f upstream. This shouldn't happen, but if it does, we'll get a backtrace of the caller, and update the pin_size values as needed. v2: * Check bo->pin_count instead of placement flags (Christian König) Reviewed-by: Christian König Signed-off-by: Michel Dänzer Signed-off-by: Alex Deucher Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 32 ++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c @@ -50,11 +50,35 @@ static bool amdgpu_need_backup(struct am return true; } +/** + * amdgpu_bo_subtract_pin_size - Remove BO from pin_size accounting + * + * @bo: &amdgpu_bo buffer object + * + * This function is called when a BO stops being pinned, and updates the + * &amdgpu_device pin_size values accordingly. + */ +static void amdgpu_bo_subtract_pin_size(struct amdgpu_bo *bo) +{ + struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev); + + if (bo->tbo.mem.mem_type == TTM_PL_VRAM) { + atomic64_sub(amdgpu_bo_size(bo), &adev->vram_pin_size); + atomic64_sub(amdgpu_vram_mgr_bo_visible_size(bo), + &adev->visible_pin_size); + } else if (bo->tbo.mem.mem_type == TTM_PL_TT) { + atomic64_sub(amdgpu_bo_size(bo), &adev->gart_pin_size); + } +} + static void amdgpu_ttm_bo_destroy(struct ttm_buffer_object *tbo) { struct amdgpu_device *adev = amdgpu_ttm_adev(tbo->bdev); struct amdgpu_bo *bo = ttm_to_amdgpu_bo(tbo); + if (WARN_ON_ONCE(bo->pin_count > 0)) + amdgpu_bo_subtract_pin_size(bo); + if (bo->kfd_bo) amdgpu_amdkfd_unreserve_system_memory_limit(bo); @@ -791,13 +815,7 @@ int amdgpu_bo_unpin(struct amdgpu_bo *bo if (bo->pin_count) return 0; - if (bo->tbo.mem.mem_type == TTM_PL_VRAM) { - atomic64_sub(amdgpu_bo_size(bo), &adev->vram_pin_size); - atomic64_sub(amdgpu_vram_mgr_bo_visible_size(bo), - &adev->visible_pin_size); - } else if (bo->tbo.mem.mem_type == TTM_PL_TT) { - atomic64_sub(amdgpu_bo_size(bo), &adev->gart_pin_size); - } + amdgpu_bo_subtract_pin_size(bo); for (i = 0; i < bo->placement.num_placement; i++) { bo->placements[i].lpfn = 0;