From patchwork Tue Oct 29 12:10:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 839327 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:4593:b0:37d:45d0:187 with SMTP id gb19csp328791wrb; Tue, 29 Oct 2024 05:11:43 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXy+2taX+uq28LM3alfHcFIreGlKwbIIQIBpMqmt/D0BVt48Kp6oIoVCLRrX4mfKV1dmRzj2g==@linaro.org X-Google-Smtp-Source: AGHT+IFwKvcP4IsiFqbML4HRB6DwKeUBquTJPrCDO2mRbnLUeoUOQieJedI5LYOgRn+9a6A2XL9o X-Received: by 2002:a05:6808:1787:b0:3e5:f9dc:dbee with SMTP id 5614622812f47-3e63848404emr10513769b6e.27.1730203902873; Tue, 29 Oct 2024 05:11:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1730203902; cv=none; d=google.com; s=arc-20240605; b=OnAaj7sDxlf+J47f2QnHumbmk3JqAS/uu7LJBAlHVdepP/jeKzZBYbc0+kwELDfQJY Lm4eoSe0+RNS69BIZygcG0EdiO1kn+F3nmV5gsiugEHHu5JTt5hXHMOnvmunoJta3Ou5 H4oXDQRUVq6Obj4+IokV8sSGWbt8XpZXWQbAX4BI0GnYzWTY7NS5M9Njm3LtjWOhqKU8 QynPH444zB7rqFHm6F8yjCSUWARsb8QH2sAb7pw+2JO/LJZbIKpWl0WjbJjLp0+5wAR3 9JAmNhOAT6wALwytOnkO5wGhFjgogMUtS7tvwyXN25YHjh2IcmoWHEUfqNxqj9NjFMG5 qQNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=hV9bRORlikllwDGAZFR9/+PU9WimawpPGHP7OfCvCPA=; fh=VyoImqtNGezAyRveop7jJLIY1GvuLKHjGRNqLnjiHgY=; b=j3XU/lfsgowq4NTBdYYTWudsPiDXOq63sNRrB09LXPShWQPNpsjSxC70YjyioNyDkZ O0wuLnXwJpEV471DhjbKbl4h0BYyUZbcoSaWDGkX+iAiN8RS3eWnnfPBTiT2eV4g8LEy iI0ums7yMSU98A3Eyox17tZ6VYTBSaMhpO1Wjh2Srunk1oaimaOhclESbiZYZcETtM0/ tdYj5cGnfwpDXGoiAYhOMKy1GUOY0bzWs8D+A2TEPWVW6H6YJJZTgTPCzrWlWZZ3R9mT KVABxXkcU0XDx1I6hZ+qPbpuC3rOi3+33v1TVQo5qFz9bOgm+iPsAuLN21CP/xr2m/Xy R/Qg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ElYp8Khd; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id a1e0cc1a2514c-85580b1250dsi1931819241.136.2024.10.29.05.11.42 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 Oct 2024 05:11:42 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ElYp8Khd; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t5l3V-0004Z0-39; Tue, 29 Oct 2024 08:10:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t5l3T-0004Yn-Q8 for qemu-devel@nongnu.org; Tue, 29 Oct 2024 08:10:35 -0400 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t5l3S-0007Rt-59 for qemu-devel@nongnu.org; Tue, 29 Oct 2024 08:10:35 -0400 Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-37ed3bd6114so3453531f8f.2 for ; Tue, 29 Oct 2024 05:10:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730203832; x=1730808632; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hV9bRORlikllwDGAZFR9/+PU9WimawpPGHP7OfCvCPA=; b=ElYp8KhdKz3DWg+8lsZsvpMmGg8Mdhdjym8tLBHzzl2//u6ef+HloMumst3EqHRPaS ZoMAzxDfjhy5PQ8B4jjYQCiwcT3BqSs+gp4F/3smLpI8XPtM0g6W3KReQyGaqIIB2el3 5tJYNLICcDLzYKvWWg+nHmSm/yY7hqUxxkcbdImeripI5GAK4JKm1zrKQtxfgXCYP55P OOIQDt5EhRPrk/ILBePqnnN0Eu/BuMzofbfhoV0pLf0ecn7ZOA/X8ndwGZ+r0U4TBzEe mZNVLj0hGnPHPPBw/bqP07vihDv9ot/gq8VI0fUzL+NE6KRnvG97h6U82XrAS9WNl94T KElw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730203832; x=1730808632; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hV9bRORlikllwDGAZFR9/+PU9WimawpPGHP7OfCvCPA=; b=XfyE9LNWpoOA9FROts5lrVO9JMyo8UDNCulvzQ5K8NoZ8n4CEbPnAqddpe8DgWmDF0 AQxoqvM8PgUeToPnmA+JkCrJn5/jZ/UrAu352eSS0vbdtSroTeS1L4XhXWZc3G1WuW59 6yI7OjV+dMq/DhL9ELJYZO7KLrJ3bg2/MuGEVQo6IEsJ8uYRjPSVDpf5nSgxKWwpVGfA kzUw7JdnFn+WVErthtLh4MBLFqe8fJWAQtFS1PJl5S7HZScMn4tqdjXNV5cbqKmx5eAE l7uPzGJMYeoNkxc07I2suDyen+Z95gdnL3gTmqG7W/fXV+UajlsJoNL9vhmEfccRGQ0T D7tw== X-Gm-Message-State: AOJu0YzwafIIxMq5YJWg6Gbqpf0AjsGc1Y74gvNTQacMAG9ZmJS8w2Sr nH4nA+eItgnYc6AlHb1Q/nodm+W7tLyUl9LNMymk+VkR9+78LNCD/FosrUQnlkA= X-Received: by 2002:adf:e543:0:b0:37d:54d0:1f20 with SMTP id ffacd0b85a97d-38061158e30mr8505650f8f.24.1730203832597; Tue, 29 Oct 2024 05:10:32 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38058b712bfsm12319579f8f.79.2024.10.29.05.10.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 05:10:31 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id D2D8B5FAA9; Tue, 29 Oct 2024 12:10:30 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Dmitry Osipenko , =?utf-8?q?Alex_Benn?= =?utf-8?q?=C3=A9e?= , "Michael S. Tsirkin" Subject: [PULL 04/13] virtio-gpu: Handle virtio_gpu_virgl_init() failure Date: Tue, 29 Oct 2024 12:10:21 +0000 Message-Id: <20241029121030.4007014-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241029121030.4007014-1-alex.bennee@linaro.org> References: <20241029121030.4007014-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42e; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Dmitry Osipenko virtio_gpu_virgl_init() may fail, leading to a further Qemu crash because Qemu assumes it never fails. Check virtio_gpu_virgl_init() return code and don't execute virtio commands on error. Failed virtio_gpu_virgl_init() will result in a timed out virtio commands for a guest OS. Signed-off-by: Dmitry Osipenko Message-Id: <20241024210311.118220-5-dmitry.osipenko@collabora.com> Signed-off-by: Alex Bennée diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index 18b6c3b3a2..71775243e9 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -222,11 +222,18 @@ struct VirtIOGPUClass { Error **errp); }; +/* VirtIOGPUGL renderer states */ +typedef enum { + RS_START, /* starting state */ + RS_INIT_FAILED, /* failed initialisation */ + RS_INITED, /* initialised and working */ + RS_RESET, /* inited and reset pending, moves to start after reset */ +} RenderState; + struct VirtIOGPUGL { struct VirtIOGPU parent_obj; - bool renderer_inited; - bool renderer_reset; + RenderState renderer_state; QEMUTimer *fence_poll; QEMUTimer *print_stats; diff --git a/hw/display/virtio-gpu-gl.c b/hw/display/virtio-gpu-gl.c index 29d20b0132..ea3413aa56 100644 --- a/hw/display/virtio-gpu-gl.c +++ b/hw/display/virtio-gpu-gl.c @@ -29,9 +29,14 @@ static void virtio_gpu_gl_update_cursor_data(VirtIOGPU *g, struct virtio_gpu_scanout *s, uint32_t resource_id) { + VirtIOGPUGL *gl = VIRTIO_GPU_GL(g); uint32_t width, height; uint32_t pixels, *data; + if (gl->renderer_state != RS_INITED) { + return; + } + data = virgl_renderer_get_cursor_data(resource_id, &width, &height); if (!data) { return; @@ -65,13 +70,22 @@ static void virtio_gpu_gl_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) return; } - if (!gl->renderer_inited) { - virtio_gpu_virgl_init(g); - gl->renderer_inited = true; - } - if (gl->renderer_reset) { - gl->renderer_reset = false; + switch (gl->renderer_state) { + case RS_RESET: virtio_gpu_virgl_reset(g); + /* fallthrough */ + case RS_START: + if (virtio_gpu_virgl_init(g)) { + gl->renderer_state = RS_INIT_FAILED; + return; + } + + gl->renderer_state = RS_INITED; + break; + case RS_INIT_FAILED: + return; + case RS_INITED: + break; } cmd = virtqueue_pop(vq, sizeof(struct virtio_gpu_ctrl_command)); @@ -98,9 +112,9 @@ static void virtio_gpu_gl_reset(VirtIODevice *vdev) * GL functions must be called with the associated GL context in main * thread, and when the renderer is unblocked. */ - if (gl->renderer_inited && !gl->renderer_reset) { + if (gl->renderer_state == RS_INITED) { virtio_gpu_virgl_reset_scanout(g); - gl->renderer_reset = true; + gl->renderer_state = RS_RESET; } }