From patchwork Mon Mar 6 16:39:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 64944 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1948681wrd; Mon, 6 Mar 2023 08:51:08 -0800 (PST) X-Google-Smtp-Source: AK7set+0anVzXDmBuQ4HN3Euop9FHVX2Ry86mwwmErmSLVCQ2cWojOA5ZGJ8Rxy2sJm/UvymSM8/ X-Received: by 2002:a17:907:a603:b0:90b:208:6179 with SMTP id vt3-20020a170907a60300b0090b02086179mr11840060ejc.28.1678121467977; Mon, 06 Mar 2023 08:51:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678121467; cv=none; d=google.com; s=arc-20160816; b=FR3bvrPDj7ggUjA2MLvLLrnVjtuKyul0V2Xife+Fs2nceEwdzQUWh3ip14czXbw9d5 WwJ8LsHfDVrHBpzFd1N/k/27stfkvL5zQBZ2BiiMrNaCqj3bs5l38IDxA6o+DENqcm2Z doDSzJ1O1lVpTQdBJZBXPoio3EqiYvz26MYXsFIQCP+izgPDNwWJQQWeP/SbrnQkDmoI yAsJjwrat/SSykpMhRIJgg/5fonI2et9wj8E4CQ/e/4BMJ0o9zV/zbTAJNAk1QMiEsO0 Xw4YFV3gyKdhfwOHMkEBRFccTskrg71KGBA/UR6VQFOcyL8oaSj7RvqsctBZMUebduIV 2e6w== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=KeF/rakNdano24eEHCWopWWwFa425ApCrYgJkB50+Rs=; b=TOtenXomt+bA9gKJR5wOUb+EcU1st41/OJElO4RtfylfG+rd28SGJBRpCrxQxQiM7Q iNabm62sGDPCLe36tANGpliIYr3/wVABQSMdofBrB452lu+1GHVjLvdWc7uxAcQg3O/s iaQp/L9LeD0+n0LDbbvA+m5weF0ei1ugCRdYDBTiTqOrzaI45NmF4ScqZJw81N9w+6dg QPxcumnPJNjy7lfpe2ToXteelUvM7bBgp7jSQihhz5320FBJQxzUzKiMqIjSYdAHQLy/ /H4TduYTnKfc78oQubdE2VCqK+r4o+QdKjUmRoSl2bTmQGxxvVl3JWWwEB5c84E5H6mQ JRfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=W+n6JtB8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m21-20020a17090607d500b008cf809e2bd4si4438797ejc.181.2023.03.06.08.50.44; Mon, 06 Mar 2023 08:51:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=W+n6JtB8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229618AbjCFQl7 (ORCPT + 99 others); Mon, 6 Mar 2023 11:41:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230192AbjCFQlj (ORCPT ); Mon, 6 Mar 2023 11:41:39 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DC4139BA1 for ; Mon, 6 Mar 2023 08:40:52 -0800 (PST) Received: from workpc.. (unknown [109.252.117.89]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dmitry.osipenko) by madras.collabora.co.uk (Postfix) with ESMTPSA id C67DD6602EE4; Mon, 6 Mar 2023 16:39:36 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1678120777; bh=2qF0hUp8glqDQ1ktUcSd1pu0qhpff4ScS2Sp+BIuEaU=; h=From:To:Cc:Subject:Date:From; b=W+n6JtB8n30LcsAnOQBmt8DYkHssmRq4ybXRTK7ze63cYN5xZJVUlMFV3qx9bXVTD j/CIjJklOkgonUVbISB8pOqdQEyWUu916qZ7CzRH2fhoF61YjwPEgGXK2OXIjhFTRY MWIWty2OOEVJhkVzLYE0AAlqTGLuMApawktqS9i+kgx30nBKcAwwPXvvWTslHqSIPe jeeB88G3cA2qFqS9DNK7JjeF0WesAtmsy0Q5hJFEBoimyQ1y9wsfEGpR7kxmj9mK2D Hs1sK++8a8NiSh0iTCT8DTOhKx14TKSHD7ldpt7Bvk+DdnbmGngXx3FKYedRZ/PpV6 RY8KK9bD0cOiQ== From: Dmitry Osipenko To: Gerd Hoffmann , Rob Clark , Emil Velikov Cc: Gurchetan Singh , Chia-I Wu , Ryan Neph , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Javier Martinez Canillas , David Airlie , kernel@collabora.com, virtualization@lists.linux-foundation.org Subject: [PATCH v3] drm/virtio: Fix handling CONFIG_DRM_VIRTIO_GPU_KMS option Date: Mon, 6 Mar 2023 19:39:16 +0300 Message-Id: <20230306163916.1595961-1-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759629816736230056?= X-GMAIL-MSGID: =?utf-8?q?1759637896589180639?= VirtIO-GPU got a new config option for disabling KMS. There were two problems left unnoticed during review when the new option was added: 1. The IS_ENABLED(CONFIG_DRM_VIRTIO_GPU_KMS) check in the code was inverted, hence KMS was disabled when it should be enabled and vice versa. 2. The disabled KMS crashed kernel with a NULL dereference in drm_kms_helper_hotplug_event(), which shall not be invoked with a disabled KMS. Fix the inverted config option check in the code and skip handling the VIRTIO_GPU_EVENT_DISPLAY sent by host when KMS is disabled in guest to fix the crash. Acked-by: Gerd Hoffmann Fixes: 72122c69d717 ("drm/virtio: Add option to disable KMS support") Signed-off-by: Dmitry Osipenko Reviewed-by: Emil Velikov --- Changelog: v3: - Moved another similar "has_edid" occurence under the "num_scanouts" condition in virtio_gpu_init(), like was suggested by Emil Velikov. - Added ack from Gerd Hoffmann. v2: - Moved the "has_edid" under the "num_scanouts" condition, like was suggested by Gerd Hoffmann. drivers/gpu/drm/virtio/virtgpu_kms.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/virtio/virtgpu_kms.c b/drivers/gpu/drm/virtio/virtgpu_kms.c index 874ad6c2621a..43e237082cec 100644 --- a/drivers/gpu/drm/virtio/virtgpu_kms.c +++ b/drivers/gpu/drm/virtio/virtgpu_kms.c @@ -43,11 +43,13 @@ static void virtio_gpu_config_changed_work_func(struct work_struct *work) virtio_cread_le(vgdev->vdev, struct virtio_gpu_config, events_read, &events_read); if (events_read & VIRTIO_GPU_EVENT_DISPLAY) { - if (vgdev->has_edid) - virtio_gpu_cmd_get_edids(vgdev); - virtio_gpu_cmd_get_display_info(vgdev); - virtio_gpu_notify(vgdev); - drm_helper_hpd_irq_event(vgdev->ddev); + if (vgdev->num_scanouts) { + if (vgdev->has_edid) + virtio_gpu_cmd_get_edids(vgdev); + virtio_gpu_cmd_get_display_info(vgdev); + virtio_gpu_notify(vgdev); + drm_helper_hpd_irq_event(vgdev->ddev); + } events_clear |= VIRTIO_GPU_EVENT_DISPLAY; } virtio_cwrite_le(vgdev->vdev, struct virtio_gpu_config, @@ -224,7 +226,7 @@ int virtio_gpu_init(struct virtio_device *vdev, struct drm_device *dev) vgdev->num_scanouts = min_t(uint32_t, num_scanouts, VIRTIO_GPU_MAX_SCANOUTS); - if (IS_ENABLED(CONFIG_DRM_VIRTIO_GPU_KMS) || !vgdev->num_scanouts) { + if (!IS_ENABLED(CONFIG_DRM_VIRTIO_GPU_KMS) || !vgdev->num_scanouts) { DRM_INFO("KMS disabled\n"); vgdev->num_scanouts = 0; vgdev->has_edid = false; @@ -253,9 +255,9 @@ int virtio_gpu_init(struct virtio_device *vdev, struct drm_device *dev) if (num_capsets) virtio_gpu_get_capsets(vgdev, num_capsets); - if (vgdev->has_edid) - virtio_gpu_cmd_get_edids(vgdev); if (vgdev->num_scanouts) { + if (vgdev->has_edid) + virtio_gpu_cmd_get_edids(vgdev); virtio_gpu_cmd_get_display_info(vgdev); virtio_gpu_notify(vgdev); wait_event_timeout(vgdev->resp_wq, !vgdev->display_info_pending,