Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1192701pxb; Thu, 4 Feb 2021 07:12:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJwE9kHt63HQV6nNkByeasoIlmZZuNleBdaBhdbKTrUCcQOG/utGC+6/MFmbrZ9knaxCoNz1 X-Received: by 2002:a17:906:8591:: with SMTP id v17mr3958924ejx.30.1612451523770; Thu, 04 Feb 2021 07:12:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612451523; cv=none; d=google.com; s=arc-20160816; b=RhVOPZ7q6hcRVwqB51YK8Zq1ulqAv2VR1mt1HW9zyZc3yJ9wGWcbIEBYCQzLBNfnmI zOXrHZu4GywBDf8PyHgLrJf9bsN92vUwdX5ybVSxOp00KtLQ4oxRwvPkfcVsz3gfyz3p m+N+graY07BALoR+5s2LgDwkGaK46f2VW4ZaC3b9z9dEkQt/oQfAw5oT8kD8LpegFiK1 30GA4moc8hBFSFAmettP21etmoIJKdN+dxf/jvLEEG8CO8jI9iBueqfn+HzGwzceWZWA gPpk4b0/xhKbXTvnjriLpu7dgISKHiLVFR2Hc9FENyXhmzTDZAeH6n0sBfUMCJL/U/r6 NFXA== 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=GJTUhsF+O0Ysq2UCOUpL23Yn8/HwuxKQnXbRqkpKmRE=; b=uRO/tCdeSmLO7MwmTbwze7UoBkjXupuEoXAWJyacVnxsNwUjSoJfcvBauZElZU6WdH BeABLWMvEBMFKiCynsglO0SN3cPGmLsVKetgSk+V5WkYs5d9UGNXuyRtdKYSNcotpdAC mQY8m3kry70HdWZJZtwb06KwPGUDNChEmUNVX5/Ve0O6axW2GrTSy5Sqmn38IGX5n6bn vwcV92BhrQHvcIF2t8B/yhxcEK7T5J7LN2jzQCcqKfsyjfOuM8sFa3n8un99rUr/Bj/+ z7Obs+mGeesZfKU3bdOvML0UNDF14sNqY0wSrgzA69AH89ehI6DdlgOU/2g4MBBz3iqm vpDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=M3GBtrCW; 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 he44si3027965ejc.386.2021.02.04.07.11.38; Thu, 04 Feb 2021 07:12: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=M3GBtrCW; 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 S237165AbhBDPIl (ORCPT + 99 others); Thu, 4 Feb 2021 10:08:41 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:33592 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237079AbhBDO6w (ORCPT ); Thu, 4 Feb 2021 09:58:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612450647; 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=GJTUhsF+O0Ysq2UCOUpL23Yn8/HwuxKQnXbRqkpKmRE=; b=M3GBtrCWTt9oI0M1rr7OT1sIyE7Cp9QfzsWxM2a8779Hg2MzESUt+m9SZVDZKHQ4IWCZfu gYT1iOzGW0/3XnLBIGJtYK4y85j6kzJaV3nwr4zdzue8v8lOYZHxJPZOmqu5oS/HQwDM9B g5uOWB1LncY/kXWWObjN8UBSwzKdsdg= 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-58-SI1NogXCPSKteCRSmqwbkw-1; Thu, 04 Feb 2021 09:57:23 -0500 X-MC-Unique: SI1NogXCPSKteCRSmqwbkw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1742C804022; Thu, 4 Feb 2021 14:57:22 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-113-108.ams2.redhat.com [10.36.113.108]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EBA225DA2D; Thu, 4 Feb 2021 14:57:18 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 2C3721801024; Thu, 4 Feb 2021 15:57:13 +0100 (CET) From: Gerd Hoffmann To: dri-devel@lists.freedesktop.org Cc: Gerd Hoffmann , Thomas Zimmermann , Dave Airlie , David Airlie , Daniel Vetter , 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 v6 08/10] drm/qxl: properly free qxl releases Date: Thu, 4 Feb 2021 15:57:09 +0100 Message-Id: <20210204145712.1531203-9-kraxel@redhat.com> In-Reply-To: <20210204145712.1531203-1-kraxel@redhat.com> References: <20210204145712.1531203-1-kraxel@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Reorganize qxl_device_fini() a bit. Add missing unpin() calls. Count releases. Add wait queue for releases. That way qxl_device_fini() can easily wait until everything is ready for proper shutdown. Signed-off-by: Gerd Hoffmann Acked-by: Thomas Zimmermann --- drivers/gpu/drm/qxl/qxl_drv.h | 2 ++ drivers/gpu/drm/qxl/qxl_cmd.c | 1 + drivers/gpu/drm/qxl/qxl_irq.c | 1 + drivers/gpu/drm/qxl/qxl_kms.c | 28 ++++++++++++++++++++++++---- drivers/gpu/drm/qxl/qxl_release.c | 2 ++ 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h index 01354b43c413..6dd57cfb2e7c 100644 --- a/drivers/gpu/drm/qxl/qxl_drv.h +++ b/drivers/gpu/drm/qxl/qxl_drv.h @@ -214,6 +214,8 @@ struct qxl_device { spinlock_t release_lock; struct idr release_idr; uint32_t release_seqno; + atomic_t release_count; + wait_queue_head_t release_event; spinlock_t release_idr_lock; struct mutex async_io_mutex; unsigned int last_sent_io_cmd; diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c index 54e3c3a97440..7e22a81bfb36 100644 --- a/drivers/gpu/drm/qxl/qxl_cmd.c +++ b/drivers/gpu/drm/qxl/qxl_cmd.c @@ -254,6 +254,7 @@ int qxl_garbage_collect(struct qxl_device *qdev) } } + wake_up_all(&qdev->release_event); DRM_DEBUG_DRIVER("%d\n", i); return i; diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c index ddf6588a2a38..d312322cacd1 100644 --- a/drivers/gpu/drm/qxl/qxl_irq.c +++ b/drivers/gpu/drm/qxl/qxl_irq.c @@ -87,6 +87,7 @@ int qxl_irq_init(struct qxl_device *qdev) init_waitqueue_head(&qdev->display_event); init_waitqueue_head(&qdev->cursor_event); init_waitqueue_head(&qdev->io_cmd_event); + init_waitqueue_head(&qdev->release_event); INIT_WORK(&qdev->client_monitors_config_work, qxl_client_monitors_config_work_func); atomic_set(&qdev->irq_received, 0); diff --git a/drivers/gpu/drm/qxl/qxl_kms.c b/drivers/gpu/drm/qxl/qxl_kms.c index 4a60a52ab62e..66d74aaaee06 100644 --- a/drivers/gpu/drm/qxl/qxl_kms.c +++ b/drivers/gpu/drm/qxl/qxl_kms.c @@ -286,11 +286,31 @@ int qxl_device_init(struct qxl_device *qdev, void qxl_device_fini(struct qxl_device *qdev) { - qxl_bo_unref(&qdev->current_release_bo[0]); - qxl_bo_unref(&qdev->current_release_bo[1]); - qxl_gem_fini(qdev); - qxl_bo_fini(qdev); + int cur_idx; + + for (cur_idx = 0; cur_idx < 3; cur_idx++) { + if (!qdev->current_release_bo[cur_idx]) + continue; + qxl_bo_unpin(qdev->current_release_bo[cur_idx]); + qxl_bo_unref(&qdev->current_release_bo[cur_idx]); + qdev->current_release_bo_offset[cur_idx] = 0; + qdev->current_release_bo[cur_idx] = NULL; + } + + /* + * Ask host to release resources (+fill release ring), + * then wait for the release actually happening. + */ + qxl_io_notify_oom(qdev); + wait_event_timeout(qdev->release_event, + atomic_read(&qdev->release_count) == 0, + HZ); flush_work(&qdev->gc_work); + qxl_surf_evict(qdev); + qxl_vram_evict(qdev); + + qxl_gem_fini(qdev); + qxl_bo_fini(qdev); qxl_ring_free(qdev->command_ring); qxl_ring_free(qdev->cursor_ring); qxl_ring_free(qdev->release_ring); diff --git a/drivers/gpu/drm/qxl/qxl_release.c b/drivers/gpu/drm/qxl/qxl_release.c index 28013fd1f8ea..43a5436853b7 100644 --- a/drivers/gpu/drm/qxl/qxl_release.c +++ b/drivers/gpu/drm/qxl/qxl_release.c @@ -196,6 +196,7 @@ qxl_release_free(struct qxl_device *qdev, qxl_release_free_list(release); kfree(release); } + atomic_dec(&qdev->release_count); } static int qxl_release_bo_alloc(struct qxl_device *qdev, @@ -344,6 +345,7 @@ int qxl_alloc_release_reserved(struct qxl_device *qdev, unsigned long size, *rbo = NULL; return idr_ret; } + atomic_inc(&qdev->release_count); mutex_lock(&qdev->release_mutex); if (qdev->current_release_bo_offset[cur_idx] + 1 >= releases_per_bo[cur_idx]) { -- 2.29.2