Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4180462pxk; Tue, 8 Sep 2020 12:47:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwLFGCgi/7uF/Z7aTi+VwNFHiqrYPHe2LKY/ihwlkcSh+ac/Dw68xYDJUFD2YZ2qDXITr17 X-Received: by 2002:aa7:ca4f:: with SMTP id j15mr660507edt.378.1599594440441; Tue, 08 Sep 2020 12:47:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599594440; cv=none; d=google.com; s=arc-20160816; b=CZ6dnR9ewq2NfWek2qZr0mwCIya937fgk9mhBVxZPcUrvRStgkdOLftDa5XPynxSlf JUBFFp9m4dwGEXWOMtVSpNVi9aOalJ9QONk93BmAU7Uo6vDTz+7b44TcGqlAO0Q1UDeM R3y+vdeIrvMsotkp6Nq6rwLcMsoMCTADbJLxG5MIU5EWEWLoGbt2806g5oBo3ZfJgg6m 0xHvuUBuFsTP76xjyBUyValeT67CWn7CqUi5uiclfi7FzT+Wr8pDlYv1IZ4DRDNFGAIN Bx2g22yrEPqVTBSs/XLhoMPxGPGKHx93dSYZsmO73bb3Sfw5snqr+HxezTDovDusxzAv DiGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=EvP5wxO99gZBW1/GgVybgs8x6Qa2e+TG1rM2skLb3n8=; b=lSffJi3+n72H19CF2ir3HC1JAVXGRrWS5B/GdKxUHhON+nbGF1TGhAYV/XIv6OMh1N wW9uy/fBi2H1ivwBF2fT5dviZ53IqzxywfrwdilVIyn0sS3QNhJDZ/c3UAjY7mreEkQb uPicSn1Qf9oW67asabSA7ySwb4vKRZj4qt6yVrS/Sfa+OFP5DJmBWjtN2cAFUcVh4R/Q XGRTtz50D0wVJ14OfeBs5JY8lPVIa1ntiSNSi020owNQVu6rKReuCFBJX2bZF+0zCXP9 Ah0i7CdsyLTh+JxT+fZJml2ia9KxEZfj6BxVyuDBgCoHYXIaBrL3K0YnNH7OtKj5bWfZ qeVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=SxjZumxD; 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 hh9si26900ejb.38.2020.09.08.12.46.57; Tue, 08 Sep 2020 12:47:20 -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 header.i=@ffwll.ch header.s=google header.b=SxjZumxD; 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 S1732381AbgIHTnD (ORCPT + 99 others); Tue, 8 Sep 2020 15:43:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730893AbgIHPwr (ORCPT ); Tue, 8 Sep 2020 11:52:47 -0400 Received: from mail-ot1-x341.google.com (mail-ot1-x341.google.com [IPv6:2607:f8b0:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08DCDC061386 for ; Tue, 8 Sep 2020 05:29:14 -0700 (PDT) Received: by mail-ot1-x341.google.com with SMTP id a65so14653055otc.8 for ; Tue, 08 Sep 2020 05:29:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=EvP5wxO99gZBW1/GgVybgs8x6Qa2e+TG1rM2skLb3n8=; b=SxjZumxDfk+p1Z5e+pGMFDZSyQBZfaolz6fGUKsKeOL5tEPmnxx/fKBJk8atljXnpf dS43UY5yxUeXlCPx9mrR1XFnfE1V6Jl3iTWzX5V3gztH23ltRxBz4zutOgsRUmVZr240 Tx3/Yfh09teKN/ZiNjXoOI19gw7Tr0Elfr1E4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=EvP5wxO99gZBW1/GgVybgs8x6Qa2e+TG1rM2skLb3n8=; b=I8+X4xFyCCUMEkmC0t3lrMfsML5mW5TrC2g3y/OaV4MkPbGRjaok2M2MhIpKStaSrQ 1u4yAHfaT+cOZgn2UzeWvZv9KJooTRCubl/tPsRf3+r4Cnscn1JVeYUqXza3ba3rkANk EaWhf4AUORebZj/GgYUpErRf0utiHgnMFSxXzdgPMYB+aHpuz+8rMcMnKmboF5npRpFg GKTVStPgAcNt7qQ7P+4iNClOLrAhBBsw4RaltPjFA4Idwt2BZrNB32eZFVBgsi6ZkUeF HVRglLoWv3HZqU6jYZmXg3rRjaygdCxO+WIaGfYukkS6HFy7/GxJxXMsXYY1aXBK8Kvw Ss8Q== X-Gm-Message-State: AOAM530+/8cBL82SMzyUJ5f1kLWor9FVkgG8Ht8/n3eGccPQ56PEvcUc Ug61dq5Y1+IfIe8JPuUqxS/gSDNEh38nbWZ4htntRw== X-Received: by 2002:a9d:4b99:: with SMTP id k25mr12321360otf.281.1599568153380; Tue, 08 Sep 2020 05:29:13 -0700 (PDT) MIME-Version: 1.0 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> In-Reply-To: From: Daniel Vetter Date: Tue, 8 Sep 2020 14:29:02 +0200 Message-ID: Subject: Re: [PATCH] drm: mxsfb: check framebuffer pitch To: Stefan Agner Cc: Tomi Valkeinen , Laurent Pinchart , Jyri Sarha , Marek Vasut , Dave Airlie , Shawn Guo , Sascha Hauer , Sascha Hauer , Fabio Estevam , dl-linux-imx , dri-devel , Linux ARM , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 8, 2020 at 2:07 PM Stefan Agner wrote: > > On 2020-09-08 10:48, Daniel Vetter wrote: > > On Tue, Sep 08, 2020 at 11:18:25AM +0300, Tomi Valkeinen wrote: > >> Hi, > >> > >> 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. > >> >> -Daniel > >> >> > >> > > >> > 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. > > After validating width of framebuffer against pitch, the only thing we > need to check here is that the width matches. From what I can tell, > least for mxsfb, this should be covered by > drm_atomic_helper_check_plane_state's can_position parameter set to > false. This only checks against the src rectangle of the crtc state, there's nothing forcing that the size of the fb matches the src rectangle exactly. I guess we could maybe add that as another parameter for hw like yours or tilcdc. Naming is a bit tricky, maybe require_matching_fb or src_must_match_fb or something like that. > So I think in my case I can get away by only checking the framebuffer. You still need both I think. -Daniel > > -- > Stefan > > > > -Daniel > > > >> > >> Tomi > >> > >> -- > >> Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. > >> Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch