Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp3452731lqp; Tue, 26 Mar 2024 09:27:52 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUxg+fWR6v9qQwME7C1LTzwAyfQRiSoW22WfBsKVnvkzTlNIM0TjPasEXTsNBgnOkOcBGjbCqPqi2ZIwL0JwnqBg7X9ZEQ3Oq/pus0vvg== X-Google-Smtp-Source: AGHT+IEl2h6rkfnbrG9Y+ArXlZ01bBvQLX3HwFaCIwqD4OfZT+mni/zDj22dfXuedYHW4dDH40vg X-Received: by 2002:a17:90a:eb0e:b0:2a0:4de8:86ef with SMTP id j14-20020a17090aeb0e00b002a04de886efmr329376pjz.1.1711470472517; Tue, 26 Mar 2024 09:27:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711470472; cv=pass; d=google.com; s=arc-20160816; b=A8w5U1ANWgjulLFmqkUrP2Lfo0/mp5sP6LweK4Op0Jpn0kKnFkbpOoelAGOHooS7GN +6Ccf3XtnEx33XeqH7M9giCuc0EgfMEwoE4ojQ5QXveXn1vjuAZt0ALS1dYTk9HdMn9b Yl+yVoEZ189DVYErKdmVPzGsyHokPsIZhNKEnEXt52bQ0Z2A0QkG0etZCqx6OUGwp65p VIOTe6S/6l4Lj38HvBTdadsIDj31FaYbpRbEqVCYvUsk4UpSW9OBToRqR5AtIWsLe9sH PZqQPMIthTbR1fZ7JONqq/gGeYG1MAYaf+4PdhaqL4riwukgffgjlOGcC9FshZ6n/GeU 8idw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:mail-followup-to:message-id:subject:cc:to:from:date :dkim-signature; bh=Bjha3IHwTqiFPh1YwXj/d0XZavZm48VG4oaRQvqaQ50=; fh=45eQo3ZJsZ9kxlKtiBlNFdEPxIxcGnXy8eMk/mnf88Q=; b=jsg1G8osXI8AK9sinTzopcO/9qVz3lux1gXX1kDZUNw/DCZkjdnP02LBSjdfXn/GTi 1hp9yTy+2isYHch6U2ZZpZ1+D1SMhQ26YacpqVKjiiDbQui6cp4/B4JZSvMWLGITdG42 hZDKVxZT2s7boQTIq4wKeF8Gb2t0XE/oiL7RAzYwHMGwON/PGyuRgMTaxVoqpAkJ4TTM 4zXXS4KasYjnh7o+mmuoiwJ74cgVMCvpoKvROUU4ws7XgvAmy6kFEQw+fRkaohWMBQ/a zI8oy+X73BlTKosfHtbk8AIq1Er2YJfbZl9neF/d8kIE+SJLwr/NdDSH0UaSanyr+jvm BDag==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Q5jIzjLO; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-119407-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119407-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id il3-20020a17090b164300b002a091cf9649si584792pjb.146.2024.03.26.09.27.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 09:27:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-119407-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Q5jIzjLO; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-119407-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119407-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com 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 306F2B2575C for ; Tue, 26 Mar 2024 15:58:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8D35613CC7A; Tue, 26 Mar 2024 15:57:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="Q5jIzjLO" Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (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 84C8C13C9CC for ; Tue, 26 Mar 2024 15:57:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711468631; cv=none; b=B6rWPPqcNTZiWBRpFbW1jdlnTm6VNbOR5Z46Tr0nRFCEfXTu/HfiaQBrS9wgq/usmij/yl3Ojwb9+o3Vg/iRkdA+i3CJtExVC8SsRzXap+3pX9Q0MdJYnRAU9CMiF4nP21zfQ88roQ3L4ZwrG9t1kG5cxbrPy31ad8DgrweXEas= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711468631; c=relaxed/simple; bh=Ixn1BFCknWB7tvXw/AFPlKu1mya2EmyRqOPQcH/8OUw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=giGckMLZ4XrTSaogVNydRO7scHPJaKBzxoitIRPed/pnJvP/noOLbit8VnjpnM77R7iKMUPXaLkdazoOnOiX7/XgyvAWUlZfBZ/MHO4OqbsQkFQYAApACt81N1xGRwULN+7Z90nqca3FYRmfeC0yZ0V53286auacR7teyGYsJJY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=Q5jIzjLO; arc=none smtp.client-ip=217.70.183.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id CBCD51BF204; Tue, 26 Mar 2024 15:56:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1711468621; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Bjha3IHwTqiFPh1YwXj/d0XZavZm48VG4oaRQvqaQ50=; b=Q5jIzjLODfk+39W+JGKprCVbfEgbLo+GihhcqM29at94QzoVWtkyOQWPipQfmlXimAySYm L+HwAdtKGADAi1+2sEt3W3OaeecrLWZQRVKKVFibb7XluRcUc7TmjrWRIvSJO6513wDQVa +ecaSBYrm9ecirZH+A5Ltq5QgWeh25rGB7BHxtAj8S/FOTTFqajmCBJ0+pUy4vQGQqGE6C GFJWinfj85OFszmaJsugYvsATHEuwSYR0PIA4RvuU64ASIkC6tbbE8PtokuQJmuodVepR3 6MGshyHgjOdITY0mKdBR3jHj/79xOuQeKv7HjvDsHsBrp+ZBiQb203oPxAQZ1A== Date: Tue, 26 Mar 2024 16:56:58 +0100 From: Louis Chauvet To: Pekka Paalanen Cc: Rodrigo Siqueira , Melissa Wen , =?iso-8859-1?Q?Ma=EDra?= Canal , Haneen Mohammed , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , arthurgrillo@riseup.net, Jonathan Corbet , 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 Subject: Re: [PATCH v5 05/16] drm/vkms: Add dummy pixel_read/pixel_write callbacks to avoid NULL pointers Message-ID: Mail-Followup-To: Pekka Paalanen , Rodrigo Siqueira , Melissa Wen , =?iso-8859-1?Q?Ma=EDra?= Canal , Haneen Mohammed , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , arthurgrillo@riseup.net, Jonathan Corbet , 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> <20240325140542.4fffd42c.pekka.paalanen@collabora.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20240325140542.4fffd42c.pekka.paalanen@collabora.com> X-GND-Sasl: louis.chauvet@bootlin.com Le 25/03/24 - 14:05, Pekka Paalanen a ?crit : > On Wed, 13 Mar 2024 18:44:59 +0100 > 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" > > + * 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; > > Hi Louis, > > I'm perhaps a bit paranoid in these things, but I'd make this not > black. Maybe something more "screaming" like magenta. There is a slight > chance that black might sometimes be expected, or not affect the > result. After all, blending something into black with pre-multiplied > alpha is equivalent to no-blending (a copy). The kernel warning is > good, the magenta is more like an assurance. Changed to 0xFF/0x00/0XFF in the V6. Thanks, Louis Chauvet > Anyway, > > Acked-by: Pekka Paalanen > > > Thanks, > pq > > > > } > > } > > > > /** > > * 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" > > + * 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; > > } > > } > > > -- Louis Chauvet, Bootlin Embedded Linux and Kernel engineering https://bootlin.com