From patchwork Wed May 27 03:19:52 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alex Deucher X-Patchwork-Id: 6486801 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 751689F38C for ; Wed, 27 May 2015 03:21:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7F3C920706 for ; Wed, 27 May 2015 03:21:08 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 9074D206FC for ; Wed, 27 May 2015 03:21:07 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 19DF66E8E8; Tue, 26 May 2015 20:21:02 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qc0-f181.google.com (mail-qc0-f181.google.com [209.85.216.181]) by gabe.freedesktop.org (Postfix) with ESMTP id A92376E8D7 for ; Tue, 26 May 2015 20:20:49 -0700 (PDT) Received: by qcxw10 with SMTP id w10so2526137qcx.3 for ; Tue, 26 May 2015 20:20:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=JdkDn72g8yV19BHqkFY2D/qke/2ViIxvsi8XthsAtEY=; b=yVYMkeZmjDoBKCyoNOPd/t8WgFh07I59VSl+Jm2ypQh+3VfcnVCPZ9kmPykNNOni8Z t/9sIOdo4JjeZlNz3e0Neo85eAMAns5dR837hzDp+V0ic/u+eEEAWNJm5Wj2NzaMfikG bxxg+bdJk3g6o8VJavxABhMm6S5v1GTLMeMGUAyfOe5adUMOz6UcxFIZKqyNL/Xb3e30 Pys3wdb7sWk9WJOCTcwOiVrPJrSKCnrEV7nf32veTxToND9mmPTiBbvNyyf3kKcvsfXj gJ/hnKYlW7Jz3aqgXHouDDYngLTpn+EPsliXGELJIJ2Dbt9vq6ddJ09fyLB/FvhA9HMn UIOA== X-Received: by 10.55.19.12 with SMTP id d12mr37425187qkh.89.1432696849383; Tue, 26 May 2015 20:20:49 -0700 (PDT) Received: from localhost.localdomain (static-74-96-105-49.washdc.fios.verizon.net. [74.96.105.49]) by mx.google.com with ESMTPSA id 20sm9629127qhf.14.2015.05.26.20.20.48 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 May 2015 20:20:49 -0700 (PDT) From: Alex Deucher X-Google-Original-From: Alex Deucher To: dri-devel@lists.freedesktop.org Subject: [PATCH 53/88] drm/amdgpu: make the CTX ioctl thread-safe Date: Tue, 26 May 2015 23:19:52 -0400 Message-Id: <1432696827-3752-23-git-send-email-alexander.deucher@amd.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1432696827-3752-1-git-send-email-alexander.deucher@amd.com> References: <1432696827-3752-1-git-send-email-alexander.deucher@amd.com> MIME-Version: 1.0 Cc: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= 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-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, 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: Marek Olšák The existing locks were protecting the list, but not the elements. v2: rename hlock to lock Signed-off-by: Marek Olšák Reviewed-by: Christian König Reviewed-by: Jammy Zhou --- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 20 ++++++++++---------- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h index 65246abc..cef3a43 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h @@ -1056,7 +1056,7 @@ struct amdgpu_ctx_mgr { struct amdgpu_device *adev; struct idr ctx_handles; /* lock for IDR system */ - struct mutex hlock; + struct mutex lock; }; /* diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c index ffb13a6..0dc3a4e 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c @@ -33,9 +33,7 @@ static void amdgpu_ctx_do_release(struct kref *ref) ctx = container_of(ref, struct amdgpu_ctx, refcount); mgr = &ctx->fpriv->ctx_mgr; - mutex_lock(&mgr->hlock); idr_remove(&mgr->ctx_handles, ctx->id); - mutex_unlock(&mgr->hlock); kfree(ctx); } @@ -49,20 +47,20 @@ int amdgpu_ctx_alloc(struct amdgpu_device *adev, struct amdgpu_fpriv *fpriv, uin if (!ctx) return -ENOMEM; - mutex_lock(&mgr->hlock); + mutex_lock(&mgr->lock); r = idr_alloc(&mgr->ctx_handles, ctx, 0, 0, GFP_KERNEL); if (r < 0) { - mutex_unlock(&mgr->hlock); + mutex_unlock(&mgr->lock); kfree(ctx); return r; } - mutex_unlock(&mgr->hlock); *id = (uint32_t)r; memset(ctx, 0, sizeof(*ctx)); ctx->id = *id; ctx->fpriv = fpriv; kref_init(&ctx->refcount); + mutex_unlock(&mgr->lock); return 0; } @@ -72,13 +70,14 @@ int amdgpu_ctx_free(struct amdgpu_device *adev, struct amdgpu_fpriv *fpriv, uint struct amdgpu_ctx *ctx; struct amdgpu_ctx_mgr *mgr = &fpriv->ctx_mgr; - rcu_read_lock(); + mutex_lock(&mgr->lock); ctx = idr_find(&mgr->ctx_handles, id); - rcu_read_unlock(); if (ctx) { kref_put(&ctx->refcount, amdgpu_ctx_do_release); + mutex_unlock(&mgr->lock); return 0; } + mutex_unlock(&mgr->lock); return -EINVAL; } @@ -87,14 +86,15 @@ int amdgpu_ctx_query(struct amdgpu_device *adev, struct amdgpu_fpriv *fpriv, uin struct amdgpu_ctx *ctx; struct amdgpu_ctx_mgr *mgr = &fpriv->ctx_mgr; - rcu_read_lock(); + mutex_lock(&mgr->lock); ctx = idr_find(&mgr->ctx_handles, id); - rcu_read_unlock(); if (ctx) { /* state should alter with CS activity */ *state = ctx->state; + mutex_unlock(&mgr->lock); return 0; } + mutex_unlock(&mgr->lock); return -EINVAL; } @@ -111,7 +111,7 @@ void amdgpu_ctx_fini(struct amdgpu_fpriv *fpriv) DRM_ERROR("ctx (id=%ul) is still alive\n",ctx->id); } - mutex_destroy(&mgr->hlock); + mutex_destroy(&mgr->lock); } int amdgpu_ctx_ioctl(struct drm_device *dev, void *data, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c index 2d50c6d..02c450d 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c @@ -497,7 +497,7 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv) idr_init(&fpriv->bo_list_handles); /* init context manager */ - mutex_init(&fpriv->ctx_mgr.hlock); + mutex_init(&fpriv->ctx_mgr.lock); idr_init(&fpriv->ctx_mgr.ctx_handles); fpriv->ctx_mgr.adev = adev;