From: Jyri Sarha Subject: Re: [PATCH] drm/tilcdc: Force recalculation of vrefresh in tilcdc_crtc_set_mode() Date: Thu, 12 Oct 2017 13:15:54 +0300 Message-ID: <355e9d3f-a601-2a88-c576-83745f1ef7cd@ti.com> References: <1507801165-21285-1-git-send-email-jsarha@ti.com> <20171012095316.GA18038@pek-khao-d1> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: <20171012095316.GA18038@pek-khao-d1> Content-Language: en-GB Sender: stable-owner@vger.kernel.org To: Kevin Hao Cc: dri-devel@lists.freedesktop.org, airlied@linux.ie, tomi.valkeinen@ti.com, laurent.pinchart@ideasonboard.com, stable@vger.kernel.org List-Id: dri-devel@lists.freedesktop.org =EF=BB=BF Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Bu= siness ID: 0615521-4. Kotipaikka/Domicile: Helsinki On 10/12/17 12:53, Kevin Hao wrote: > On Thu, Oct 12, 2017 at 12:39:25PM +0300, Jyri Sarha wrote: >> We are using the vrefresh to check if we are too close to vertical >> sync to update the two framebuffer DMA registers and risk a >> collision. The vrefresh is coming from user space and normally it is >> not used for anything. For instance xserver leaves vrefresh to zero >> causing a division by zero when setting the mode. We want to make sure >> the value is valid and force its recalculation in >> tilcdc_crtc_set_mode(). >> >> Reported-by: Kevin Hao >> Fixes: 11abbc9f39e0 ("drm/tilcdc: Set framebuffer DMA address to HW only= if CRTC is enabled") >> Cc: # v4.11+ >> Signed-off-by: Jyri Sarha >> --- >> drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 10 ++++++++++ >> 1 file changed, 10 insertions(+) >> >> diff --git a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c b/drivers/gpu/drm/tilc= dc/tilcdc_crtc.c >> index 704db24..aa5e87c 100644 >> --- a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c >> +++ b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c >> @@ -459,6 +459,16 @@ static void tilcdc_crtc_set_mode(struct drm_crtc *c= rtc) >> drm_framebuffer_get(fb); >> =20 >> crtc->hwmode =3D crtc->state->adjusted_mode; >> + >> + /* We are using the vrefresh to check if we are too close to >> + * vertical sync to update the two framebuffer DMA registers >> + * and risk a collision. The vrefresh is coming from user >> + * space and normally it is not used for anything. We want to >> + * make sure the value is valid and force its recalculation >> + * here. >> + */ >> + crtc->hwmode.vrefresh =3D 0; >=20 > Why do we need this? >=20 The drm_mode_vrefresh() [1] checks if the vrefresh is > 0 and only calculates it if it is not. I want to make sure the value is correct by recalculating it always. This is to prevent buggy user space SW from causing undefined behaviour. Best regards, Jyri [1] int drm_mode_vrefresh(const struct drm_display_mode *mode) { int refresh =3D 0; unsigned int calc_val; if (mode->vrefresh > 0) refresh =3D mode->vrefresh; else if (mode->htotal > 0 && mode->vtotal > 0) { int vtotal; vtotal =3D mode->vtotal; /* work out vrefresh the value will be x1000 */ calc_val =3D (mode->clock * 1000); calc_val /=3D mode->htotal; refresh =3D (calc_val + vtotal / 2) / vtotal; if (mode->flags & DRM_MODE_FLAG_INTERLACE) refresh *=3D 2; if (mode->flags & DRM_MODE_FLAG_DBLSCAN) refresh /=3D 2; if (mode->vscan > 1) refresh /=3D mode->vscan; } return refresh; }