From patchwork Wed Jan 30 16:07:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shayenne Moura X-Patchwork-Id: 10788907 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 798C713BF for ; Wed, 30 Jan 2019 16:07:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 64A0D2FB57 for ; Wed, 30 Jan 2019 16:07:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 577D42FBA5; Wed, 30 Jan 2019 16:07:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0C0A02FB57 for ; Wed, 30 Jan 2019 16:07:19 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 26A5D8954A; Wed, 30 Jan 2019 16:07:18 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qt1-x844.google.com (mail-qt1-x844.google.com [IPv6:2607:f8b0:4864:20::844]) by gabe.freedesktop.org (Postfix) with ESMTPS id F15338954A for ; Wed, 30 Jan 2019 16:07:16 +0000 (UTC) Received: by mail-qt1-x844.google.com with SMTP id t13so76662qtn.3 for ; Wed, 30 Jan 2019 08:07:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=tEC/1d7HwlRgQF4JsIh02lHiS2ctUBvLOXuE7PW9NQU=; b=Jy3cvsMv2MkjvGEFfn9ODVXBNcK1pjcHMlz4oEh1SwVgGlVrFpErsU0Pda02T6jJo/ ZxoQ6JMc1FN01FeR6vOn9nUutfJ8HhbU/APOr7HKumWzZ7fGahm1vWH/SjAiNw8TalRQ /i1gEsfqQj13Os8KfbMoGm3ubfO5xlaV7ELCgyclYN4zVqqINZjCq3nAq7+lum54lYFc YKK6JaapfqKpNeVxwzt58hwMNj+UoyNvMoFmKuTO6Qn8HvjCo0x56eEnAWQ5j1OfHIwG 6yAl1ng6KnuONbNjsvw0OtTxrI+bQ+9Vz9usoSMf5z3bUFTeXPeq+maHXJIzz9Yt08xC 3PoQ== X-Gm-Message-State: AJcUukdP7iIzMEc5f0nRMv0FngDsToX0lQvLFibgZ8WPma3PVTxmLrAR eI12BlRGvScv0RxjCHey+aA= X-Google-Smtp-Source: ALg8bN5ZMOX1R8ucVKpM3hmvserhCd+POspecpXR13DEX2Dyq1hh/KUUwWW3wye6g80YGd9ti0Du3w== X-Received: by 2002:a0c:81c4:: with SMTP id 4mr30036967qve.156.1548864436074; Wed, 30 Jan 2019 08:07:16 -0800 (PST) Received: from smtp.gmail.com ([143.107.45.1]) by smtp.gmail.com with ESMTPSA id d85sm1790571qkb.89.2019.01.30.08.07.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 30 Jan 2019 08:07:15 -0800 (PST) Date: Wed, 30 Jan 2019 14:07:11 -0200 From: Shayenne Moura To: Rodrigo Siqueira , Haneen Mohammed , Daniel Vetter , David Airlie Subject: [PATCH 2/2] drm: vkms: Bugfix racing hrtimer vblank handle Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20171215 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP When the vblank irq happens, kernel time subsystem executes `vkms_vblank_simulate`. In parallel or not, it prepares all stuff necessary to the next vblank with arm, and it must flush these stuff before the next vblank irq. However, vblank counter is ahead when arm is executed in parallel with handle vblank. CPU 0: CPU 1: | | atomic_commit_tail is ongoing | | | | hrtimer: vkms_vblank_simulate() | | | drm_crtc_handle_vblank() | | drm_crtc_arm_vblank() | | | ->get_vblank_timestamp() | | | | hrtimer_forward_now() Then, we should guarantee that the vblank interval time is correct (not changed) before finish the vblank handle. Fix the bug including the call to `hrtimer_forward_now()` in the same lock of `drm_crtc_handle_vblank()` to ensure that the timestamp update is correct when finish the vblank handle. Signed-off-by: Shayenne Moura Signed-off-by: Daniel Vetter Reviewed-by: Rodrigo Siqueira --- drivers/gpu/drm/vkms/vkms_crtc.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_crtc.c index 23146ff2a25b..5a095610726b 100644 --- a/drivers/gpu/drm/vkms/vkms_crtc.c +++ b/drivers/gpu/drm/vkms/vkms_crtc.c @@ -10,13 +10,17 @@ #include #include -static void _vblank_handle(struct vkms_output *output) +static enum hrtimer_restart vkms_vblank_simulate(struct hrtimer *timer) { + struct vkms_output *output = container_of(timer, struct vkms_output, + vblank_hrtimer); struct drm_crtc *crtc = &output->crtc; struct vkms_crtc_state *state = to_vkms_crtc_state(crtc->state); + int ret_overrun; bool ret; spin_lock(&output->lock); + ret = drm_crtc_handle_vblank(crtc); if (!ret) DRM_ERROR("vkms failure on handling vblank"); @@ -37,19 +41,9 @@ static void _vblank_handle(struct vkms_output *output) DRM_WARN("failed to queue vkms_crc_work_handle"); } - spin_unlock(&output->lock); -} - -static enum hrtimer_restart vkms_vblank_simulate(struct hrtimer *timer) -{ - struct vkms_output *output = container_of(timer, struct vkms_output, - vblank_hrtimer); - int ret_overrun; - - _vblank_handle(output); - ret_overrun = hrtimer_forward_now(&output->vblank_hrtimer, output->period_ns); + spin_unlock(&output->lock); return HRTIMER_RESTART; }