Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5644516img; Wed, 27 Mar 2019 12:19:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqwdyqhYj7xC/8PJOm3Sf3zKMU+bdI+5AGR3FsIXs9HDTq982K8sPZDnns7CxmaibTxf7Cet X-Received: by 2002:a65:6091:: with SMTP id t17mr35750061pgu.328.1553714378341; Wed, 27 Mar 2019 12:19:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553714378; cv=none; d=google.com; s=arc-20160816; b=E2/FP0L/SJQ9TElsNQLfbDiQqqRetxGJvwYhNvj2TgWOQnZRCvY32rK3bpVzKkHBB/ aidHQrVAyqnueXyJroBjJ8mp7KR2EKU1qgjECvV+dCGUkbTmu13YeLfGczFWdBVlDFA5 EajC25SyTqYZ/3xEvu80kjIF0LVmyB5uS8bM7WQzoMr7pk03K7n2E2h5309uClPoavUR F50OyTIuwIP2IPIL9+1ojzOHkMpnskSCY+NtKNLv5apVr5c77JcIoV0t6GdhoXwKEuna 97PJ3FYn4yjrdFhlhP34HWtokJ+ZcXXfCDnp4eLr0RWbfxJtJ398ACIZFLLuP5xFs5CJ 6BQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=YjebnsXoFkl+T5fFlKqGdQT0z+Vt5l+QA4pF/S8E5a4=; b=DA9ikJ1MGu/r5kcz9rL7kyqsyfvYv4GUJxJG6N8pmAMJjT1Pn0UKxqKB5px6s3ck3m IyDMyLJpNSJARCP4KHXm5g0DPTVQn9IyN2MENiwqV/3/9r6Nms0QHq4l7VfWMjrvF49m Zp94wmSmAlMpD6wzqb0De6onM/z6MctH5YcLFQf3nO4WOoRzOnRoprQC/4yjIXKzW5Rm RGV0bJlalDvBv4vNqqKNSW//ZNdCb/0K0oC+VvA81X5z8Sc7sdDecKEqMefIR+Vdxg7W HQb0dmOUBpExcYZ0ekVopucjBcjzuOSyFaVqRnDykIS2xBTlWvgjmNJlYgF9cPQveOoO jRAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="dhR3/Ad5"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1si21085116plw.390.2019.03.27.12.19.23; Wed, 27 Mar 2019 12:19:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="dhR3/Ad5"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388519AbfC0TSw (ORCPT + 99 others); Wed, 27 Mar 2019 15:18:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:49954 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388275AbfC0SH7 (ORCPT ); Wed, 27 Mar 2019 14:07:59 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C147D2184D; Wed, 27 Mar 2019 18:07:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553710078; bh=U4FrbHQVU5pAAR6QFdkGVBhH645KpOhMaj1MOvfwEtA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dhR3/Ad59opa0n03f0euYNt6oZmXB7ecQCk1fP4PMSPTJdASoCrGvWCdv5YKTpR3j HIbnT3dUUzgL2149pWPCD1D1wzZUpuGpsN/RDnOn0le0yGgMCn+kmFe9rb3XmykekR hBXI7Gh4uSmERzqDXO5EyUl8n93RrMgVzhxv7sgU= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Shayenne Moura , Daniel Vetter , Rodrigo Siqueira , Sasha Levin , dri-devel@lists.freedesktop.org Subject: [PATCH AUTOSEL 5.0 188/262] drm/vkms: Bugfix racing hrtimer vblank handle Date: Wed, 27 Mar 2019 14:00:43 -0400 Message-Id: <20190327180158.10245-188-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327180158.10245-1-sashal@kernel.org> References: <20190327180158.10245-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Shayenne Moura [ Upstream commit ba420afab565bdc7b028ddd4f222260f2de7a1db ] 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 Signed-off-by: Rodrigo Siqueira Link: https://patchwork.freedesktop.org/patch/msgid/e2e4b8f3a5cab7b2dba75bf1930f86b0a4ee08c9.1548856186.git.shayenneluzmoura@gmail.com Signed-off-by: Sasha Levin --- 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 eb56ee893761..53ab49408a98 100644 --- a/drivers/gpu/drm/vkms/vkms_crtc.c +++ b/drivers/gpu/drm/vkms/vkms_crtc.c @@ -4,13 +4,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"); @@ -31,19 +35,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; } -- 2.19.1