From patchwork Thu Aug 9 11:37:09 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: 10561209 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A40EE139A for ; Thu, 9 Aug 2018 11:37:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 954CD2A896 for ; Thu, 9 Aug 2018 11:37:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 89C9D2AC82; Thu, 9 Aug 2018 11:37:39 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 185612A896 for ; Thu, 9 Aug 2018 11:37:39 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E8D2D6E6E7; Thu, 9 Aug 2018 11:37:24 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wm0-x244.google.com (mail-wm0-x244.google.com [IPv6:2a00:1450:400c:c09::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id A238E6E710; Thu, 9 Aug 2018 11:37:19 +0000 (UTC) Received: by mail-wm0-x244.google.com with SMTP id s9-v6so6029609wmh.3; Thu, 09 Aug 2018 04:37:19 -0700 (PDT) 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=5wyUcioXdKNaNsyunWtfcWaE4ByDtUbTfwTbQbE/zIU=; b=OHqr5O/fORhzBgnDktAx4q7Exev1TSwHVHmKuWteYlVLGuyJRjj3/pmRhpdGmJl123 MLjABoOh+QMAP92bnmX2fdN9Dev3Z+FzeIrVBPvnWyW/4MuLCKWtO73iiqd4xYRfJug3 sPW2HWgho9ziqB+OR3QHHrElZ2wcfGw7A4Xs+9Fm2pljAF4QjsceWGZz0Kzo2dj9jV6r wHa+fI3wOK6IOzOPriZTKbmMoWAPCP3rFs96Pd4AkEOmv3iTSber5K5el4Z3MYEAssIP WPljOwBFk3V4ycMpv7lr7Jp3gUCcwLeYYiTwXhQ+BDPYpev9IpacKpeH28iNdubonaIG IHTQ== X-Gm-Message-State: AOUpUlEp/m/xFuM21K4bfI0CbPJhOrb1qrLyCjeKvWM2eTAkNcWoYHg9 jm3jwR3BsKG+T9CFdmG6QJrjLnBI X-Google-Smtp-Source: AA+uWPyoOjrP5GkA/MSF4kFxyS5oo7cXI1hGWnpndb+5NuhMbOnVSyyF9DMyZF62QF9YZjso5+hI8g== X-Received: by 2002:a1c:cbc1:: with SMTP id b184-v6mr1425878wmg.149.1533814637806; Thu, 09 Aug 2018 04:37:17 -0700 (PDT) Received: from baker.fritz.box ([2a02:908:1257:4460:3d33:c568:5cf9:1c03]) by smtp.gmail.com with ESMTPSA id v5-v6sm4734842wru.60.2018.08.09.04.37.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Aug 2018 04:37:17 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: intel-gfx@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Date: Thu, 9 Aug 2018 13:37:09 +0200 Message-Id: <20180809113713.48024-3-christian.koenig@amd.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180809113713.48024-1-christian.koenig@amd.com> References: <20180809113713.48024-1-christian.koenig@amd.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH 2/6] dma-buf: add reservation object shared fence accessor X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP Add a helper to access the shared fences in an reservation object. Signed-off-by: Christian König Reviewed-by: Huang Rui --- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 7 ++----- drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | 3 +-- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 4 ++-- drivers/gpu/drm/msm/msm_gem.c | 4 ++-- drivers/gpu/drm/nouveau/nouveau_fence.c | 3 +-- drivers/gpu/drm/radeon/radeon_sync.c | 3 +-- drivers/gpu/drm/ttm/ttm_bo.c | 4 +--- include/linux/reservation.h | 19 +++++++++++++++++++ 8 files changed, 29 insertions(+), 18 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c index fa38a960ce00..989932234160 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c @@ -238,9 +238,7 @@ static int amdgpu_amdkfd_remove_eviction_fence(struct amdgpu_bo *bo, for (i = 0; i < shared_count; ++i) { struct dma_fence *f; - f = rcu_dereference_protected(fobj->shared[i], - reservation_object_held(resv)); - + f = reservation_object_get_shared_fence(resv, fobj, i); if (ef) { if (f->context == ef->base.context) { dma_fence_put(f); @@ -273,8 +271,7 @@ static int amdgpu_amdkfd_remove_eviction_fence(struct amdgpu_bo *bo, struct dma_fence *f; struct amdgpu_amdkfd_fence *efence; - f = rcu_dereference_protected(fobj->shared[i], - reservation_object_held(resv)); + f = reservation_object_get_shared_fence(resv, fobj, i); efence = to_amdgpu_amdkfd_fence(f); if (efence) { diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c index 2d6f5ec77a68..dbfd62ab67e4 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c @@ -212,8 +212,7 @@ int amdgpu_sync_resv(struct amdgpu_device *adev, return r; for (i = 0; i < flist->shared_count; ++i) { - f = rcu_dereference_protected(flist->shared[i], - reservation_object_held(resv)); + f = reservation_object_get_shared_fence(resv, flist, i); /* We only want to trigger KFD eviction fences on * evict or move jobs. Skip KFD fences otherwise. */ diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c index c6611cff64c8..22896a398eab 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c @@ -1482,8 +1482,8 @@ static bool amdgpu_ttm_bo_eviction_valuable(struct ttm_buffer_object *bo, flist = reservation_object_get_list(bo->resv); if (flist) { for (i = 0; i < flist->shared_count; ++i) { - f = rcu_dereference_protected(flist->shared[i], - reservation_object_held(bo->resv)); + f = reservation_object_get_shared_fence(bo->resv, + flist, i); if (amdkfd_fence_check_mm(f, current->mm)) return false; } diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c index f583bb4222f9..95d25dbfde2b 100644 --- a/drivers/gpu/drm/msm/msm_gem.c +++ b/drivers/gpu/drm/msm/msm_gem.c @@ -651,8 +651,8 @@ int msm_gem_sync_object(struct drm_gem_object *obj, return 0; for (i = 0; i < fobj->shared_count; i++) { - fence = rcu_dereference_protected(fobj->shared[i], - reservation_object_held(msm_obj->resv)); + fence = reservation_object_get_shared_fence(msm_obj->resv, + fobj, i); if (fence->context != fctx->context) { ret = dma_fence_wait(fence, true); if (ret) diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c index 412d49bc6e56..3ce921c276c1 100644 --- a/drivers/gpu/drm/nouveau/nouveau_fence.c +++ b/drivers/gpu/drm/nouveau/nouveau_fence.c @@ -376,8 +376,7 @@ nouveau_fence_sync(struct nouveau_bo *nvbo, struct nouveau_channel *chan, bool e struct nouveau_channel *prev = NULL; bool must_wait = true; - fence = rcu_dereference_protected(fobj->shared[i], - reservation_object_held(resv)); + fence = reservation_object_get_shared_fence(resv, fobj, i); f = nouveau_local_fence(fence, chan->drm); if (f) { diff --git a/drivers/gpu/drm/radeon/radeon_sync.c b/drivers/gpu/drm/radeon/radeon_sync.c index be5d7a38d3aa..bf7f9a648838 100644 --- a/drivers/gpu/drm/radeon/radeon_sync.c +++ b/drivers/gpu/drm/radeon/radeon_sync.c @@ -110,8 +110,7 @@ int radeon_sync_resv(struct radeon_device *rdev, return r; for (i = 0; i < flist->shared_count; ++i) { - f = rcu_dereference_protected(flist->shared[i], - reservation_object_held(resv)); + f = reservation_object_get_shared_fence(resv, flist, i); fence = to_radeon_fence(f); if (fence && fence->rdev == rdev) radeon_sync_fence(sync, fence); diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index 7c484729f9b2..820d97d3e8b9 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -370,9 +370,7 @@ static void ttm_bo_flush_all_fences(struct ttm_buffer_object *bo) dma_fence_enable_sw_signaling(fence); for (i = 0; fobj && i < fobj->shared_count; ++i) { - fence = rcu_dereference_protected(fobj->shared[i], - reservation_object_held(bo->resv)); - + fence = reservation_object_get_shared_fence(bo->resv, fobj, i); if (!fence->ops->signaled) dma_fence_enable_sw_signaling(fence); } diff --git a/include/linux/reservation.h b/include/linux/reservation.h index 54cf6773a14c..8a3298574bf5 100644 --- a/include/linux/reservation.h +++ b/include/linux/reservation.h @@ -140,6 +140,25 @@ reservation_object_get_list(struct reservation_object *obj) reservation_object_held(obj)); } +/** + * reservation_object_get_shared_fence - get a fence from a reservation object's + * shared fence list. + * @obj: the reservation object + * @list: the list to get the fence from + * @idx: the index in the list to get + * + * Returns the fence from the shared fence list. Does NOT take references to + * the fence. Needs to be in RCU context or the obj->lock must be held. + */ +static inline struct dma_fence * +reservation_object_get_shared_fence(struct reservation_object *obj, + struct reservation_object_list *list, + unsigned int idx) +{ + return rcu_dereference_protected(list->shared[idx], + reservation_object_held(obj)); +} + /** * reservation_object_lock - lock the reservation object * @obj: the reservation object