From patchwork Fri Feb 16 13:13:06 2024 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: 13560009 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 53608C48260 for ; Fri, 16 Feb 2024 13:13:37 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7E47010EB59; Fri, 16 Feb 2024 13:13:36 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="LS+QuHiO"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) by gabe.freedesktop.org (Postfix) with ESMTPS id B160910E904; Fri, 16 Feb 2024 13:13:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708089211; x=1739625211; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0mNEiG09rOvqohMM/wKrWcfMiB7f6Xi7ipFgIo9qHwg=; b=LS+QuHiO1wDVWxjreLHdOoYMnlJYogezsb8g13EmWJRk9cCGR1ezkyP0 fDWkW8NVxV1T9Ayta6yK96lqTVH8XvHGcMU2bAsFy2/6u7fxKTs6REJxB oapfH11saUbMcROn5S5e0hFMwy/B7kUphzsxIVDbb4Po/TInHQ5DLfLiC Cw1swkI5QcxwJHpHAPmmtEn61ZXXxTB2Gp1mwufhtSXI5fS4BhDVIRNXD coxhfrpb5lo9XxNwUZUWNINO5Hn8XoRYrOOLK8FlAbPZ2zcx1wMZZidpA MiJbXybFUwMRi7Wj58y8BJgSKdtTuu6KX+Gz+W2MaYAugOch6RvmZ9SD5 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10985"; a="2328540" X-IronPort-AV: E=Sophos;i="6.06,164,1705392000"; d="scan'208";a="2328540" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Feb 2024 05:13:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,164,1705392000"; d="scan'208";a="8504799" Received: from lapeders-mobl1.ger.corp.intel.com (HELO fedora..) ([10.249.254.121]) by orviesa005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Feb 2024 05:13:29 -0800 From: =?utf-8?q?Thomas_Hellstr=C3=B6m?= To: intel-xe@lists.freedesktop.org, intel-gfx@list.freedesktop.org Cc: =?utf-8?q?Thomas_Hellstr=C3=B6m?= , =?utf-8?q?Christian_K=C3=B6nig?= , dri-devel@lists.freedesktop.org Subject: [PATCH 4/4] drm/ttm: Allow continued swapout after -ENOSPC falure Date: Fri, 16 Feb 2024 14:13:06 +0100 Message-ID: <20240216131306.101932-5-thomas.hellstrom@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240216131306.101932-1-thomas.hellstrom@linux.intel.com> References: <20240216131306.101932-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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The -ENOSPC failure from ttm_bo_swapout() meant that the lru_lock was dropped and simply restarting the iteration meant we'd likely hit the same error again on the same resource. Now that we can restart the iteration even if the lock was dropped, do that. Cc: Christian König Cc: Signed-off-by: Thomas Hellström --- drivers/gpu/drm/ttm/ttm_device.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_device.c b/drivers/gpu/drm/ttm/ttm_device.c index e8a6a1dab669..4a030b4bc848 100644 --- a/drivers/gpu/drm/ttm/ttm_device.c +++ b/drivers/gpu/drm/ttm/ttm_device.c @@ -168,15 +168,20 @@ int ttm_device_swapout(struct ttm_device *bdev, struct ttm_operation_ctx *ctx, num_pages = PFN_UP(bo->base.size); ret = ttm_bo_swapout(bo, ctx, gfp_flags); - /* ttm_bo_swapout has dropped the lru_lock */ - if (!ret) { - ttm_resource_cursor_fini(&cursor); - return num_pages; - } - if (ret != -EBUSY) { - ttm_resource_cursor_fini(&cursor); - return ret; + /* Couldn't swap out, and retained the lru_lock */ + if (ret == -EBUSY) + continue; + /* Couldn't swap out and dropped the lru_lock */ + if (ret == -ENOSPC) { + spin_lock(&bdev->lru_lock); + continue; } + /* + * Dropped the lock and either succeeded or + * hit an error that forces us to break. + */ + ttm_resource_cursor_fini(&cursor); + return ret ? ret : num_pages; } } ttm_resource_cursor_fini_locked(&cursor);