From patchwork Sat Oct 22 04:02:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zack Rusin X-Patchwork-Id: 13015753 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A6AAEC04A95 for ; Sat, 22 Oct 2022 04:04:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id ECD4110E6C7; Sat, 22 Oct 2022 04:03:24 +0000 (UTC) Received: from letterbox.kde.org (letterbox.kde.org [46.43.1.242]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7B79010E143 for ; Sat, 22 Oct 2022 04:02:50 +0000 (UTC) Received: from vertex.vmware.com (pool-173-49-113-140.phlapa.fios.verizon.net [173.49.113.140]) (Authenticated sender: zack) by letterbox.kde.org (Postfix) with ESMTPSA id C8ECC320A6B; Sat, 22 Oct 2022 05:02:48 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kde.org; s=users; t=1666411369; bh=yFkxNmJrm5V8zjuZE5xI3HVSGvEeM0v0x9DDjUD/yLQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q3pKbAY5rNWGwmY7PTzu7lbB123HqsTv9A+/SSEFjXqmCoEHOVYNyU5FDhCyxuDy3 VFDNMC/dDSPs6f4tadPq55Ahrs/KYr5m2KyHMxxN8b0d4zuuvdHPcKCyA5ZDt1NTXK uX3zvC9+NUg5Bc7uicdqwImdVVCVhk0ZuUcR6MCkhuGgwqB2hbwKBWZwr5R3dwdHSa 8kNI3DZDSV+8jCjusy37EPU0Cru9fH/1S41srpSfFv/K5QRQ36F7mSORhyHQ5/zkZJ yQ6/z+gK9iw+oLmHtseQMhQ9CX8Ij4jJEbW9d+R1hZyChGCAP2elNFQcaL3fNHJ925 ByQVk8MOWY6hw== From: Zack Rusin To: dri-devel@lists.freedesktop.org Subject: [PATCH v4 12/17] drm/vmwgfx: Do not allow invalid bpp's for dumb buffers Date: Sat, 22 Oct 2022 00:02:31 -0400 Message-Id: <20221022040236.616490-13-zack@kde.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221022040236.616490-1-zack@kde.org> References: <20221022040236.616490-1-zack@kde.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Zack Rusin Cc: krastevm@vmware.com, banackm@vmware.com, mombasawalam@vmware.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Zack Rusin Dumb buffers allow a very limited set of formats. Basically everything apart from 1, 2 and 4 is expected to return an error. Make vmwgfx follow those guidelines. This fixes igt's dumb_buffer invalid_bpp test on vmwgfx. Signed-off-by: Zack Rusin Reviewed-by: Martin Krastev Reviewed-by: Maaz Mombasawala --- drivers/gpu/drm/vmwgfx/vmwgfx_bo.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c index 822251aaab0a..d218b15953e0 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c @@ -807,9 +807,23 @@ int vmw_dumb_create(struct drm_file *file_priv, { struct vmw_private *dev_priv = vmw_priv(dev); struct vmw_buffer_object *vbo; + int cpp = DIV_ROUND_UP(args->bpp, 8); int ret; - args->pitch = args->width * ((args->bpp + 7) / 8); + switch (cpp) { + case 1: /* DRM_FORMAT_C8 */ + case 2: /* DRM_FORMAT_RGB565 */ + case 4: /* DRM_FORMAT_XRGB8888 */ + break; + default: + /* + * Dumb buffers don't allow anything else. + * This is tested via IGT's dumb_buffers + */ + return -EINVAL; + } + + args->pitch = args->width * cpp; args->size = ALIGN(args->pitch * args->height, PAGE_SIZE); ret = vmw_gem_object_create_with_handle(dev_priv, file_priv,