From patchwork Wed May 10 14:19:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Hellstr=C3=B6m?= X-Patchwork-Id: 13236961 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 8F30DC7EE26 for ; Wed, 10 May 2023 14:20:01 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8C0DA10E4C0; Wed, 10 May 2023 14:19:59 +0000 (UTC) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3BD8010E4AB; Wed, 10 May 2023 14:19:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1683728396; x=1715264396; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Mi4rtPSPC3U49tE8xbm/O1QWkUpjo/FfUXJXWSsekVE=; b=XEzvC9q117nD9W8e5eOP6N3fKfWaA0vVHkeHkKwqW7BoEoMU/BbpXG4y moGD7Y/eHEJTrHaqj/9j6oAaQf/t8aZ1DyfW9+wVpHkOiaHpQ5BjQsmzD llEp76G3i768QHxYX4mEHgz5HDzgYUvjscKX9KEkY3lKQ023rgdDWIICc Ta/TDej1v7eTDUuQmx+VnZFx52AM3eK6ktLOHFpTTAlu0RsXjhNxOyLjV MKwNMfj5KGOWjKhfuaXkizRojX99fWRNfsr8arGdcIU8AroB5y/MDVQeY FboqYxE1BKDSGcAkj3wygnoBQONggtHgvdcvnNwk3dCBK+0wZ0di+Jb5U A==; X-IronPort-AV: E=McAfee;i="6600,9927,10706"; a="339469145" X-IronPort-AV: E=Sophos;i="5.99,264,1677571200"; d="scan'208";a="339469145" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 May 2023 07:19:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10706"; a="768931696" X-IronPort-AV: E=Sophos;i="5.99,264,1677571200"; d="scan'208";a="768931696" Received: from aboreiko-mobl3.ger.corp.intel.com (HELO thellstr-mobl1.intel.com) ([10.249.254.114]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 May 2023 07:19:50 -0700 From: =?utf-8?q?Thomas_Hellstr=C3=B6m?= To: dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org Subject: [PATCH 1/2] drm/xe: Fix unlocked access of the vma::rebind_link Date: Wed, 10 May 2023 16:19:31 +0200 Message-Id: <20230510141932.413348-2-thomas.hellstrom@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230510141932.413348-1-thomas.hellstrom@linux.intel.com> References: <20230510141932.413348-1-thomas.hellstrom@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Thomas_Hellstr=C3=B6m?= Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" the vma::rebind_link is protected by the vm's resv, but we was modifying it without. Fix this by use the vma::userptr_link instead for the tmp_evict list. The vma::userptr_link is protected by the vm lock. Signed-off-by: Thomas Hellström Reviewed-by: Matthew Brost --- drivers/gpu/drm/xe/xe_vm.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c index 0a4becdf4675..5f93d78c2e58 100644 --- a/drivers/gpu/drm/xe/xe_vm.c +++ b/drivers/gpu/drm/xe/xe_vm.c @@ -764,8 +764,7 @@ int xe_vm_userptr_pin(struct xe_vm *vm) if (err < 0) goto out_err; - list_del_init(&vma->userptr_link); - list_move_tail(&vma->rebind_link, &tmp_evict); + list_move_tail(&vma->userptr_link, &tmp_evict); } /* Take lock and move to rebind_list for rebinding. */ @@ -773,16 +772,17 @@ int xe_vm_userptr_pin(struct xe_vm *vm) if (err) goto out_err; - list_splice_tail(&tmp_evict, &vm->rebind_list); + list_for_each_entry_safe(vma, next, &tmp_evict, userptr_link) { + list_del_init(&vma->userptr_link); + list_move_tail(&vma->rebind_link, &vm->rebind_list); + } + dma_resv_unlock(&vm->resv); return 0; out_err: - list_for_each_entry_safe(vma, next, &tmp_evict, rebind_link) { - list_del_init(&vma->rebind_link); - list_add_tail(&vma->userptr_link, &vm->userptr.repin_list); - } + list_splice_tail(&tmp_evict, &vm->userptr.repin_list); return err; } From patchwork Wed May 10 14:19:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Hellstr=C3=B6m?= X-Patchwork-Id: 13236962 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 E0C73C77B7D for ; Wed, 10 May 2023 14:20:04 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 077DD10E4AB; Wed, 10 May 2023 14:20:04 +0000 (UTC) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by gabe.freedesktop.org (Postfix) with ESMTPS id 34D8D10E4AF; Wed, 10 May 2023 14:19:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1683728398; x=1715264398; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3j8RY09Nrc18YSpqt7dul3RIDM/3aBWwXVBmexY72Og=; b=ksgIGj8UeQi5fI6xxrb1leIjQLYOa4/psEdIVoJvK9BsaaNYJp0IfjXD 8nrQPNT3SAAsGGc1l+u18VuJ0vSEJZzPITLLtjERRfW4w83SblZvEUcZY g/KAWV5tPkFlqZRdYi2KMoRCvJ1pycll06DEIYJR38iWIa4zw0gMuvHwO g2iR/m8nLDD4u2SGYjNaFSWlJOXLx04ZKacqG22J7poiDUgVmQhc6zJ+V ZxQmvDW3aALv0+6sr/Zt0hAZBAwhl80s1PZQXPQzJzKAQtOYDoAWBPOQv 6hS2IExRXWZBRsTdRQyxwcP7qx9HkcPozL92e1fA/If8lAk0KS51aFuWC A==; X-IronPort-AV: E=McAfee;i="6600,9927,10706"; a="339469168" X-IronPort-AV: E=Sophos;i="5.99,264,1677571200"; d="scan'208";a="339469168" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 May 2023 07:19:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10706"; a="768931727" X-IronPort-AV: E=Sophos;i="5.99,264,1677571200"; d="scan'208";a="768931727" Received: from aboreiko-mobl3.ger.corp.intel.com (HELO thellstr-mobl1.intel.com) ([10.249.254.114]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 May 2023 07:19:56 -0700 From: =?utf-8?q?Thomas_Hellstr=C3=B6m?= To: dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org Subject: [PATCH 2/2] drm/xe: Properly remove the vma from the vm::notifer::rebind_list when destroyed Date: Wed, 10 May 2023 16:19:32 +0200 Message-Id: <20230510141932.413348-3-thomas.hellstrom@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230510141932.413348-1-thomas.hellstrom@linux.intel.com> References: <20230510141932.413348-1-thomas.hellstrom@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Thomas_Hellstr=C3=B6m?= Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" If a vma was destroyed with the bo evicted, it might happen that we forget to remove it from the notifer::rebind_list. Fix to make sure that really happens. Signed-off-by: Thomas Hellström Reviewed-by: Matthew Brost --- drivers/gpu/drm/xe/xe_vm.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c index 5f93d78c2e58..f54b3b7566c9 100644 --- a/drivers/gpu/drm/xe/xe_vm.c +++ b/drivers/gpu/drm/xe/xe_vm.c @@ -978,6 +978,15 @@ static void xe_vma_destroy(struct xe_vma *vma, struct dma_fence *fence) } else { xe_bo_assert_held(vma->bo); list_del(&vma->bo_link); + /* + * TODO: We can do an advisory check for list link empty here, + * if this lock becomes too costly. Nobody can re-add to the + * bo to the vm::notifier::rebind_list at this point since we + * have the bo lock. + */ + spin_lock(&vm->notifier.list_lock); + list_del(&vma->notifier.rebind_link); + spin_unlock(&vm->notifier.list_lock); if (!vma->bo->vm) vm_remove_extobj(vma); }