Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4108866pxk; Tue, 8 Sep 2020 10:55:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwT23GKHsZFg6c5rHQUK0eUDRZ/zPoH+mxQLLTHLj/phi8f4rfa5ENNPDloNlJCSoPoI8jh X-Received: by 2002:a05:6402:17da:: with SMTP id s26mr102485edy.221.1599587757876; Tue, 08 Sep 2020 10:55:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599587757; cv=none; d=google.com; s=arc-20160816; b=uto6R+GlsOG/1L+qe0haYMEUTgo6VcWuATWwZpiG0a5gSZDhHnwSplTfz8E1uEpxS9 WqmEm6xuCF4+QVXVfaJYdXCsIyIM3JyQ0oorZoJfsPzk63jNNy8oxUL6PddLUrI0FURv oK4k2BmjEsZV1ib8vrMspZ57YUJDHlwVfVXrBGuzXrrI9RhpcdPxFAkJqWzSYeD4KqVy kGEduTX0i6KH0U3C4yZwLv4WCvZ1KAdA5l4NtkbKpfaFyJMQ14cupzT15uHS44uY8auY tQbuTEvMuWjYICf1+sGdb0syJFcm440MXYehIrM9R2bulQXsc4xXKAAuDbIMkifvO74U +5WA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=26g9MvqLfSrFEX9y0isIESwNtY4LtdHPm8Ti14l/0nI=; b=cX1x1wmi2xg9itoMfQoEWxNOkd4/77TUpiUw41l6BWsgq1Y6KUrrdCgmsdBxBXRnqG yHCQl7xGXSb8I+HQaMUQBYu4bHvHt+0CfZ6IjvamDw7VUeuF6Fir1UG8aeE/+6WdARVi 0OJq3DD51FYl52IFKYacOd1djcV01DKF0buKXEmnPnm65IxBIDqF5Jx1QWudCsJwyrE7 ngPPAFtOlUitp86sDQlWNlC9Ftf2WImiO4CoyquJIWOGKgZxGJaCzuXi06PyNiiOWKaJ Y7K0TCqVHk7HhmmMdagzKlv2H3q2w78HnMPbuSWQlkCyfOpvj538QiGb9brQD1wpBXqj y3DA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=QGa30Zxm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f9si13374275edm.167.2020.09.08.10.55.35; Tue, 08 Sep 2020 10:55:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=QGa30Zxm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731807AbgIHRw4 (ORCPT + 99 others); Tue, 8 Sep 2020 13:52:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731626AbgIHQNo (ORCPT ); Tue, 8 Sep 2020 12:13:44 -0400 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3813C0617A4 for ; Tue, 8 Sep 2020 05:13:00 -0700 (PDT) Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id EF77339; Tue, 8 Sep 2020 14:07:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1599566866; bh=gVQ6vV1AXzJOgjJLHm9N/dNNMo5x6er9J7+iF8u+AkI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=QGa30ZxmFOr8fkWU2OJpI/toSpG6N4iUhztpdHqegiOWw5o0Y4gQ0PfCRvN8uHsWi P6a2E3nLv3IjzpbAfep3BTCZivEbImsehfIgwob+5ckDFvUMf7nv9nKRkiWfmUuynp YePkjknL80Di8J06EJlpqK5ZMTdw6XEDGiVIQTF0= Date: Tue, 8 Sep 2020 15:07:19 +0300 From: Laurent Pinchart To: Daniel Vetter Cc: Tomi Valkeinen , Stefan Agner , jsarha@ti.com, marex@denx.de, airlied@linux.ie, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] drm: mxsfb: check framebuffer pitch Message-ID: <20200908120719.GD6047@pendragon.ideasonboard.com> References: <20200907160343.124405-1-stefan@agner.ch> <20200907161712.GF6047@pendragon.ideasonboard.com> <20200907181855.GE2352366@phenom.ffwll.local> <86615b4b1551d4a6f1cfcc13b38e616c@agner.ch> <20200908084855.GH2352366@phenom.ffwll.local> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200908084855.GH2352366@phenom.ffwll.local> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 08, 2020 at 10:48:55AM +0200, Daniel Vetter wrote: > On Tue, Sep 08, 2020 at 11:18:25AM +0300, Tomi Valkeinen wrote: > > On 08/09/2020 10:55, Stefan Agner wrote: > > > On 2020-09-07 20:18, Daniel Vetter wrote: > > >> On Mon, Sep 07, 2020 at 07:17:12PM +0300, Laurent Pinchart wrote: > > >>> Hi Stefan, > > >>> > > >>> Thank you for the patch. > > >>> > > >>> On Mon, Sep 07, 2020 at 06:03:43PM +0200, Stefan Agner wrote: > > >>>> The lcdif IP does not support a framebuffer pitch (stride) other than > > >>>> the CRTC width. Check for equality and reject the state otherwise. > > >>>> > > >>>> This prevents a distorted picture when using 640x800 and running the > > >>>> Mesa graphics stack. Mesa tires to use a cache aligned stride, which > > >>> > > >>> s/tires/tries/ > > >>> > > >>>> leads at that particular resolution to width != stride. Currently > > >>>> Mesa has no fallback behavior, but rejecting this configuration allows > > >>>> userspace to handle the issue correctly. > > >>> > > >>> I'm increasingly impressed by how featureful this IP core is :-) > > >>> > > >>>> Signed-off-by: Stefan Agner > > >>>> --- > > >>>> drivers/gpu/drm/mxsfb/mxsfb_kms.c | 22 ++++++++++++++++++---- > > >>>> 1 file changed, 18 insertions(+), 4 deletions(-) > > >>>> > > >>>> diff --git a/drivers/gpu/drm/mxsfb/mxsfb_kms.c b/drivers/gpu/drm/mxsfb/mxsfb_kms.c > > >>>> index b721b8b262ce..79aa14027f91 100644 > > >>>> --- a/drivers/gpu/drm/mxsfb/mxsfb_kms.c > > >>>> +++ b/drivers/gpu/drm/mxsfb/mxsfb_kms.c > > >>>> @@ -403,14 +403,28 @@ static int mxsfb_plane_atomic_check(struct drm_plane *plane, > > >>>> { > > >>>> struct mxsfb_drm_private *mxsfb = to_mxsfb_drm_private(plane->dev); > > >>>> struct drm_crtc_state *crtc_state; > > >>>> + unsigned int pitch; > > >>>> + int ret; > > >>>> > > >>>> crtc_state = drm_atomic_get_new_crtc_state(plane_state->state, > > >>>> &mxsfb->crtc); > > >>>> > > >>>> - return drm_atomic_helper_check_plane_state(plane_state, crtc_state, > > >>>> - DRM_PLANE_HELPER_NO_SCALING, > > >>>> - DRM_PLANE_HELPER_NO_SCALING, > > >>>> - false, true); > > >>>> + ret = drm_atomic_helper_check_plane_state(plane_state, crtc_state, > > >>>> + DRM_PLANE_HELPER_NO_SCALING, > > >>>> + DRM_PLANE_HELPER_NO_SCALING, > > >>>> + false, true); > > >>>> + if (ret || !plane_state->visible) > > >>> > > >>> Would it be more explict to check for !plane_state->fb ? Otherwise I'll > > >>> have to verify that !fb always implies !visible :-) > > >>> > > >>>> + return ret; > > >>>> + > > >>>> + pitch = crtc_state->mode.hdisplay * > > >>>> + plane_state->fb->format->cpp[0]; > > >>> > > >>> This holds on a single line. > > >>> > > >>>> + if (plane_state->fb->pitches[0] != pitch) { > > >>>> + dev_err(plane->dev->dev, > > >>>> + "Invalid pitch: fb and crtc widths must be the same"); > > >>> > > >>> I'd turn this into a dev_dbg(), printing error messages to the kernel > > >>> log in response to user-triggered conditions is a bit too verbose and > > >>> could flood the log. > > >>> > > >>> Wouldn't it be best to catch this issue when creating the framebuffer ? > > >> > > >> Yeah this should be verified at addfb time. We try to validate as early as > > >> possible. > > > > > > Sounds sensible. From what I can tell fb_create is the proper callback > > > to implement this at addfb time. Will give this a try. > > > > > > FWIW, I got the idea from drivers/gpu/drm/tilcdc/tilcdc_plane.c. Maybe > > > should be moved to addfb there too? > > > > But you don't know the crtc width when creating the framebuffer. > > Hm right this is a different check. What we could check in fb_create for > both is that the logical fb size matches exactly the pitch. That's not > sufficient criteria, but it will at least catch some of them already. > > But yeah we'd need both here. Correct. At addfb time we can check the pitch, and at atomic check time we should check that the plane spans the whole CRTC. -- Regards, Laurent Pinchart