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 CDF80C369AB for ; Thu, 24 Apr 2025 18:39:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 931AF10E18B; Thu, 24 Apr 2025 18:39:09 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="Z9I2hn71"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) by gabe.freedesktop.org (Postfix) with ESMTPS id E31F710E18B for ; Thu, 24 Apr 2025 18:39:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1745519948; x=1777055948; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=4QsfjYBIbOfxeah78PlVLZzyzN5dMq1wM2NlNQYurzY=; b=Z9I2hn7137dD6bFFxISA0bhCYbpLYYmTekz5cpWqqdpbWYMUZU1OdUCp h6JLbP0RYvA489StGITx/KBrtur8UkRa22u/5lFEd2toiXH+ca69bCLwr vwPnpFbcH7lG9v0hE0iqYtRVW/DhYneD4sNcxhcQ/T9ikms9oXnim9AUi UHZs+it49FndM4l+8nSKZFBnsTtlji96lcz/6XVSJHafyAuuvMmuvF+3S jCZkdJUorFWucPycTB+Qp5jFLVc2jJ0wMr8hyTb+HVzLjFBwDZlelCP2D f8iuA7b6N2Id1gdYKFd+gtDtMf+e5A9kiHaiQLWWY8I4kSghNmA942aG6 w==; X-CSE-ConnectionGUID: NK+2tjH6RtKs1ft9W4vR2g== X-CSE-MsgGUID: NYIawRd2QQqlL8H9e6q1Gg== X-IronPort-AV: E=McAfee;i="6700,10204,11413"; a="58545181" X-IronPort-AV: E=Sophos;i="6.15,236,1739865600"; d="scan'208";a="58545181" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Apr 2025 11:39:07 -0700 X-CSE-ConnectionGUID: PckZWO/sSjyYMKLjUZ1+Fw== X-CSE-MsgGUID: 5vGcjh/DRxWDHggEMhRgtw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,236,1739865600"; d="scan'208";a="137544431" Received: from lstrano-desk.jf.intel.com ([10.54.39.91]) by ORVIESA003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Apr 2025 11:39:07 -0700 From: Matthew Brost To: intel-xe@lists.freedesktop.org Cc: christian.koenig@amd.com Subject: [PATCH] drm/xe: Drop slab for hw fences Date: Thu, 24 Apr 2025 11:40:27 -0700 Message-Id: <20250424184027.644688-1-matthew.brost@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: , Errors-To: intel-xe-bounces@lists.freedesktop.org Sender: "Intel-xe" Fences can outlive the Xe module so drop slab allocations for hw fences to prevent potential UAF. Suggested-by: Christian König Signed-off-by: Matthew Brost --- drivers/gpu/drm/xe/xe_hw_fence.c | 24 ++---------------------- drivers/gpu/drm/xe/xe_hw_fence.h | 3 --- drivers/gpu/drm/xe/xe_module.c | 4 ---- 3 files changed, 2 insertions(+), 29 deletions(-) diff --git a/drivers/gpu/drm/xe/xe_hw_fence.c b/drivers/gpu/drm/xe/xe_hw_fence.c index 0b4f12be3692..7e66fc97f05b 100644 --- a/drivers/gpu/drm/xe/xe_hw_fence.c +++ b/drivers/gpu/drm/xe/xe_hw_fence.c @@ -16,28 +16,9 @@ #include "xe_map.h" #include "xe_trace.h" -static struct kmem_cache *xe_hw_fence_slab; - -int __init xe_hw_fence_module_init(void) -{ - xe_hw_fence_slab = kmem_cache_create("xe_hw_fence", - sizeof(struct xe_hw_fence), 0, - SLAB_HWCACHE_ALIGN, NULL); - if (!xe_hw_fence_slab) - return -ENOMEM; - - return 0; -} - -void xe_hw_fence_module_exit(void) -{ - rcu_barrier(); - kmem_cache_destroy(xe_hw_fence_slab); -} - static struct xe_hw_fence *fence_alloc(void) { - return kmem_cache_zalloc(xe_hw_fence_slab, GFP_KERNEL); + return kvzalloc(sizeof(struct xe_hw_fence), GFP_KERNEL); } static void fence_free(struct rcu_head *rcu) @@ -45,8 +26,7 @@ static void fence_free(struct rcu_head *rcu) struct xe_hw_fence *fence = container_of(rcu, struct xe_hw_fence, dma.rcu); - if (!WARN_ON_ONCE(!fence)) - kmem_cache_free(xe_hw_fence_slab, fence); + kvfree(fence); } static void hw_fence_irq_run_cb(struct irq_work *work) diff --git a/drivers/gpu/drm/xe/xe_hw_fence.h b/drivers/gpu/drm/xe/xe_hw_fence.h index f13a1c4982c7..96f34332fd8d 100644 --- a/drivers/gpu/drm/xe/xe_hw_fence.h +++ b/drivers/gpu/drm/xe/xe_hw_fence.h @@ -11,9 +11,6 @@ /* Cause an early wrap to catch wrapping errors */ #define XE_FENCE_INITIAL_SEQNO (-127) -int xe_hw_fence_module_init(void); -void xe_hw_fence_module_exit(void); - void xe_hw_fence_irq_init(struct xe_hw_fence_irq *irq); void xe_hw_fence_irq_finish(struct xe_hw_fence_irq *irq); void xe_hw_fence_irq_run(struct xe_hw_fence_irq *irq); diff --git a/drivers/gpu/drm/xe/xe_module.c b/drivers/gpu/drm/xe/xe_module.c index 05c7d0ae6d83..0c440c57e02a 100644 --- a/drivers/gpu/drm/xe/xe_module.c +++ b/drivers/gpu/drm/xe/xe_module.c @@ -96,10 +96,6 @@ static const struct init_funcs init_funcs[] = { .init = xe_configfs_init, .exit = xe_configfs_exit, }, - { - .init = xe_hw_fence_module_init, - .exit = xe_hw_fence_module_exit, - }, { .init = xe_sched_job_module_init, .exit = xe_sched_job_module_exit, -- 2.34.1