Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp972585imu; Wed, 16 Jan 2019 10:29:25 -0800 (PST) X-Google-Smtp-Source: ALg8bN7y9f4oTgYRghdUGG8VCjG3NjXB4ggTo9OLyCmSkEE5tgv4JEJlsAtpcMcWHLbDuBs9Hq5x X-Received: by 2002:a17:902:82c2:: with SMTP id u2mr11259875plz.110.1547663365555; Wed, 16 Jan 2019 10:29:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547663365; cv=none; d=google.com; s=arc-20160816; b=R0gTy9iPFuvpy70UK6TQqAlxfbKNKh0jtwxX0alxU3/9d5YpCl/sC5qfxZ/Ui2N1P4 wlFUc8qQLIc5FYRhoYMv1SJag1sceJDFA0usRfbfsgwhKfICtJp03daxsBiDj2o0TPL9 3cyXuPpNAMTiA4Nwa7qPEnyEaoc+zs4s1pH3g48Dd0lOM2anziBCt4yiQxueuVsZXI8N LVysBHzhpwjXEyoZdD3ZNGqJZzxUEDuqrmp0Fu3vnZqYX9is9zw4X4HZVfSr/u3jrLIb rbDSIy8j1aZ9v1tvXhiEYvsB6iqFDls9suxcTSFB0fIWdHFUxPMrLDBAlYXnKteJs70j Ckjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=PEruoebhOTbj9X4VkjwrFJTyYuFWUXrzgd95JtRTF88=; b=Pq14I7IQvZ4Efl8OAkT9phIyszIED/tV7/c7dxOlkZDK7flwGJknC/FJzj/BDfQ1KI sA8aDuHZ3wjDaLowtxod/E2F5Pe3AseT7pVqhvOTwYcOSSf7c28ZuzV44wqCM18cK3gh HRTtrx21bKvEIFqgevCLa/RJapOkGwDkDJnQkBbvNnDQgzBmz9g9uHfvyifxCo+yafX8 h/nZsGPJTCibIBLoyv2GXp38s8CcgN4UaZ1vnJeYRxj/pMUzhD1+WXPdzZPh+W/k233q 48zPc+xK3giKdZyBAqG7NjodXqTMoYz5daJhvO99P8LhAdHyzTkTm4RY4kDSI7MvycUm O2hA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g71si6579030pgc.419.2019.01.16.10.29.07; Wed, 16 Jan 2019 10:29:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388788AbfAPIf3 (ORCPT + 99 others); Wed, 16 Jan 2019 03:35:29 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44774 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388753AbfAPIf2 (ORCPT ); Wed, 16 Jan 2019 03:35:28 -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 mx1.redhat.com (Postfix) with ESMTPS id D0032C0528B9; Wed, 16 Jan 2019 08:35:27 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-117-186.ams2.redhat.com [10.36.117.186]) by smtp.corp.redhat.com (Postfix) with ESMTP id B816F60BEC; Wed, 16 Jan 2019 08:35:22 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id B7B72A213; Wed, 16 Jan 2019 09:35:21 +0100 (CET) From: Gerd Hoffmann To: dri-devel@lists.freedesktop.org Cc: Gerd Hoffmann , 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 1/3] drm/qxl: add mode/framebuffer check functions Date: Wed, 16 Jan 2019 09:35:19 +0100 Message-Id: <20190116083521.22673-2-kraxel@redhat.com> In-Reply-To: <20190116083521.22673-1-kraxel@redhat.com> References: <20190116083521.22673-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 16 Jan 2019 08:35:28 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a helper functions to check video modes. Also add a helper to check framebuffer buffer objects, using the former for consistency. That way we should not fail in qxl_primary_atomic_check() because video modes which are too big will not be added to the mode list in the first place. Signed-off-by: Gerd Hoffmann --- drivers/gpu/drm/qxl/qxl_display.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/drivers/gpu/drm/qxl/qxl_display.c b/drivers/gpu/drm/qxl/qxl_display.c index 1f8fddcc34..07a37d52c4 100644 --- a/drivers/gpu/drm/qxl/qxl_display.c +++ b/drivers/gpu/drm/qxl/qxl_display.c @@ -191,6 +191,21 @@ void qxl_display_read_client_monitors_config(struct qxl_device *qdev) } } +static int qxl_check_mode(struct qxl_device *qdev, + unsigned int width, + unsigned int height) +{ + if (width * height * 4 > qdev->vram_size) + return -ENOMEM; + return 0; +} + +static int qxl_check_framebuffer(struct qxl_device *qdev, + struct qxl_bo *bo) +{ + return qxl_check_mode(qdev, bo->surf.width, bo->surf.height); +} + static int qxl_add_monitors_config_modes(struct drm_connector *connector, unsigned *pwidth, unsigned *pheight) @@ -466,12 +481,7 @@ static int qxl_primary_atomic_check(struct drm_plane *plane, bo = gem_to_qxl_bo(state->fb->obj[0]); - if (bo->surf.stride * bo->surf.height > qdev->vram_size) { - DRM_ERROR("Mode doesn't fit in vram size (vgamem)"); - return -EINVAL; - } - - return 0; + return qxl_check_framebuffer(qdev, bo); } static int qxl_primary_apply_cursor(struct drm_plane *plane) @@ -941,20 +951,11 @@ static enum drm_mode_status qxl_conn_mode_valid(struct drm_connector *connector, { struct drm_device *ddev = connector->dev; struct qxl_device *qdev = ddev->dev_private; - int i; - /* TODO: is this called for user defined modes? (xrandr --add-mode) - * TODO: check that the mode fits in the framebuffer */ + if (qxl_check_mode(qdev, mode->hdisplay, mode->vdisplay) != 0) + return MODE_BAD; - if (qdev->monitors_config_width == mode->hdisplay && - qdev->monitors_config_height == mode->vdisplay) - return MODE_OK; - - for (i = 0; i < ARRAY_SIZE(common_modes); i++) { - if (common_modes[i].w == mode->hdisplay && common_modes[i].h == mode->vdisplay) - return MODE_OK; - } - return MODE_BAD; + return MODE_OK; } static struct drm_encoder *qxl_best_encoder(struct drm_connector *connector) -- 2.9.3