From nobody Tue Feb 10 06:59:07 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1615543671; cv=none; d=zohomail.com; s=zohoarc; b=Zl/dsywcBHbe2JVSbXm+4Efibob9ysVS24go0COcrJ3lAjiydC8q2pO5JaN9chdskjw5L5DY1dAxlOaAfUUkl6EGJ4bvYay2Izfs1/2pZInRXBeZIE5qkvsG2o83BjZRZEMcRKxy2ZcWRMI1GNutxVNZEObuIzTu3zBleD2AAiY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615543671; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Dfy+XpSJ2UwD5uiWvJktRkJ4rAc79gIr7V3kV7OpfsE=; b=LvjbmG9c6HQ2vlycU5nWEGjqnOhkgjxbqPMaPBy67DPxyowoDGNWjgvSngNNQt1yol3JVozfDBjMl9iktFhYrtaa08bRPsqNNy6TmUW16xMYLqtrdo59ocbaoBIvN0znJgYE9K7/mcGt8h3EfVDm+NWk6AtvjpHrXfqe+ILnIDk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615543671991450.64365641654945; Fri, 12 Mar 2021 02:07:51 -0800 (PST) Received: from localhost ([::1]:37848 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lKehy-0006MB-U3 for importer@patchew.org; Fri, 12 Mar 2021 05:07:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34242) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lKeby-0006nO-B0 for qemu-devel@nongnu.org; Fri, 12 Mar 2021 05:01:38 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:52605) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lKebw-0002IY-ED for qemu-devel@nongnu.org; Fri, 12 Mar 2021 05:01:38 -0500 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-24-u0lBUwyrPOaW_TntfavkeA-1; Fri, 12 Mar 2021 05:01:33 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 58EF619200D3 for ; Fri, 12 Mar 2021 10:01:32 +0000 (UTC) Received: from localhost (unknown [10.36.110.50]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9F2B7610A8; Fri, 12 Mar 2021 10:01:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615543295; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Dfy+XpSJ2UwD5uiWvJktRkJ4rAc79gIr7V3kV7OpfsE=; b=WgwDuDBN3en3HS224ffFeqEMe1vy17R1u6ILnPYwweWiDjZTrYetulSPEaqAbjcuIt5Vzi YujiyilFhY9iaT21ZpeJnLgT+CSIBpwB55qosSLzIG936vsYgpDWaVaQjrCvD38pLmSRLs 1p1L8PmyXJ+6IH0EbaRO5XH7HR/AZDs= X-MC-Unique: u0lBUwyrPOaW_TntfavkeA-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PATCH 03/27] vhost-user-gpu: fix vugbm_device_init fallback Date: Fri, 12 Mar 2021 14:00:44 +0400 Message-Id: <20210312100108.2706195-4-marcandre.lureau@redhat.com> In-Reply-To: <20210312100108.2706195-1-marcandre.lureau@redhat.com> References: <20210312100108.2706195-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.25, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Marc-Andr=C3=A9 Lureau vugbm implements GBM device wrapping, udmabuf and memory fallback. However, the fallback/detection logic is flawed, as if "/dev/udmabuf" failed to be opened, it will not initialize vugbm and crash later. Rework the vugbm_device_init() logic to initialize correctly in all cases. Signed-off-by: Marc-Andr=C3=A9 Lureau --- contrib/vhost-user-gpu/vugbm.h | 2 +- contrib/vhost-user-gpu/vhost-user-gpu.c | 6 +--- contrib/vhost-user-gpu/vugbm.c | 44 +++++++++++-------------- 3 files changed, 22 insertions(+), 30 deletions(-) diff --git a/contrib/vhost-user-gpu/vugbm.h b/contrib/vhost-user-gpu/vugbm.h index 66f1520764..82bc4934e1 100644 --- a/contrib/vhost-user-gpu/vugbm.h +++ b/contrib/vhost-user-gpu/vugbm.h @@ -54,7 +54,7 @@ struct vugbm_buffer { uint32_t format; }; =20 -bool vugbm_device_init(struct vugbm_device *dev, int fd); +void vugbm_device_init(struct vugbm_device *dev, int fd); void vugbm_device_destroy(struct vugbm_device *dev); =20 bool vugbm_buffer_create(struct vugbm_buffer *buffer, struct vugbm_device = *dev, diff --git a/contrib/vhost-user-gpu/vhost-user-gpu.c b/contrib/vhost-user-g= pu/vhost-user-gpu.c index b27990ffdb..ef40fbccbb 100644 --- a/contrib/vhost-user-gpu/vhost-user-gpu.c +++ b/contrib/vhost-user-gpu/vhost-user-gpu.c @@ -1186,11 +1186,7 @@ main(int argc, char *argv[]) exit(EXIT_FAILURE); } =20 - if (g.drm_rnode_fd >=3D 0) { - if (!vugbm_device_init(&g.gdev, g.drm_rnode_fd)) { - g_warning("Failed to init DRM device, using fallback path"); - } - } + vugbm_device_init(&g.gdev, g.drm_rnode_fd); =20 if ((!!opt_socket_path + (opt_fdnum !=3D -1)) !=3D 1) { g_printerr("Please specify either --fd or --socket-path\n"); diff --git a/contrib/vhost-user-gpu/vugbm.c b/contrib/vhost-user-gpu/vugbm.c index f5304ada2f..fb15d0372c 100644 --- a/contrib/vhost-user-gpu/vugbm.c +++ b/contrib/vhost-user-gpu/vugbm.c @@ -199,55 +199,51 @@ vugbm_device_destroy(struct vugbm_device *dev) dev->device_destroy(dev); } =20 -bool +void vugbm_device_init(struct vugbm_device *dev, int fd) { - dev->fd =3D fd; + assert(!dev->inited); =20 #ifdef CONFIG_GBM - dev->dev =3D gbm_create_device(fd); -#endif - - if (0) { - /* nothing */ + if (fd >=3D 0) { + dev->dev =3D gbm_create_device(fd); } -#ifdef CONFIG_GBM - else if (dev->dev !=3D NULL) { + if (dev->dev !=3D NULL) { + dev->fd =3D fd; dev->alloc_bo =3D alloc_bo; dev->free_bo =3D free_bo; dev->get_fd =3D get_fd; dev->map_bo =3D map_bo; dev->unmap_bo =3D unmap_bo; dev->device_destroy =3D device_destroy; + dev->inited =3D true; } #endif #ifdef CONFIG_MEMFD - else if (g_file_test("/dev/udmabuf", G_FILE_TEST_EXISTS)) { + if (!dev->inited && g_file_test("/dev/udmabuf", G_FILE_TEST_EXISTS)) { dev->fd =3D open("/dev/udmabuf", O_RDWR); - if (dev->fd < 0) { - return false; + if (dev->fd >=3D 0) { + g_debug("Using experimental udmabuf backend"); + dev->alloc_bo =3D udmabuf_alloc_bo; + dev->free_bo =3D udmabuf_free_bo; + dev->get_fd =3D udmabuf_get_fd; + dev->map_bo =3D udmabuf_map_bo; + dev->unmap_bo =3D udmabuf_unmap_bo; + dev->device_destroy =3D udmabuf_device_destroy; + dev->inited =3D true; } - g_debug("Using experimental udmabuf backend"); - dev->alloc_bo =3D udmabuf_alloc_bo; - dev->free_bo =3D udmabuf_free_bo; - dev->get_fd =3D udmabuf_get_fd; - dev->map_bo =3D udmabuf_map_bo; - dev->unmap_bo =3D udmabuf_unmap_bo; - dev->device_destroy =3D udmabuf_device_destroy; } #endif - else { + if (!dev->inited) { g_debug("Using mem fallback"); dev->alloc_bo =3D mem_alloc_bo; dev->free_bo =3D mem_free_bo; dev->map_bo =3D mem_map_bo; dev->unmap_bo =3D mem_unmap_bo; dev->device_destroy =3D mem_device_destroy; - return false; + dev->inited =3D true; } - - dev->inited =3D true; - return true; + assert(dev->inited); } =20 static bool --=20 2.29.0