Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2907946lqp; Mon, 25 Mar 2024 12:41:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWrmq84XWowB0ZwJNKPJwycsNwM0evaYq+hn1PBJlrZP+D2HnazrgkPApr5DhiY8WqC+ZKSF3iYItRMsTyUrpjko/hLzaZS2cl9MhplBQ== X-Google-Smtp-Source: AGHT+IG/wx34RIoQZSw2yLl+ZivktdH/YU/65hRxFLuqSUw7lwfWcbftdJuKgDl/dufrOUZ3DBtk X-Received: by 2002:a05:6358:480d:b0:17f:1ceb:1d54 with SMTP id k13-20020a056358480d00b0017f1ceb1d54mr9239919rwn.10.1711395701352; Mon, 25 Mar 2024 12:41:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711395701; cv=pass; d=google.com; s=arc-20160816; b=aJSbzv0RNZs14OPG8ZaXxlwezSpqFUNoHNT7vQbHiEzTq3BwG82ziP2DITpcIwV/ju 7IOI4uSvca+w7xCQGyt+J9P0jp4V4pWd0EXV0edi66i1aHq1JVmCdgyElsBF9OBx85Qu mSUBgdg5duMvnGmxMSUmuKt4DtMWjpgtmYQ5YZbbJBcdPz/xh6/s+CO6UTRg6MHg2Z2u wjJlZetPCZpZIgicZGzrqR80R5EaClvJ4zssjL1gWN4B1vslqXfwe73PuMI/oYIdQAKD k8cbdH49pQ2h2thtRrCKwUR9opbfCuKs8tKU3C03uSNTsWADH+ufWmBFjYYlu4TMy1Pp 0Fow== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=ImUkmTdcElH4c269QxHEf9Y5l2DHO+qtVviBXPkTw6Q=; fh=LEGVttrEe3EZzL8pWHKr59dCooiiMJK7UIxJnC6gzwU=; b=1EwKCievgACgYmrMHDx77Mmjf5GWsfTkxH9wJ5o5M4J3sGlE7NhqykFcS9YDiwpbex dmxAib3xlEPcPPjYjOsOApnyETjwduXkRTsFL/QABFQ9zpnnabApZK5LsO5OyApm4xmX Z17af0nr/LUjECSUbZ812fHCSZXQg1eV6DTvz7NoV6CHhRcmywUUAWQeQypwDyrU4wZy uBydLQ9kjPbthlzRt+5gX/pNSLsnyZbSi1PslGxA7HiGpDYW/DCVseqifnd0EZU3wWG2 gMHvs0b230Qzs54e2f4pCyrn2n4ejRV0mMMBXuvzpRskbtq78IDuoCMQnkyqLYy1r7o4 6XOw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=fail header.i=@igalia.com header.s=20170329 header.b=IfMftF9u; arc=pass (i=1 spf=pass spfdomain=igalia.com dkim=pass dkdomain=igalia.com); spf=pass (google.com: domain of linux-kernel+bounces-117192-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117192-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 141-20020a630193000000b005dc80a2a308si7735379pgb.436.2024.03.25.12.41.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 12:41:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-117192-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=fail header.i=@igalia.com header.s=20170329 header.b=IfMftF9u; arc=pass (i=1 spf=pass spfdomain=igalia.com dkim=pass dkdomain=igalia.com); spf=pass (google.com: domain of linux-kernel+bounces-117192-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117192-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 4805CB2A045 for ; Mon, 25 Mar 2024 16:11:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 78B5213D8BB; Mon, 25 Mar 2024 13:59:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="IfMftF9u" Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7B35B12B141 for ; Mon, 25 Mar 2024 13:59:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711375175; cv=none; b=rHFV2xxCJverxWMo8dLL1JRZDeoS8w+Ki59DH1lhlXvRBwZxMwKy0AqYc0w6D7vHY5GBt06b8wp66YJc5lW6IkGwpdAbFAXtXaKck/HZXlvvxOchfB5gsg9lACd3PNYejehMW3XolzcSZ5Kx5tQmOE2VOYdrQHrpBuUXTju+rNo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711375175; c=relaxed/simple; bh=KjgqyNVGdRTpM+b80kBME4KupCYpHOuZwd/ATEa8mXQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=jdgVnfqLCt0h/TO2DJVH/OUdDxWyMvyfafmqaGtqJJi8TKauqxkPPxZutfZrRk4Fr19N/PS1NxhxteP/q8wSEy8wv3FYFkCmC46+iMWZ+zK1I15/u21jlHVdipc4DLDh/zoHvIRPBYkUGX7mXkioZZo/lOx876dHG++klS31eG4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=IfMftF9u; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:From: References:Cc:To:Subject:MIME-Version:Date:Message-ID:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=ImUkmTdcElH4c269QxHEf9Y5l2DHO+qtVviBXPkTw6Q=; b=IfMftF9uzXkjFKBgjkZWvk95uI 2qHzTsKT2glJckG0g5fNRuZG4zi1aUAML+indJefuH4K86aOXHQyNtt+eLKkAftoMXRSb4QetIByU nx3xo9zCyot5iiQnnA9s+Zxm0H6TTvaQP4L438nTSuF9hqWu+ioLZ9Gx+iVzol675XOCAiIhCrXyz 1R4ETzVsAm8Q9dcA/iGBTqD2dOC4Hgm6OZtVQD0IKR0CbeGpIJ82oXE57iJg69HwFR+oB3H1/dGMY zBVAAnu4+MxAsjOC5uBG5SKevlaMF8grkDgBkHGylYoFkmVKPkWZJ83GqfGRDA7JxSNZRLKjNgZtp /bhD9pQQ==; Received: from [177.34.169.255] (helo=[192.168.0.139]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_128_GCM:128) (Exim) id 1rokr7-00F5Ls-JY; Mon, 25 Mar 2024 14:59:17 +0100 Message-ID: Date: Mon, 25 Mar 2024 10:59:09 -0300 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5 05/16] drm/vkms: Add dummy pixel_read/pixel_write callbacks to avoid NULL pointers To: Louis Chauvet , Rodrigo Siqueira , Melissa Wen , Haneen Mohammed , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , arthurgrillo@riseup.net, Jonathan Corbet , pekka.paalanen@haloniitty.fi Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, marcheu@google.com, nicolejadeyee@google.com References: <20240313-yuv-v5-0-e610cbd03f52@bootlin.com> <20240313-yuv-v5-5-e610cbd03f52@bootlin.com> Content-Language: en-US From: =?UTF-8?Q?Ma=C3=ADra_Canal?= Autocrypt: addr=mcanal@igalia.com; keydata= xjMEZIsaeRYJKwYBBAHaRw8BAQdAGU6aY8oojw61KS5rGGMrlcilFqR6p6ID45IZ6ovX0h3N H01haXJhIENhbmFsIDxtY2FuYWxAaWdhbGlhLmNvbT7CjwQTFggANxYhBDMCqFtIvFKVRJZQ hDSPnHLaGFVuBQJkixp5BQkFo5qAAhsDBAsJCAcFFQgJCgsFFgIDAQAACgkQNI+cctoYVW5u GAEAwpaC5rI3wD8zqETKwGVoXd6+AbmGfZuVD40xepy7z/8BAM5w95/oyPsHUqOsg/xUTlNp rlbhA+WWoaOXA3XgR+wCzjgEZIsaeRIKKwYBBAGXVQEFAQEHQGoOK0jgh0IorMAacx6WUUWb s3RLiJYWUU6iNrk5wWUbAwEIB8J+BBgWCAAmFiEEMwKoW0i8UpVEllCENI+cctoYVW4FAmSL GnkFCQWjmoACGwwACgkQNI+cctoYVW6cqwD/Q9R98msvkhgRvi18fzUPFDwwogn+F+gQJJ6o pwpgFkAA/R2zOfla3IT6G3SBoV5ucdpdCpnIXFpQLbmfHK7dXsAC In-Reply-To: <20240313-yuv-v5-5-e610cbd03f52@bootlin.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 3/13/24 14:44, Louis Chauvet wrote: > Introduce two callbacks which does nothing. They are used in replacement > of NULL and it avoid kernel OOPS if this NULL is called. > > If those callback are used, it means that there is a mismatch between > what formats are announced by atomic_check and what is realy supported by > atomic_update. > > Signed-off-by: Louis Chauvet > --- > drivers/gpu/drm/vkms/vkms_formats.c | 43 +++++++++++++++++++++++++++++++------ > 1 file changed, 37 insertions(+), 6 deletions(-) > > diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkms_formats.c > index 55a4365d21a4..b57d85b8b935 100644 > --- a/drivers/gpu/drm/vkms/vkms_formats.c > +++ b/drivers/gpu/drm/vkms/vkms_formats.c > @@ -136,6 +136,21 @@ static void RGB565_to_argb_u16(u8 *in_pixel, struct pixel_argb_u16 *out_pixel) > out_pixel->b = drm_fixp2int_round(drm_fixp_mul(fp_b, fp_rb_ratio)); > } > > +/** > + * black_to_argb_u16() - pixel_read callback which always read black > + * > + * This callback is used when an invalid format is requested for plane reading. > + * It is used to avoid null pointer to be used as a function. In theory, this function should > + * never be called, except if you found a bug in the driver/DRM core. > + */ > +static void black_to_argb_u16(u8 *in_pixel, struct pixel_argb_u16 *out_pixel) > +{ > + out_pixel->a = (u16)0xFFFF; > + out_pixel->r = 0; > + out_pixel->g = 0; > + out_pixel->b = 0; > +} > + > /** > * vkms_compose_row - compose a single row of a plane > * @stage_buffer: output line with the composed pixels > @@ -238,6 +253,16 @@ static void argb_u16_to_RGB565(u8 *out_pixel, struct pixel_argb_u16 *in_pixel) > *pixel = cpu_to_le16(r << 11 | g << 5 | b); > } > > +/** > + * argb_u16_to_nothing() - pixel_write callback with no effect > + * > + * This callback is used when an invalid format is requested for writeback. > + * It is used to avoid null pointer to be used as a function. In theory, this should never > + * happen, except if there is a bug in the driver > + */ > +static void argb_u16_to_nothing(u8 *out_pixel, struct pixel_argb_u16 *in_pixel) > +{} > + > /** > * Generic loop for all supported writeback format. It is executed just after the blending to > * write a line in the writeback buffer. > @@ -261,8 +286,8 @@ void vkms_writeback_row(struct vkms_writeback_job *wb, > > /** > * Retrieve the correct read_pixel function for a specific format. > - * The returned pointer is NULL for unsupported pixel formats. The caller must ensure that the > - * pointer is valid before using it in a vkms_plane_state. > + * If the format is not supported by VKMS a warn is emitted and a dummy "always read black" "If the format is not supported by VKMS, a warning is emitted and a dummy "always read black"..." > + * function is returned. > * > * @format: DRM_FORMAT_* value for which to obtain a conversion function (see [drm_fourcc.h]) > */ > @@ -285,18 +310,21 @@ pixel_read_t get_pixel_read_function(u32 format) > * format must: > * - Be listed in vkms_formats in vkms_plane.c > * - Have a pixel_read callback defined here > + * > + * To avoid kernel crash, a dummy "always read black" function is used. It means > + * that during the composition, this plane will always be black. > */ > WARN(true, > "Pixel format %p4cc is not supported by VKMS planes. This is a kernel bug, atomic check must forbid this configuration.\n", > &format); > - return (pixel_read_t)NULL; > + return &black_to_argb_u16; > } > } > > /** > * Retrieve the correct write_pixel function for a specific format. > - * The returned pointer is NULL for unsupported pixel formats. The caller must ensure that the > - * pointer is valid before using it in a vkms_writeback_job. > + * If the format is not supported by VKMS a warn is emitted and a dummy "don't do anything" "If the format is not supported by VKMS, a warning is emitted and a dummy "don't do anything"..." Best Regards, - MaĆ­ra > + * function is returned. > * > * @format: DRM_FORMAT_* value for which to obtain a conversion function (see [drm_fourcc.h]) > */ > @@ -319,10 +347,13 @@ pixel_write_t get_pixel_write_function(u32 format) > * format must: > * - Be listed in vkms_wb_formats in vkms_writeback.c > * - Have a pixel_write callback defined here > + * > + * To avoid kernel crash, a dummy "don't do anything" function is used. It means > + * that the resulting writeback buffer is not composed and can contains any values. > */ > WARN(true, > "Pixel format %p4cc is not supported by VKMS writeback. This is a kernel bug, atomic check must forbid this configuration.\n", > &format); > - return (pixel_write_t)NULL; > + return &argb_u16_to_nothing; > } > } >