From patchwork Fri Jan 12 09:47:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 10160901 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0225360327 for ; Fri, 12 Jan 2018 13:58:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E3E23288B2 for ; Fri, 12 Jan 2018 13:58:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D8BEE288B6; Fri, 12 Jan 2018 13:58:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5C830288B2 for ; Fri, 12 Jan 2018 13:58:02 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 236096E50F; Fri, 12 Jan 2018 13:58:01 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr0-x243.google.com (mail-wr0-x243.google.com [IPv6:2a00:1450:400c:c0c::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id 842796E50F for ; Fri, 12 Jan 2018 13:57:59 +0000 (UTC) Received: by mail-wr0-x243.google.com with SMTP id f8so5387068wre.4 for ; Fri, 12 Jan 2018 05:57:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=MDgiwmmKdQR0r4vwoWXXcBaCN1/EVdiUJ4q65Bj+qFI=; b=jmyKCAzNL9P9uaomEM3qh3ZDj341tGtzvn2zXoswZhCjFmmzN+wz258krLVNyTg7vq 4cMhZMwfHbh6VBR8hsAwHLIgaP4j+V/cy3UCj1CZMmVyRbxqXxEpPScHVY4mcJ8ZSYZ5 L0ybR6ATr0ZqgGjPYpciLsHhBpyWobHdr7wCXoCTe7j7S3DkmbLl3XaAOMg2dlepej7A bMbaQi+XJ+jksp6bcFRgq3kb4uXt3jkw4DXaUB2+x4PExKHtkXJRx8cbIl4yHIGRLFNm zoc2SoYLCTkdg7LgMT46KZpCvMYPdpvZ7l3ZLNepH5Cax/w4BJoiWEXEpfVJGG/58oyC GEgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MDgiwmmKdQR0r4vwoWXXcBaCN1/EVdiUJ4q65Bj+qFI=; b=eDlL2JgLRlND8FdBjqxBll02icaLESORA5utQyBUpgnkAf3sYJq8OjddEcwVItA63G rJPj1jJoLF1lb8Acz0x04DtZfOeJKPs3c7XJY0u5Yc5DSFuYyFJ+/Fq9z67sEdFFcUto Nql4SABdYnkmXoCuel+MYZBpthMUFGHi7/13kenS7Z3YhVyo+eFyF1/enDxcE2BuuBHb O5LaQyapZM6uuE8C91xyxkmYdxr9Hxr31jAqqA4sS+wyCLpsfaGUaKPABxN1Xxe2JlVc /nHsM5iA2KZ+C8S0wHhXeXuYC4kxzhz2sk86hig72VG721hYcIJAOKhxiwW6pniOUKnN gsiw== X-Gm-Message-State: AKGB3mJXioGUyeX7N2dponwXUjHtOZ4i/gBeoOslMB8iUOltUZENmIY+ tnmTKkWZBpDPUmCRgN0dyR+z+A== X-Google-Smtp-Source: ACJfBouRBGu1LaRUsnjZjK3ZErcvF0HAbu84/F3xmWDcL2eMs+QEE0TpOmKcifiP/GyTkfcKpcktoA== X-Received: by 10.223.192.134 with SMTP id d6mr18877982wrf.206.1515750453353; Fri, 12 Jan 2018 01:47:33 -0800 (PST) Received: from baker.fritz.box ([2a02:908:1251:8fc0:6d3c:530f:8e94:9257]) by smtp.gmail.com with ESMTPSA id p10sm16616345wrh.61.2018.01.12.01.47.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Jan 2018 01:47:32 -0800 (PST) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?UTF-8?q?Christian=20K=C3=B6nig?= To: daniel@ffwll.ch, sumit.semwal@linaro.org, gustavo@padovan.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org Subject: [PATCH 3/3] drm/amdgpu: always allocate a PASIDs for each VM v2 Date: Fri, 12 Jan 2018 10:47:29 +0100 Message-Id: <20180112094729.17491-3-christian.koenig@amd.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180112094729.17491-1-christian.koenig@amd.com> References: <20180112094729.17491-1-christian.koenig@amd.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Start to always allocate a pasid for each VM. v2: use dev_warn when we run out of PASIDs Signed-off-by: Christian König --- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 43 ++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c index 5773a581761b..a108b30d8186 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c @@ -805,7 +805,7 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv) { struct amdgpu_device *adev = dev->dev_private; struct amdgpu_fpriv *fpriv; - int r; + int r, pasid; file_priv->driver_priv = NULL; @@ -819,28 +819,25 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv) goto out_suspend; } - r = amdgpu_vm_init(adev, &fpriv->vm, - AMDGPU_VM_CONTEXT_GFX, 0); - if (r) { - kfree(fpriv); - goto out_suspend; + pasid = amdgpu_pasid_alloc(16); + if (pasid < 0) { + dev_warn(adev->dev, "No more PASIDs available!"); + pasid = 0; } + r = amdgpu_vm_init(adev, &fpriv->vm, AMDGPU_VM_CONTEXT_GFX, pasid); + if (r) + goto error_pasid; fpriv->prt_va = amdgpu_vm_bo_add(adev, &fpriv->vm, NULL); if (!fpriv->prt_va) { r = -ENOMEM; - amdgpu_vm_fini(adev, &fpriv->vm); - kfree(fpriv); - goto out_suspend; + goto error_vm; } if (amdgpu_sriov_vf(adev)) { r = amdgpu_map_static_csa(adev, &fpriv->vm, &fpriv->csa_va); - if (r) { - amdgpu_vm_fini(adev, &fpriv->vm); - kfree(fpriv); - goto out_suspend; - } + if (r) + goto error_vm; } mutex_init(&fpriv->bo_list_lock); @@ -849,6 +846,16 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv) amdgpu_ctx_mgr_init(&fpriv->ctx_mgr); file_priv->driver_priv = fpriv; + goto out_suspend; + +error_vm: + amdgpu_vm_fini(adev, &fpriv->vm); + +error_pasid: + if (pasid) + amdgpu_pasid_free(pasid); + + kfree(fpriv); out_suspend: pm_runtime_mark_last_busy(dev->dev); @@ -871,6 +878,8 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev, struct amdgpu_device *adev = dev->dev_private; struct amdgpu_fpriv *fpriv = file_priv->driver_priv; struct amdgpu_bo_list *list; + struct amdgpu_bo *pd; + unsigned int pasid; int handle; if (!fpriv) @@ -895,7 +904,13 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev, amdgpu_bo_unreserve(adev->virt.csa_obj); } + pasid = fpriv->vm.pasid; + pd = amdgpu_bo_ref(fpriv->vm.root.base.bo); + amdgpu_vm_fini(adev, &fpriv->vm); + if (pasid) + amdgpu_pasid_free_delayed(pd->tbo.resv, pasid); + amdgpu_bo_unref(&pd); idr_for_each_entry(&fpriv->bo_list_handles, list, handle) amdgpu_bo_list_free(list);