From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B00B5C7EE29 for ; Tue, 23 May 2023 09:47:56 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8F97110E424; Tue, 23 May 2023 09:47:56 +0000 (UTC) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6F0E910E424 for ; Tue, 23 May 2023 09:47:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1684835272; x=1716371272; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Uiw2HzYNc8rUcgcaeKLrP/DUEy20yrRHl1U7bj6Z1ZE=; b=faw+aQ6kScGnysTOnvWTEYnZHp16h3EeA3Pk/GOySBmfpegxmvoTTSpX FRbJdSBHTP8WpX9NcD49Hp+lU73pAK19IKNu5WM2IGhiyakDxXZ5asv00 csW5p+Z7glf/oRqfNNlPB3RH2kjebsFJWMU4kHTDaDyxyFg6BLRZIucCz HAuwIZ+UDHvGk7DpugoLfKCqVjrISxkjhvShiz5uBA8A/umI6SesNghL5 sYSzhH1NI5qgWFE2oyMCZEgnBx60XmBtTWO822MxJbg4JojgOxqLb1ilG kp4xzSVVck12affIp76aSzDrKoIx01Qlr5eaPc9Xw4ykU6LS/39lC5C/c A==; X-IronPort-AV: E=McAfee;i="6600,9927,10718"; a="337777479" X-IronPort-AV: E=Sophos;i="6.00,185,1681196400"; d="scan'208";a="337777479" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 May 2023 02:47:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10718"; a="736797332" X-IronPort-AV: E=Sophos;i="6.00,185,1681196400"; d="scan'208";a="736797332" Received: from eakeogh-mobl1.ger.corp.intel.com (HELO mwauld-desk1.intel.com) ([10.252.0.142]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 May 2023 02:47:49 -0700 From: Matthew Auld To: intel-xe@lists.freedesktop.org Date: Tue, 23 May 2023 10:47:27 +0100 Message-Id: <20230523094727.162266-8-matthew.auld@intel.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230523094727.162266-1-matthew.auld@intel.com> References: <20230523094727.162266-1-matthew.auld@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Intel-xe] [PATCH v9 8/8] drm/xe: Use atomic for mem_access.ref X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rodrigo Vivi Errors-To: intel-xe-bounces@lists.freedesktop.org Sender: "Intel-xe" From: Maarten Lankhorst xe_guc_ct_fast_path() is called from an irq context, and cannot lock the mutex used by xe_device_mem_access_ongoing(). Fortunately it is easy to fix if we switch the ref over to an atomic. Signed-off-by: Maarten Lankhorst Signed-off-by: Matthew Auld Cc: Rodrigo Vivi Cc: Thomas Hellström Cc: Matthew Brost Reviewed-by: Rodrigo Vivi --- drivers/gpu/drm/xe/xe_device.c | 34 ++++++++++++---------------- drivers/gpu/drm/xe/xe_device_types.h | 6 ++--- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c index ac11cd7c3b67..b69fefbac845 100644 --- a/drivers/gpu/drm/xe/xe_device.c +++ b/drivers/gpu/drm/xe/xe_device.c @@ -412,30 +412,23 @@ u32 xe_device_ccs_bytes(struct xe_device *xe, u64 size) DIV_ROUND_UP(size, NUM_BYTES_PER_CCS_BYTE) : 0; } -void xe_device_assert_mem_access(struct xe_device *xe) -{ - if (xe_pm_read_callback_task(xe) == current) - return; - - XE_WARN_ON(!xe->mem_access.ref); -} - bool xe_device_mem_access_ongoing(struct xe_device *xe) { - bool ret; - if (xe_pm_read_callback_task(xe) == current) return true; - mutex_lock(&xe->mem_access.lock); - ret = xe->mem_access.ref; - mutex_unlock(&xe->mem_access.lock); + return atomic_read(&xe->mem_access.ref); +} - return ret; +void xe_device_assert_mem_access(struct xe_device *xe) +{ + XE_WARN_ON(!xe_device_mem_access_ongoing(xe)); } void xe_device_mem_access_get(struct xe_device *xe) { + int ref; + /* * This looks racy, but should be fine since the pm_callback_task only * transitions from NULL -> current (and back to NULL again), during the @@ -455,23 +448,26 @@ void xe_device_mem_access_get(struct xe_device *xe) * for example just on the 0 -> 1. */ mutex_lock(&xe->mem_access.lock); - if (xe->mem_access.ref == 0) + if (atomic_read(&xe->mem_access.ref) == 0) xe->mem_access.hold_rpm = xe_pm_runtime_resume_and_get(xe); - xe->mem_access.ref++; + ref = atomic_inc_return(&xe->mem_access.ref); mutex_unlock(&xe->mem_access.lock); - XE_WARN_ON(xe->mem_access.ref == S32_MAX); + XE_WARN_ON(ref == S32_MAX); } void xe_device_mem_access_put(struct xe_device *xe) { + int ref; + if (xe_pm_read_callback_task(xe) == current) return; mutex_lock(&xe->mem_access.lock); - if (--xe->mem_access.ref == 0 && xe->mem_access.hold_rpm) + ref = atomic_dec_return(&xe->mem_access.ref); + if (ref == 0 && xe->mem_access.hold_rpm) xe_pm_runtime_put(xe); mutex_unlock(&xe->mem_access.lock); - XE_WARN_ON(xe->mem_access.ref < 0); + XE_WARN_ON(ref < 0); } diff --git a/drivers/gpu/drm/xe/xe_device_types.h b/drivers/gpu/drm/xe/xe_device_types.h index b5a56e112c0a..f1515aff8437 100644 --- a/drivers/gpu/drm/xe/xe_device_types.h +++ b/drivers/gpu/drm/xe/xe_device_types.h @@ -261,9 +261,9 @@ struct xe_device { */ struct { /** - * @lock: Protects @ref and serializes multiple callers. + * @lock: Serializes multiple callers. * - * Also used as lockdep aid to hopefully ensure that it sees + * But mainly used as lockdep aid to hopefully ensure that it sees * that the runtime_pm callbacks can be called while holding * @lock, and therefore any locks that the caller is holding * also have a clear dependency on the @lock and any locks the @@ -274,7 +274,7 @@ struct xe_device { */ struct mutex lock; /** @ref: ref count of memory accesses */ - s32 ref; + atomic_t ref; /** @hold_rpm: need to put rpm ref back at the end */ bool hold_rpm; } mem_access; -- 2.40.1