Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1135247imu; Wed, 16 Jan 2019 13:23:17 -0800 (PST) X-Google-Smtp-Source: ALg8bN59CCDwgwmj03UYtNVjdS1Jnrn/Vm/5o5Q8Mj/1BSs3q9gWH7amcArvgpAYwwBDpofmE1co X-Received: by 2002:a62:9111:: with SMTP id l17mr11912510pfe.200.1547673796939; Wed, 16 Jan 2019 13:23:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547673796; cv=none; d=google.com; s=arc-20160816; b=JyxbVWiVs1sBGRJ4lGeipBjW7ROIbDNWOpDN24PSeA7NTe3+4TRKaxL0sZnQjkGjk8 YgDRQaS0sXbKwzMtEAr5sOYmTMOyKBTKQ+BYVIAuoq988DvE4IXTKzPZIUN5vxeNAg9b OF9fKWxQmK2x/LyP/SlRiUatISmnEcaJSmosVwFzVTA2TTfTG9I8+Ge8UKW/TwsikGte dVKrrI2jze9iwFxfdd+K2moIHRIxxZdizxX1ouzABo8u7Eq0Igjam89VuAjl99Fi9BvM VyMxz9cTOxjOe5PrpK6lXDHmx5vyyF3WzNWp0h2q5suxXXe+d9CPz8tZFoHlPEyuX/ev Ovzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date; bh=YhH13iAmubCVDtXFtFydq3SiavIoe8FCXztl3jPqBZk=; b=gifdw18z1d4Y7gXhZxt2m+2TTnJGuQrvmoNgJ6s6VFgAaEH5DxFBwZjH3tt1f+AKRh FfRc1REpaXVy8gNKsyv8rLzVT/kfG8HhNC+iWqHuIwkBV5oFx6Vvu+91pQVhOF6b4aqv JDt3ze6MliFIvNJLG9WMZ7ZNgvd3bx3lkbL+QmMLR37gmamKodSaJ5cN4U36iz7AbwpZ fzCPqeisJMJ9YILNc+oyW7iehnqjfyzyQVGchdeUZjxwYk1onLElk4srwBMMcEQnxPR6 Mritb1Xy6FehO3jqFHWkpI90SIWDbj+m94IlQ0Gg8UO4QQABt67yZpUzpFBmldoQPCDe TqRg== 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 e6si6921318pgp.504.2019.01.16.13.22.58; Wed, 16 Jan 2019 13:23:16 -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 S2391594AbfAPJYx (ORCPT + 99 others); Wed, 16 Jan 2019 04:24:53 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42826 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730575AbfAPJYx (ORCPT ); Wed, 16 Jan 2019 04:24:53 -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 32778BDD0; Wed, 16 Jan 2019 09:24:52 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1DBD961090; Wed, 16 Jan 2019 09:24:52 +0000 (UTC) Received: from zmail25.collab.prod.int.phx2.redhat.com (zmail25.collab.prod.int.phx2.redhat.com [10.5.83.31]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E2F4B1803396; Wed, 16 Jan 2019 09:24:51 +0000 (UTC) Date: Wed, 16 Jan 2019 04:24:51 -0500 (EST) From: Frediano Ziglio To: Gerd Hoffmann Cc: dri-devel@lists.freedesktop.org, David Airlie , open list , "open list:DRM DRIVER FOR QXL VIRTUAL GPU" , Daniel Vetter , "open list:DRM DRIVER FOR QXL VIRTUAL GPU" , Dave Airlie Message-ID: <636470684.58090538.1547630691403.JavaMail.zimbra@redhat.com> In-Reply-To: <20190116083521.22673-2-kraxel@redhat.com> References: <20190116083521.22673-1-kraxel@redhat.com> <20190116083521.22673-2-kraxel@redhat.com> Subject: Re: [Spice-devel] [PATCH 1/3] drm/qxl: add mode/framebuffer check functions MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [10.33.32.17, 10.4.195.23] Thread-Topic: drm/qxl: add mode/framebuffer check functions Thread-Index: VEZ7rzz3Wgc94Qph+OmMvmvbQh/xhw== 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.29]); Wed, 16 Jan 2019 09:24:52 +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) Is someone checking for integer overflows already? > + 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) Frediano