From patchwork Wed Feb 8 14:53:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Matthew Auld X-Patchwork-Id: 13133130 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 8813AC05027 for ; Wed, 8 Feb 2023 14:57:32 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2310E10E7B0; Wed, 8 Feb 2023 14:57:27 +0000 (UTC) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0EE0D10E7A7; Wed, 8 Feb 2023 14:57:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675868243; x=1707404243; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=opTd8+G1Y/rtR2GCvHtLEXdoN8IPXeYAezj4yEWDy54=; b=gkvdA/xWwJc1xD2u5YmvDGO/oR+sOAuXiXheBwPVoRn/8rQxOlgSSFmZ A+92MLOS9dqu4g4aND/S8L8XhflpAI0PRKbtBmym4ScOKk0cHsleMBq1E 4+85MOkK8j2qTwogrsl6u9SPa5TxypzlHEd1LlNRPrP4r1JD3qAn885GK XPyFP3uvXopf6ytD/0MQ/JYbAyvhHHVzkWjF7xUPkRLPHTRIl1jGcyAT3 iKM7fREJe6vkHiB7nTFsKT9x10/WfKRSSq/Xn5T+1YtQNppDHVCGVxk4L LJOT8eKkzHpF7bAflm8DP0FOu2ermS+YiT1i1qBhExcoGXOEMIJySNT4H Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10615"; a="328469192" X-IronPort-AV: E=Sophos;i="5.97,281,1669104000"; d="scan'208";a="328469192" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2023 06:57:22 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10615"; a="617233448" X-IronPort-AV: E=Sophos;i="5.97,281,1669104000"; d="scan'208";a="617233448" Received: from hassanka-mobl1.ger.corp.intel.com (HELO mwauld-desk1.intel.com) ([10.252.31.252]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2023 06:57:21 -0800 From: Matthew Auld To: intel-gfx@lists.freedesktop.org Subject: [PATCH 2/4] drm/qxl: handle NULL bo->resource in move callback Date: Wed, 8 Feb 2023 14:53:17 +0000 Message-Id: <20230208145319.397235-2-matthew.auld@intel.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230208145319.397235-1-matthew.auld@intel.com> References: <20230208145319.397235-1-matthew.auld@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?Christian_K=C3=B6nig?= , dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The ttm bo now initially has NULL bo->resource, and leaves the driver the handle that. However it looks like we forgot to handle that for qxl. It looks like this will just null-ptr-deref in qxl_bo_move(), if bo->resource is NULL. Fix this by calling move_null() if the new resource is TTM_PL_SYSTEM, otherwise do the multi-hop sequence to ensure can safely call into ttm_bo_move_memcpy(), since it might also need to clear the memory. This should give the same behaviour as before. Fixes: 180253782038 ("drm/ttm: stop allocating dummy resources during BO creation") Signed-off-by: Matthew Auld Cc: Christian König --- drivers/gpu/drm/qxl/qxl_ttm.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c index a92a5b0d4c25..1a82629bce3f 100644 --- a/drivers/gpu/drm/qxl/qxl_ttm.c +++ b/drivers/gpu/drm/qxl/qxl_ttm.c @@ -143,6 +143,17 @@ static int qxl_bo_move(struct ttm_buffer_object *bo, bool evict, struct ttm_resource *old_mem = bo->resource; int ret; + if (!old_mem) { + if (new_mem->mem_type != TTM_PL_SYSTEM) { + hop->mem_type = TTM_PL_SYSTEM; + hop->flags = TTM_PL_FLAG_TEMPORARY; + return -EMULTIHOP; + } + + ttm_bo_move_null(bo, new_mem); + return 0; + } + qxl_bo_move_notify(bo, new_mem); ret = ttm_bo_wait_ctx(bo, ctx);