From patchwork Mon Nov 11 14:23:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 13870860 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 CDA1CD2E9FF for ; Mon, 11 Nov 2024 14:31:23 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CA63610E4D3; Mon, 11 Nov 2024 14:31:21 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.b="cisjVO2r"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="hUnbruna"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="cisjVO2r"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="hUnbruna"; dkim-atps=neutral Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by gabe.freedesktop.org (Postfix) with ESMTPS id CACE910E4D1 for ; Mon, 11 Nov 2024 14:31:20 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (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) by smtp-out2.suse.de (Postfix) with ESMTPS id 893FD1F38F; Mon, 11 Nov 2024 14:31:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1731335479; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RmqTy4Ji0VdfJoCRO7fyir1AA6UMizO/yN2t537BzuU=; b=cisjVO2rcd/29HWLvn0Vx1gIH99I4yXPxK1WlWHv7hVCa5G1dq1f8tzvXjv3P1PWE0vfhp b9ayaPKcsaQYd4h7dt/baoAj2nGsKGT4qNoTtdoCrXXk7K/Qq/+hssohtIGTOuDeE5eNLv ZzP9Yv+cRadaeKgDIBYtcFQQfJsL9+s= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1731335479; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RmqTy4Ji0VdfJoCRO7fyir1AA6UMizO/yN2t537BzuU=; b=hUnbrunapiuuGsnC/ttYj/V3Nf6A7/+rkJPBuqI9v0vspesLdt8iLqwc61DrQZkK7fA8Nt Rzbjvi70FE5iMUCA== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1731335479; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RmqTy4Ji0VdfJoCRO7fyir1AA6UMizO/yN2t537BzuU=; b=cisjVO2rcd/29HWLvn0Vx1gIH99I4yXPxK1WlWHv7hVCa5G1dq1f8tzvXjv3P1PWE0vfhp b9ayaPKcsaQYd4h7dt/baoAj2nGsKGT4qNoTtdoCrXXk7K/Qq/+hssohtIGTOuDeE5eNLv ZzP9Yv+cRadaeKgDIBYtcFQQfJsL9+s= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1731335479; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RmqTy4Ji0VdfJoCRO7fyir1AA6UMizO/yN2t537BzuU=; b=hUnbrunapiuuGsnC/ttYj/V3Nf6A7/+rkJPBuqI9v0vspesLdt8iLqwc61DrQZkK7fA8Nt Rzbjvi70FE5iMUCA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (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) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 45CCD13A17; Mon, 11 Nov 2024 14:31:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 2D/ODzcVMmeWaAAAD6G6ig (envelope-from ); Mon, 11 Nov 2024 14:31:19 +0000 From: Thomas Zimmermann To: maarten.lankhorst@linux.intel.com, mripard@kernel.org, airlied@gmail.com, simona@ffwll.ch, p.zabel@pengutronix.de Cc: dri-devel@lists.freedesktop.org, imx@lists.linux.dev, Thomas Zimmermann Subject: [PATCH 1/5] drm/dumb-buffers: Sanitize output on errors Date: Mon, 11 Nov 2024 15:23:03 +0100 Message-ID: <20241111143114.631690-2-tzimmermann@suse.de> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241111143114.631690-1-tzimmermann@suse.de> References: <20241111143114.631690-1-tzimmermann@suse.de> MIME-Version: 1.0 X-Spamd-Result: default: False [-6.80 / 50.00]; REPLY(-4.00)[]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_COUNT_TWO(0.00)[2]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FREEMAIL_TO(0.00)[linux.intel.com,kernel.org,gmail.com,ffwll.ch,pengutronix.de]; RCVD_TLS_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCPT_COUNT_SEVEN(0.00)[8]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; TO_DN_SOME(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com] 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The ioctls MODE_CREATE_DUMB and MODE_MAP_DUMB return results into a memory buffer supplied by user space. On errors, it is possible that intermediate values are being returned. The exact semantics depends on the DRM driver's implementation of these ioctls. Although this is most-likely not a security problem in practice, avoid any uncertainty by clearing the memory to 0 on errors. Signed-off-by: Thomas Zimmermann --- drivers/gpu/drm/drm_dumb_buffers.c | 40 ++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/drm_dumb_buffers.c b/drivers/gpu/drm/drm_dumb_buffers.c index 70032bba1c97..9916aaf5b3f2 100644 --- a/drivers/gpu/drm/drm_dumb_buffers.c +++ b/drivers/gpu/drm/drm_dumb_buffers.c @@ -99,7 +99,30 @@ int drm_mode_create_dumb(struct drm_device *dev, int drm_mode_create_dumb_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv) { - return drm_mode_create_dumb(dev, data, file_priv); + struct drm_mode_create_dumb *args = data; + int err; + + err = drm_mode_create_dumb(dev, args, file_priv); + if (err) { + args->handle = 0; + args->pitch = 0; + args->size = 0; + } + return err; +} + +static int drm_mode_mmap_dumb(struct drm_device *dev, struct drm_mode_map_dumb *args, + struct drm_file *file_priv) +{ + if (!dev->driver->dumb_create) + return -ENOSYS; + + if (dev->driver->dumb_map_offset) + return dev->driver->dumb_map_offset(file_priv, dev, args->handle, + &args->offset); + else + return drm_gem_dumb_map_offset(file_priv, dev, args->handle, + &args->offset); } /** @@ -120,17 +143,12 @@ int drm_mode_mmap_dumb_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv) { struct drm_mode_map_dumb *args = data; + int err; - if (!dev->driver->dumb_create) - return -ENOSYS; - - if (dev->driver->dumb_map_offset) - return dev->driver->dumb_map_offset(file_priv, dev, - args->handle, - &args->offset); - else - return drm_gem_dumb_map_offset(file_priv, dev, args->handle, - &args->offset); + err = drm_mode_mmap_dumb(dev, args, file_priv); + if (err) + args->offset = 0; + return err; } int drm_mode_destroy_dumb(struct drm_device *dev, u32 handle, From patchwork Mon Nov 11 14:23:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 13870864 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 ECA48D12D49 for ; Mon, 11 Nov 2024 14:31:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2E94310E4D4; Mon, 11 Nov 2024 14:31:24 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.b="2EqUWkL4"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="O1GFXAej"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="2EqUWkL4"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="O1GFXAej"; dkim-atps=neutral Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3607010E4CF for ; Mon, 11 Nov 2024 14:31:21 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (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) by smtp-out1.suse.de (Postfix) with ESMTPS id C23042198E; Mon, 11 Nov 2024 14:31:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1731335479; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=V3aBHbxdOm3avQlNIV4M0kiGIE9VzkafCgHXSn6ic0Y=; b=2EqUWkL43psH0r4O+cytWk14kJXDUj2TrjhhAUmnT6Ae9Opsr0Yoy4fwvWmx8j5a1AqlK+ hb8En2ZXZn5PQYYll7ZaqHJ0MEQIc57b6tS7EbgX7wxiCFCSTuKlK1Bl1uVi4F7Jsv1KlN 7SN7qVy/s2APijPLR+oH1jrCHfYeurs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1731335479; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=V3aBHbxdOm3avQlNIV4M0kiGIE9VzkafCgHXSn6ic0Y=; b=O1GFXAejF4FW2ET3dxgejIyek1c/Nvdu0j7DTc/A0nUx9+Qo4m93f8szg3FzArvOa7UxtH tkED5YI0o3JUq5Bg== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1731335479; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=V3aBHbxdOm3avQlNIV4M0kiGIE9VzkafCgHXSn6ic0Y=; b=2EqUWkL43psH0r4O+cytWk14kJXDUj2TrjhhAUmnT6Ae9Opsr0Yoy4fwvWmx8j5a1AqlK+ hb8En2ZXZn5PQYYll7ZaqHJ0MEQIc57b6tS7EbgX7wxiCFCSTuKlK1Bl1uVi4F7Jsv1KlN 7SN7qVy/s2APijPLR+oH1jrCHfYeurs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1731335479; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=V3aBHbxdOm3avQlNIV4M0kiGIE9VzkafCgHXSn6ic0Y=; b=O1GFXAejF4FW2ET3dxgejIyek1c/Nvdu0j7DTc/A0nUx9+Qo4m93f8szg3FzArvOa7UxtH tkED5YI0o3JUq5Bg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (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) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 870B513301; Mon, 11 Nov 2024 14:31:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id iDKjHzcVMmeWaAAAD6G6ig (envelope-from ); Mon, 11 Nov 2024 14:31:19 +0000 From: Thomas Zimmermann To: maarten.lankhorst@linux.intel.com, mripard@kernel.org, airlied@gmail.com, simona@ffwll.ch, p.zabel@pengutronix.de Cc: dri-devel@lists.freedesktop.org, imx@lists.linux.dev, Thomas Zimmermann Subject: [PATCH 2/5] drm/dumb-buffers: Fix size calculations and set default pitch and size Date: Mon, 11 Nov 2024 15:23:04 +0100 Message-ID: <20241111143114.631690-3-tzimmermann@suse.de> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241111143114.631690-1-tzimmermann@suse.de> References: <20241111143114.631690-1-tzimmermann@suse.de> MIME-Version: 1.0 X-Spamd-Result: default: False [-6.80 / 50.00]; REPLY(-4.00)[]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_COUNT_TWO(0.00)[2]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FREEMAIL_TO(0.00)[linux.intel.com,kernel.org,gmail.com,ffwll.ch,pengutronix.de]; RCVD_TLS_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCPT_COUNT_SEVEN(0.00)[8]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; TO_DN_SOME(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com] 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Calculate the dumb-buffer scanline pitch with existing 4CC format helpers and provide results to drivers. Fixes the overflow and size tests. Drivers can further reuse the computed values. The dumb-buffer overflow tests round up any given bits-per-pixel value to a multiple of 8. So even one-bit formats, such as DRM_FORMAT_C1, require 8 bits per pixel. While not common, low-end displays use such formats; with a possibly considerable overallocation of memory. There's also quite a bit of code duplication among DRM's memory managers. Each calculates scanline pitch and buffer size from the given arguments. But the implementations are inconsistent in how they treat alignment and format support. Therefore, provide the already-calculated values for pitch and size to memory managers. Later patches will update each to make use of them. The commit adds drm_mode_align_dumb(), a helper to align a given dumb buffer's pitch and size. It also exports the function for memory managers to use. Signed-off-by: Thomas Zimmermann --- drivers/gpu/drm/drm_dumb_buffers.c | 83 +++++++++++++++++++++++------- include/drm/drm_dumb_buffers.h | 12 +++++ 2 files changed, 77 insertions(+), 18 deletions(-) create mode 100644 include/drm/drm_dumb_buffers.h diff --git a/drivers/gpu/drm/drm_dumb_buffers.c b/drivers/gpu/drm/drm_dumb_buffers.c index 9916aaf5b3f2..0f87a4c426c1 100644 --- a/drivers/gpu/drm/drm_dumb_buffers.c +++ b/drivers/gpu/drm/drm_dumb_buffers.c @@ -25,6 +25,8 @@ #include #include +#include +#include #include #include @@ -57,41 +59,86 @@ * a hardware-specific ioctl to allocate suitable buffer objects. */ +int drm_mode_align_dumb(struct drm_mode_create_dumb *args, + unsigned long pitch_align, + unsigned long size_align) +{ + u32 pitch = args->pitch; + u32 size; + + if (!pitch) + return -EINVAL; + + if (pitch_align) + pitch = roundup(pitch, pitch_align); + + /* overflow checks for 32bit size calculations */ + if (args->height > U32_MAX / pitch) + return -EINVAL; + + if (!size_align) + size_align = PAGE_SIZE; + else if (!IS_ALIGNED(size_align, PAGE_SIZE)) + return -EINVAL; + + size = ALIGN(args->height * pitch, size_align); + if (!size) + return -EINVAL; + + args->pitch = pitch; + args->size = size; + + return 0; +} +EXPORT_SYMBOL(drm_mode_align_dumb); + int drm_mode_create_dumb(struct drm_device *dev, struct drm_mode_create_dumb *args, struct drm_file *file_priv) { - u32 cpp, stride, size; + u32 fourcc; + const struct drm_format_info *info; + u64 pitch; + int ret; if (!dev->driver->dumb_create) return -ENOSYS; if (!args->width || !args->height || !args->bpp) return -EINVAL; - /* overflow checks for 32bit size calculations */ - if (args->bpp > U32_MAX - 8) - return -EINVAL; - cpp = DIV_ROUND_UP(args->bpp, 8); - if (cpp > U32_MAX / args->width) + /* + * The scanline pitch depends on the buffer width and the color + * format. The latter is specified as a color-mode constant for + * which we first have to find the corresponding color format. + * + * Different color formats can have the same color-mode constant. + * For example XRGB8888 and BGRX8888 both have a color mode of 32. + * It is possible to use different formats for dumb-buffer allocation + * and rendering as long as all involved formats share the same + * color-mode constant. + */ + fourcc = drm_driver_color_mode_format(dev, args->bpp); + if (fourcc == DRM_FORMAT_INVALID) return -EINVAL; - stride = cpp * args->width; - if (args->height > U32_MAX / stride) + info = drm_format_info(fourcc); + if (!info) return -EINVAL; - - /* test for wrap-around */ - size = args->height * stride; - if (PAGE_ALIGN(size) == 0) + pitch = drm_format_info_min_pitch(info, 0, args->width); + if (!pitch || pitch > U32_MAX) return -EINVAL; /* - * handle, pitch and size are output parameters. Zero them out to - * prevent drivers from accidentally using uninitialized data. Since - * not all existing userspace is clearing these fields properly we - * cannot reject IOCTL with garbage in them. + * The fields handle, pitch and size are output parameters. Zero out + * handle to prevent drivers from accidentally using uninitialized + * data. Set default pitch and size to the values computed for the + * overflow tests. Driver are free to override them, the default values + * are what most drivers want. */ args->handle = 0; - args->pitch = 0; - args->size = 0; + args->pitch = pitch; + ret = drm_mode_align_dumb(args, 0, 0); + if (ret) + return ret; return dev->driver->dumb_create(file_priv, dev, args); } diff --git a/include/drm/drm_dumb_buffers.h b/include/drm/drm_dumb_buffers.h new file mode 100644 index 000000000000..00172c5997d2 --- /dev/null +++ b/include/drm/drm_dumb_buffers.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: MIT */ + +#ifndef __DRM_DUMB_BUFFERS_H__ +#define __DRM_DUMB_BUFFERS_H__ + +struct drm_mode_create_dumb; + +int drm_mode_align_dumb(struct drm_mode_create_dumb *args, + unsigned long pitch_align, + unsigned long size_align); + +#endif From patchwork Mon Nov 11 14:23:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 13870861 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 9878DD12D49 for ; Mon, 11 Nov 2024 14:31:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CDB3210E4CF; Mon, 11 Nov 2024 14:31:23 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.b="mJk1wojr"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="8v+i6Cso"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="mJk1wojr"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="8v+i6Cso"; dkim-atps=neutral Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by gabe.freedesktop.org (Postfix) with ESMTPS id 64AD010E4D1 for ; Mon, 11 Nov 2024 14:31:21 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (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) by smtp-out1.suse.de (Postfix) with ESMTPS id 0D34D2198F; Mon, 11 Nov 2024 14:31:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1731335480; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zMKeSh3h2kFM3GAJNr2vzHmRFexGjq5qUiie0o7/Rvo=; b=mJk1wojricgc4f2b7EuTsnE1/b4gLpzA/Y7nq3C8r2D+8qW9mv5/5f3yYM5yjKkWVaqS6W qLOQKgyuO5n474ry+ooykpj0JfDuuO2Mfi7qBgVbYzg8ztkP2N1Z3P/0jl564OP0CzJrLW YhQoOtkcGXTuFF3KFK6FOD34JObqJ6I= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1731335480; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zMKeSh3h2kFM3GAJNr2vzHmRFexGjq5qUiie0o7/Rvo=; b=8v+i6CsoezLAb8hcK7TIrIjyzwH2P25nvngMxKBBl1Ds3bc6+Vz2p9Ehh18itKWlySxKpr 3HFW5C7rk0nfwKDQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1731335480; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zMKeSh3h2kFM3GAJNr2vzHmRFexGjq5qUiie0o7/Rvo=; b=mJk1wojricgc4f2b7EuTsnE1/b4gLpzA/Y7nq3C8r2D+8qW9mv5/5f3yYM5yjKkWVaqS6W qLOQKgyuO5n474ry+ooykpj0JfDuuO2Mfi7qBgVbYzg8ztkP2N1Z3P/0jl564OP0CzJrLW YhQoOtkcGXTuFF3KFK6FOD34JObqJ6I= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1731335480; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zMKeSh3h2kFM3GAJNr2vzHmRFexGjq5qUiie0o7/Rvo=; b=8v+i6CsoezLAb8hcK7TIrIjyzwH2P25nvngMxKBBl1Ds3bc6+Vz2p9Ehh18itKWlySxKpr 3HFW5C7rk0nfwKDQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (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) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id C87B513A17; Mon, 11 Nov 2024 14:31:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id GCipLzcVMmeWaAAAD6G6ig (envelope-from ); Mon, 11 Nov 2024 14:31:19 +0000 From: Thomas Zimmermann To: maarten.lankhorst@linux.intel.com, mripard@kernel.org, airlied@gmail.com, simona@ffwll.ch, p.zabel@pengutronix.de Cc: dri-devel@lists.freedesktop.org, imx@lists.linux.dev, Thomas Zimmermann Subject: [PATCH 3/5] drm/gem-dma: Use aligned default pitch and size for dumb buffers Date: Mon, 11 Nov 2024 15:23:05 +0100 Message-ID: <20241111143114.631690-4-tzimmermann@suse.de> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241111143114.631690-1-tzimmermann@suse.de> References: <20241111143114.631690-1-tzimmermann@suse.de> MIME-Version: 1.0 X-Spamd-Result: default: False [-6.80 / 50.00]; REPLY(-4.00)[]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; FUZZY_BLOCKED(0.00)[rspamd.com]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FREEMAIL_TO(0.00)[linux.intel.com,kernel.org,gmail.com,ffwll.ch,pengutronix.de]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCVD_TLS_ALL(0.00)[]; R_RATELIMIT(0.00)[to_ip_from(RLqirfcw6gnbcr9a9yhi49fhi6)]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_SEVEN(0.00)[8]; FREEMAIL_ENVRCPT(0.00)[gmail.com] 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Use the pitch and size values stored in the args parameter for allocating a dumb buffer in drm_gem_dma_dumb_create(). The values come from drm_mode_create_dumb(). Align the pitch to a multiple of 8. Push the current calculation into the only direct caller imx. Imx's hardware requires the framebuffer width to be aligned to 8. The driver's current approach is actually incorrect, as it only guarantees this implicitly and requires bpp to be a multiple of 8 already. A later commit will fix this problem by aligning the scanline pitch such that an aligned width still fits into each scanline's memory. A number of other drivers are build on top of gem-dma helpers and implement their own dumb-buffer allocation. These drivers invoke drm_gem_dma_dumb_create_internal(), which is not affected by this commit. Signed-off-by: Thomas Zimmermann --- drivers/gpu/drm/drm_gem_dma_helper.c | 7 +++++-- drivers/gpu/drm/imx/ipuv3/imx-drm-core.c | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/drm_gem_dma_helper.c b/drivers/gpu/drm/drm_gem_dma_helper.c index 870b90b78bc4..0961e52893b9 100644 --- a/drivers/gpu/drm/drm_gem_dma_helper.c +++ b/drivers/gpu/drm/drm_gem_dma_helper.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -304,9 +305,11 @@ int drm_gem_dma_dumb_create(struct drm_file *file_priv, struct drm_mode_create_dumb *args) { struct drm_gem_dma_object *dma_obj; + int ret; - args->pitch = DIV_ROUND_UP(args->width * args->bpp, 8); - args->size = args->pitch * args->height; + ret = drm_mode_align_dumb(args, 8, 0); + if (ret) + return ret; dma_obj = drm_gem_dma_create_with_handle(file_priv, drm, args->size, &args->handle); diff --git a/drivers/gpu/drm/imx/ipuv3/imx-drm-core.c b/drivers/gpu/drm/imx/ipuv3/imx-drm-core.c index ced06bd8eae8..b3c9e8fcb45e 100644 --- a/drivers/gpu/drm/imx/ipuv3/imx-drm-core.c +++ b/drivers/gpu/drm/imx/ipuv3/imx-drm-core.c @@ -145,6 +145,8 @@ static int imx_drm_dumb_create(struct drm_file *file_priv, int ret; args->width = ALIGN(width, 8); + args->pitch = DIV_ROUND_UP(args->width * args->bpp, 8); + args->size = args->pitch * args->height; ret = drm_gem_dma_dumb_create(file_priv, drm, args); if (ret) From patchwork Mon Nov 11 14:23:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 13870863 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 DC2A3D12D54 for ; Mon, 11 Nov 2024 14:31:27 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 22FDB10E4D2; Mon, 11 Nov 2024 14:31:24 +0000 (UTC) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by gabe.freedesktop.org (Postfix) with ESMTPS id A7B8E10E4CF for ; Mon, 11 Nov 2024 14:31:21 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (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) by smtp-out2.suse.de (Postfix) with ESMTPS id 4E1331F457; Mon, 11 Nov 2024 14:31:20 +0000 (UTC) Authentication-Results: smtp-out2.suse.de; none Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (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) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 143E513301; Mon, 11 Nov 2024 14:31:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id kJmMAzgVMmeWaAAAD6G6ig (envelope-from ); Mon, 11 Nov 2024 14:31:20 +0000 From: Thomas Zimmermann To: maarten.lankhorst@linux.intel.com, mripard@kernel.org, airlied@gmail.com, simona@ffwll.ch, p.zabel@pengutronix.de Cc: dri-devel@lists.freedesktop.org, imx@lists.linux.dev, Thomas Zimmermann Subject: [PATCH 4/5] drm/gem-shmem: Use aligned default pitch and size for dumb buffers Date: Mon, 11 Nov 2024 15:23:06 +0100 Message-ID: <20241111143114.631690-5-tzimmermann@suse.de> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241111143114.631690-1-tzimmermann@suse.de> References: <20241111143114.631690-1-tzimmermann@suse.de> MIME-Version: 1.0 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[]; ASN(0.00)[asn:25478, ipnet:::/0, country:RU] X-Rspamd-Queue-Id: 4E1331F457 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Rspamd-Server: rspamd1.dmz-prg2.suse.org 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Use the pitch and size values stored in the args parameter for allocating a dumb buffer in drm_gem_shmem_dumb_create(). The values come from drm_mode_create_dumb(). Align the pitch to a multiple of 8. Signed-off-by: Thomas Zimmermann --- drivers/gpu/drm/drm_gem_shmem_helper.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c index 8508060a1a95..630a4fad7af1 100644 --- a/drivers/gpu/drm/drm_gem_shmem_helper.c +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -514,18 +515,11 @@ EXPORT_SYMBOL(drm_gem_shmem_purge); int drm_gem_shmem_dumb_create(struct drm_file *file, struct drm_device *dev, struct drm_mode_create_dumb *args) { - u32 min_pitch = DIV_ROUND_UP(args->width * args->bpp, 8); + int ret; - if (!args->pitch || !args->size) { - args->pitch = min_pitch; - args->size = PAGE_ALIGN(args->pitch * args->height); - } else { - /* ensure sane minimum values */ - if (args->pitch < min_pitch) - args->pitch = min_pitch; - if (args->size < args->pitch * args->height) - args->size = PAGE_ALIGN(args->pitch * args->height); - } + ret = drm_mode_align_dumb(args, 8, 0); + if (ret) + return ret; return drm_gem_shmem_create_with_handle(file, dev, args->size, &args->handle); } From patchwork Mon Nov 11 14:23:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 13870862 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 CC097D2E9F0 for ; Mon, 11 Nov 2024 14:31:26 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CE9FB10E4D0; Mon, 11 Nov 2024 14:31:23 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.b="MsGnFC4B"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="xTr2ARlH"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="MsGnFC4B"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="xTr2ARlH"; dkim-atps=neutral Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by gabe.freedesktop.org (Postfix) with ESMTPS id DAA5910E4D4 for ; Mon, 11 Nov 2024 14:31:21 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (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) by smtp-out2.suse.de (Postfix) with ESMTPS id 8E18E1F45A; Mon, 11 Nov 2024 14:31:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1731335480; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y9h9XHtfaqzI4O/2tolbkYILB+f7Kff73b6msVgAJtE=; b=MsGnFC4BSR2+7GxXXTQcCKC1FqNtrHPRL0YnEym3FtLlMQVZBLHNGlHtsokskVy1d4iq7L hlei8taMEuZHUdGVZmfBgvFIg0UkYez1UwdUjBM/9dCGka8uOav6MzRV+vt7Vije7BHHk5 bcQWUm601q0CkHsay9NBgoJbbkDlPq4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1731335480; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y9h9XHtfaqzI4O/2tolbkYILB+f7Kff73b6msVgAJtE=; b=xTr2ARlHUN2AlwFP0180z+5hxORs/dk6bMQMCfSE+GVGBu0ASd0RMOWVpQR29WRcwxYs5E e/TLYXsWtoFM2WBg== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1731335480; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y9h9XHtfaqzI4O/2tolbkYILB+f7Kff73b6msVgAJtE=; b=MsGnFC4BSR2+7GxXXTQcCKC1FqNtrHPRL0YnEym3FtLlMQVZBLHNGlHtsokskVy1d4iq7L hlei8taMEuZHUdGVZmfBgvFIg0UkYez1UwdUjBM/9dCGka8uOav6MzRV+vt7Vije7BHHk5 bcQWUm601q0CkHsay9NBgoJbbkDlPq4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1731335480; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y9h9XHtfaqzI4O/2tolbkYILB+f7Kff73b6msVgAJtE=; b=xTr2ARlHUN2AlwFP0180z+5hxORs/dk6bMQMCfSE+GVGBu0ASd0RMOWVpQR29WRcwxYs5E e/TLYXsWtoFM2WBg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (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) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 54CDC13301; Mon, 11 Nov 2024 14:31:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id eJRsEzgVMmeWaAAAD6G6ig (envelope-from ); Mon, 11 Nov 2024 14:31:20 +0000 From: Thomas Zimmermann To: maarten.lankhorst@linux.intel.com, mripard@kernel.org, airlied@gmail.com, simona@ffwll.ch, p.zabel@pengutronix.de Cc: dri-devel@lists.freedesktop.org, imx@lists.linux.dev, Thomas Zimmermann Subject: [PATCH 5/5] drm/gem-vram: Use default pitch and size for dumb buffers Date: Mon, 11 Nov 2024 15:23:07 +0100 Message-ID: <20241111143114.631690-6-tzimmermann@suse.de> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241111143114.631690-1-tzimmermann@suse.de> References: <20241111143114.631690-1-tzimmermann@suse.de> MIME-Version: 1.0 X-Spamd-Result: default: False [-6.80 / 50.00]; REPLY(-4.00)[]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_COUNT_TWO(0.00)[2]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_SEVEN(0.00)[8]; FUZZY_BLOCKED(0.00)[rspamd.com]; FREEMAIL_TO(0.00)[linux.intel.com,kernel.org,gmail.com,ffwll.ch,pengutronix.de]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCVD_TLS_ALL(0.00)[]; R_RATELIMIT(0.00)[to_ip_from(RLqirfcw6gnbcr9a9yhi49fhi6)]; FREEMAIL_ENVRCPT(0.00)[gmail.com] 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Use the pitch and size values stored in the args parameter for allocating a dumb buffer in drm_gem_vram_dumb_create(). Inline the relevant code from drm_gem_vram_fill_create_dumb(), but without the size computation. This value comes from drm_mode_create_dumb(). Align the pitch to a multiple of 8. Only hibmc and vboxvideo use gem-vram. Hibmc invokes the call to drm_gem_vram_fill_create_dumb() directly and is therefore not affected. Signed-off-by: Thomas Zimmermann --- drivers/gpu/drm/drm_gem_vram_helper.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_gem_vram_helper.c b/drivers/gpu/drm/drm_gem_vram_helper.c index 22b1fe9c03b8..0d1a9cce47e7 100644 --- a/drivers/gpu/drm/drm_gem_vram_helper.c +++ b/drivers/gpu/drm/drm_gem_vram_helper.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -582,10 +583,31 @@ int drm_gem_vram_driver_dumb_create(struct drm_file *file, struct drm_device *dev, struct drm_mode_create_dumb *args) { + struct drm_gem_vram_object *gbo; + int ret; + if (WARN_ONCE(!dev->vram_mm, "VRAM MM not initialized")) return -EINVAL; - return drm_gem_vram_fill_create_dumb(file, dev, 0, 0, args); + ret = drm_mode_align_dumb(args, 8, 0); + if (ret) + return ret; + + gbo = drm_gem_vram_create(dev, args->size, 0); + if (IS_ERR(gbo)) + return PTR_ERR(gbo); + + ret = drm_gem_handle_create(file, &gbo->bo.base, &args->handle); + if (ret) + goto err_drm_gem_object_put; + + drm_gem_object_put(&gbo->bo.base); + + return 0; + +err_drm_gem_object_put: + drm_gem_object_put(&gbo->bo.base); + return ret; } EXPORT_SYMBOL(drm_gem_vram_driver_dumb_create);