Message ID | 20230306143234.1561759-1-dmitry.osipenko@collabora.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1878538wrd; Mon, 6 Mar 2023 06:42:42 -0800 (PST) X-Google-Smtp-Source: AK7set89/fOdh9WORZtLR7cyZeQEAgp8RkLi20FNbJrD7926G5J9qDrkoUFBTaiMtuvhQYVxAh+4 X-Received: by 2002:a17:90b:4b44:b0:237:72e5:61bd with SMTP id mi4-20020a17090b4b4400b0023772e561bdmr12101969pjb.49.1678113762535; Mon, 06 Mar 2023 06:42:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678113762; cv=none; d=google.com; s=arc-20160816; b=EKB3pPqk27ZIFXXmZzbwrfMGTvqGrWuGSGIfhXsSaCuNBa1rXJms95mB7DMT2rihdr ru1HVlHFyVY7JG8806lL3jHzPbUm8eXf6mSqYIZwyjD7kqDSxfOgMoiBPohSWYt9XyLX Mo+pM6pieva+zwqKhs+ZDDmg/T8NvJl52bD8rc8+fnui/azA8dWWAfolRFlRGPZmBAqo 6O+/iwe2ULQgZKtC0r8tZtYaQXCewSCfHbR4i0FThSbJdumla9aqHenIE+gMhRqqWMi3 KiRnqsPnMvoxCYTeX5Jc/RKnPaczL21s4gwxhRox8gKZLUOXRlORir1tve3L8m3t5cZH Uh/A== 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=A4aJ5QiAGhjLw9GR7RMe58heHcQZBLrn15J+HNmJ0qo=; b=ndx529ygP8tcBQMDWKLwFH+n780EsnhyBGCFKb4ciLKsfL0kIgLdZodz4uF3ZYpy/J Lh5DMQ5dK1FkaPBLGH5w85AieYU3iFDhXO69H2j0mPdhScublS6p32f5sAxnCO7aZZU4 OkfqwmQabHzcB4tYM5GD/gU8d74C6r8YvlieJyKWWP/bovf6D4XPDiQOy+VsG4M9kP8R 1LWnHh4iE/X8RP6NWGWIM1VKZkemmPHkYbTYwIZ5WidbI/ynQzaKZcGOXhcWK+NWOE/q PmPQEAVtM3BBbbLaRxjPwM3FDBX1s7mNPBgnTNtVWTfbbvVyNXlL8PLYn+G+6M+pW3wk yihw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=VGYL25Nk; 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 m13-20020a17090a2c0d00b002378962a69fsi8894003pjd.81.2023.03.06.06.42.29; Mon, 06 Mar 2023 06:42:42 -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=VGYL25Nk; 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 S229720AbjCFOfD (ORCPT <rfc822;toshivichauhan@gmail.com> + 99 others); Mon, 6 Mar 2023 09:35:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229788AbjCFOfB (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 6 Mar 2023 09:35:01 -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 4F96BBBB1 for <linux-kernel@vger.kernel.org>; Mon, 6 Mar 2023 06:34:25 -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 2A553660220B; Mon, 6 Mar 2023 14:33:05 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1678113186; bh=gJrshKNUaitWNWbqYmQJvTDpbgAcQ7xq5COOHL06j48=; h=From:To:Cc:Subject:Date:From; b=VGYL25Nk+XguA0di2RClfj+YaJ7Z/yUfecAaaKgHQlu2cWiveT+N/ZkiXqQZ7ZBfv 66hnylM0mBMgus89gmzTNnWbJ5fzRbSOwmj3OvyO+r0TaunD8uhDqxKjtiKU8aSCfL 84WVBND/GmoitV0965ylpRG9ZH5dUyvGdMHljXxFK0eFR6FeKjlR8VrZm9R5KcWZD5 rwv5qfVlh7YdYgOVpo7N9mKKcxS18BDm4NUikrXb0kcpjV0XCmu9hNesHp+si7H06b xdi+mkCoOcffTEpKjTRORXPfUkLg5RgpVmdShpmTICo5TdD2fa/lvWmSEjPneOFf9t bnDfiWFXi1A1A== From: Dmitry Osipenko <dmitry.osipenko@collabora.com> To: Gerd Hoffmann <kraxel@redhat.com>, Rob Clark <robdclark@gmail.com> Cc: Gurchetan Singh <gurchetansingh@chromium.org>, Chia-I Wu <olvaffe@gmail.com>, Ryan Neph <ryanneph@chromium.org>, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Javier Martinez Canillas <javierm@redhat.com>, David Airlie <airlied@redhat.com>, kernel@collabora.com, virtualization@lists.linux-foundation.org Subject: [PATCH v2] drm/virtio: Fix handling CONFIG_DRM_VIRTIO_GPU_KMS option Date: Mon, 6 Mar 2023 17:32:34 +0300 Message-Id: <20230306143234.1561759-1-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: <linux-kernel.vger.kernel.org> 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?1759629816736230056?= |
Series |
[v2] drm/virtio: Fix handling CONFIG_DRM_VIRTIO_GPU_KMS option
|
|
Commit Message
Dmitry Osipenko
March 6, 2023, 2:32 p.m. UTC
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.
Fixes: 72122c69d717 ("drm/virtio: Add option to disable KMS support")
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
---
Changelog:
v2: - Moved the "has_edid" under the "num_scanouts" condition, like was
suggested by Gerd Hoffmann.
drivers/gpu/drm/virtio/virtgpu_kms.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
Comments
On Mon, Mar 06, 2023 at 05:32:34PM +0300, Dmitry Osipenko wrote: > 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. > > Fixes: 72122c69d717 ("drm/virtio: Add option to disable KMS support") > Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com> > --- > > Changelog: > > v2: - Moved the "has_edid" under the "num_scanouts" condition, like was > suggested by Gerd Hoffmann. Acked-by: Gerd Hoffmann <kraxel@redhat.com>
On 2023/03/06, Dmitry Osipenko wrote: > 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. > > Fixes: 72122c69d717 ("drm/virtio: Add option to disable KMS support") > Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com> > --- > > Changelog: > > v2: - Moved the "has_edid" under the "num_scanouts" condition, like was > suggested by Gerd Hoffmann. > Hi Dmitry, I think there's more than one piece like that in the driver. > drivers/gpu/drm/virtio/virtgpu_kms.c | 14 ++++++++------ > 1 file changed, 8 insertions(+), 6 deletions(-) > > diff --git a/drivers/gpu/drm/virtio/virtgpu_kms.c b/drivers/gpu/drm/virtio/virtgpu_kms.c > index 874ad6c2621a..15f2519988e7 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); Worth doing the same thing in virtio_gpu_init()? Aka move the has_edid && get_edids within the num_scanouts if block. HTH Emil
On 3/6/23 18:02, Emil Velikov wrote: > On 2023/03/06, Dmitry Osipenko wrote: >> 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. >> >> Fixes: 72122c69d717 ("drm/virtio: Add option to disable KMS support") >> Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com> >> --- >> >> Changelog: >> >> v2: - Moved the "has_edid" under the "num_scanouts" condition, like was >> suggested by Gerd Hoffmann. >> > > Hi Dmitry, I think there's more than one piece like that in the driver. > >> drivers/gpu/drm/virtio/virtgpu_kms.c | 14 ++++++++------ >> 1 file changed, 8 insertions(+), 6 deletions(-) >> >> diff --git a/drivers/gpu/drm/virtio/virtgpu_kms.c b/drivers/gpu/drm/virtio/virtgpu_kms.c >> index 874ad6c2621a..15f2519988e7 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); > > Worth doing the same thing in virtio_gpu_init()? Aka move the has_edid > && get_edids within the num_scanouts if block. Good catch, that could be done for consistency.
diff --git a/drivers/gpu/drm/virtio/virtgpu_kms.c b/drivers/gpu/drm/virtio/virtgpu_kms.c index 874ad6c2621a..15f2519988e7 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;