Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5630594pxb; Tue, 16 Feb 2021 03:43:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJzJEpxwOUEQDK6mgOATqs/UdkZY7L0HgbMrFCtvg2a/Gv3m9epDcn4r+EMCjQ+S0fEP5KS3 X-Received: by 2002:a05:6402:5250:: with SMTP id t16mr20194834edd.302.1613475783640; Tue, 16 Feb 2021 03:43:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613475783; cv=none; d=google.com; s=arc-20160816; b=WmJEnuw3LSUQzk0eWBiuLFLCksUR07rg0I07gBpVLWpIx3USELFGJXP31uBwNb7DPd F6PZ91ucd40PERy3pbSZKGuRI07upO2SA8p4asHi5uAU3N3J8uU684YRPWKaQQm0AQ/q GwHzg+YZOO6JtlFUggF+JmS7E8Wwd9ry3yzq9k3HeO/PqqZ4KE8Gj2Usn0roh9rstclX sdhFZYkWnZF/TpPV/KLWwwVEDk0CcWmDZ9O1FhlbPUE9eSob+l6Ku6ENYhmEO2iudiWm eDvlgbZqUefOXGEhuDzvEI7GVdLZ1/E3L/3moXRfP+8zWYSM+2OD0loHNPuGXEZWNGV7 gfug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=T8hgdABHiihi7b1TSdIb3dTzwFOZ3FXXWBxTS5RCCB4=; b=DSG8KLIt252tQx6dPxE0ejM3wrDVQvrDaEZP4BSXOq9o/9Z3Vm+KaNQpW09b1AKPG6 Aipq6/jTxLy27IugA+/vVqY9LKnOI3j/P64tah0rZYybzGER9uLFLOYlW7eslYgh+lZf P8vrWDUnLm5+ihkjDjdiNC5IWUrcaCIE/vryx7GBLvHHETgdJF8//DP2k+EqdEB92qVi ph6IkaCQH0HVWab9OdszW1P8Hvtyz2uq/S47XFBd2Xvq4DtnIRt4AnbShmZX9scEJ+H/ GNgKX0myROxLH0kIH62WglXmuwBY0juWUeyoAtkoZ5CYynpQ6R6Vx2XlFCZHiUuh/cpg mNGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ERiVu1op; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g11si168678edn.182.2021.02.16.03.42.40; Tue, 16 Feb 2021 03:43:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ERiVu1op; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230359AbhBPLk6 (ORCPT + 99 others); Tue, 16 Feb 2021 06:40:58 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:20025 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230361AbhBPLi6 (ORCPT ); Tue, 16 Feb 2021 06:38:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613475446; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T8hgdABHiihi7b1TSdIb3dTzwFOZ3FXXWBxTS5RCCB4=; b=ERiVu1op5A8QonIJ/alVGmA56j51t3E+6B/ojpBYIhJ6OvjwEhuxN9aX2GudzipIBrtV4A UiYmdJbdYy6Y3m16Pid9q+X2QvQsMgW3M4QL9hlMI/7iN4IvCmCl09q4/bhzRVy3+Vx9UK urc86iuNEIgiiLAmMWFxEI5C/L/GBxA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-330-UXBmoa8xN5ir7z2OuPg4fA-1; Tue, 16 Feb 2021 06:37:25 -0500 X-MC-Unique: UXBmoa8xN5ir7z2OuPg4fA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 96192107ACC7; Tue, 16 Feb 2021 11:37:23 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-114-184.ams2.redhat.com [10.36.114.184]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 86CEA722C6; Tue, 16 Feb 2021 11:37:19 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id ABF1A18003BB; Tue, 16 Feb 2021 12:37:17 +0100 (CET) From: Gerd Hoffmann To: dri-devel@lists.freedesktop.org Cc: Gerd Hoffmann , Dave Airlie , David Airlie , Daniel Vetter , Thomas Zimmermann , virtualization@lists.linux-foundation.org (open list:DRM DRIVER FOR QXL VIRTUAL GPU), spice-devel@lists.freedesktop.org (open list:DRM DRIVER FOR QXL VIRTUAL GPU), linux-kernel@vger.kernel.org (open list) Subject: [PATCH 04/10] drm/qxl: fix lockdep issue in qxl_alloc_release_reserved Date: Tue, 16 Feb 2021 12:37:10 +0100 Message-Id: <20210216113716.716996-5-kraxel@redhat.com> In-Reply-To: <20210216113716.716996-1-kraxel@redhat.com> References: <20210216113716.716996-1-kraxel@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Call qxl_bo_unpin (which does a reservation) without holding the release_mutex lock. Fixes lockdep (correctly) warning on a possible deadlock. Fixes: 65ffea3c6e73 ("drm/qxl: unpin release objects") Signed-off-by: Gerd Hoffmann --- drivers/gpu/drm/qxl/qxl_release.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/qxl/qxl_release.c b/drivers/gpu/drm/qxl/qxl_release.c index a831184e014a..352a11a8485b 100644 --- a/drivers/gpu/drm/qxl/qxl_release.c +++ b/drivers/gpu/drm/qxl/qxl_release.c @@ -284,7 +284,7 @@ int qxl_alloc_release_reserved(struct qxl_device *qdev, unsigned long size, int type, struct qxl_release **release, struct qxl_bo **rbo) { - struct qxl_bo *bo; + struct qxl_bo *bo, *free_bo = NULL; int idr_ret; int ret = 0; union qxl_release_info *info; @@ -317,8 +317,7 @@ int qxl_alloc_release_reserved(struct qxl_device *qdev, unsigned long size, mutex_lock(&qdev->release_mutex); if (qdev->current_release_bo_offset[cur_idx] + 1 >= releases_per_bo[cur_idx]) { - qxl_bo_unpin(qdev->current_release_bo[cur_idx]); - qxl_bo_unref(&qdev->current_release_bo[cur_idx]); + free_bo = qdev->current_release_bo[cur_idx]; qdev->current_release_bo_offset[cur_idx] = 0; qdev->current_release_bo[cur_idx] = NULL; } @@ -326,6 +325,10 @@ int qxl_alloc_release_reserved(struct qxl_device *qdev, unsigned long size, ret = qxl_release_bo_alloc(qdev, &qdev->current_release_bo[cur_idx], priority); if (ret) { mutex_unlock(&qdev->release_mutex); + if (free_bo) { + qxl_bo_unpin(free_bo); + qxl_bo_unref(&free_bo); + } qxl_release_free(qdev, *release); return ret; } @@ -341,6 +344,10 @@ int qxl_alloc_release_reserved(struct qxl_device *qdev, unsigned long size, *rbo = bo; mutex_unlock(&qdev->release_mutex); + if (free_bo) { + qxl_bo_unpin(free_bo); + qxl_bo_unref(&free_bo); + } ret = qxl_release_list_add(*release, bo); qxl_bo_unref(&bo); -- 2.29.2