From: Rodrigo Siqueira Subject: [PATCH] drm/vkms: Avoid extra discount in the timestamp value Date: Sun, 19 May 2019 21:12:08 -0300 Message-ID: <20190520001208.yh4jivl5lcc7iarh@smtp.gmail.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="uc56hyofhfino5qs" Return-path: Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org To: Ville Syrjala , Shayenne Moura , Haneen Mohammed , Daniel Vetter , David Airlie Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org List-Id: dri-devel@lists.freedesktop.org --uc56hyofhfino5qs Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable After the commit def35e7c5926 ("drm/vkms: Bugfix extra vblank frame") some of the crc tests (IGT) start to fail in the vkms with the following error: [drm:drm_crtc_add_crc_entry [drm]] *ERROR* Overflow of CRC buffer, userspace reads too slow. [drm] failed to queue vkms_crc_work_handle ... The commit def35e7c5926 ("drm/vkms: Bugfix extra vblank frame") added an operation for decrement the timestamp value returned by `get_vblank_timestamp()` which solved the problems related to kms_flip tests. However, each call to `get_vblank_timestamp()` reduces the timestamp even when it is not required. Such decrement generates a negative number in the following calculation within `drm_update_vblank_count()`: u64 diff_ns =3D ktime_to_ns(ktime_sub(t_vblank, vblank->time)); Next, the DIV_ROUND_CLOSEST_ULL macro is invoked using the diff_ns value, which generates an undefined result. Therefore, the returned frame is incorrect, which assign a huge number to the variable frame_end. In this case, causing the loop (`vkms_crc_work_handle()`) below to take a long time: frame_end =3D drm_crtc_accurate_vblank_count(crtc); while (frame_start <=3D frame_end) drm_crtc_add_crc_entry(crtc, true, frame_start++, &crc32); This commit fixes this issue by adding a check that validates whether the current vblank timestamp is still the same, thus avoiding excessive timestamp decrement of the timestamp value. Signed-off-by: Rodrigo Siqueira Signed-off-by: Shayenne Moura --- drivers/gpu/drm/vkms/vkms_crtc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_c= rtc.c index 7508815fac11..3ce60e66673e 100644 --- a/drivers/gpu/drm/vkms/vkms_crtc.c +++ b/drivers/gpu/drm/vkms/vkms_crtc.c @@ -74,9 +74,13 @@ bool vkms_get_vblank_timestamp(struct drm_device *dev, u= nsigned int pipe, { struct vkms_device *vkmsdev =3D drm_device_to_vkms_device(dev); struct vkms_output *output =3D &vkmsdev->output; + struct drm_vblank_crtc *vblank =3D &dev->vblank[pipe]; =20 *vblank_time =3D output->vblank_hrtimer.node.expires; =20 + if (*vblank_time =3D=3D vblank->time) + return true; + if (!in_vblank_irq) *vblank_time -=3D output->period_ns; =20 --=20 2.21.0 --uc56hyofhfino5qs Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEE4tZ+ii1mjMCMQbfkWJzP/comvP8FAlzh8NgACgkQWJzP/com vP9XZw/8DzjkHaVji5ckdIfVFUqa+07K3xDYWNMgtir03K2ftctLGRjXYxjPCJIi VhiEi1FYYOyU5ot9kBtC+swChiySN0CC/fMdsSfPi54aKHN4KCjHe/MI3KWHhRTy /vMoJ1fYYJ42Nx+jSxRDP0IJhOZ1xXmznaalIkg89iq29+T01KQ9ACyc3JwYP2TM VLBhwNXsSfv/X6FMsl6mZM5AJthTKQDOEffufzgIiUlblvIGVQ/X4C+H0T98Pla6 PXfwyJrC0APwnbA7pi7s2wTVEEbzoLLCyUCER/iQ9NNslhgFubVsiNrgZ8SuYC8T 89a2wyJjSMfBa0O858whjX7V3Q3ZyYtFzl3GVSglfgUhEbp8qxQIsXOnUqGD6Mhu oIwpTU5eRCrCkbOuzsHxxxdI1hLiobKvKjvR6ZU9ff8zIOhJrxwk4bwQyyIKOv8c nBtCKS5rQ2BdVn3oGw3LmF83Un8fR0eM70XVUqbj/GsXA+hceDEkaJ2455vPZzh1 L7hKH5oJ7MsuQTN488+voVdjj4nkiJVRLYH+rsqKynSRYUcTay8bcGm3l4IZ5d3T snsk2td5Rvs6esVgD9SGwOU4omevVcVDEZ7FAtryq/F/6wBEfMn3hd06qwzUMQpX MibkbrpiWUKk5TvRyPYZxs72Ks7iLrfqK9sacxRayXqvylPhrsU= =bRsS -----END PGP SIGNATURE----- --uc56hyofhfino5qs--