From patchwork Thu Jun 6 22:27:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 10980517 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 1DFDE14B6 for ; Thu, 6 Jun 2019 22:28:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D3CC1FFE4 for ; Thu, 6 Jun 2019 22:28:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 00DE027EE2; Thu, 6 Jun 2019 22:28:08 +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,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 785531FFE4 for ; Thu, 6 Jun 2019 22:28:08 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 878FB899DC; Thu, 6 Jun 2019 22:28:05 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3C48B899DC for ; Thu, 6 Jun 2019 22:28:03 +0000 (UTC) Received: by mail-ed1-x543.google.com with SMTP id c26so5581347edt.1 for ; Thu, 06 Jun 2019 15:28:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vQ7V/P5FFnDJXfv1tJb5nKMK43wXWwa030NP+k5b/b8=; b=mYXtL0J4zyKsAUqRkqpSMrF80er550Xt0w1mlDEiCAoH8Gs32B+ZOyF1FdH5u5U/ut ilGB7I2gckLztJgm4SVAhoYJXEhZeV5x9tfudv9t1PWEaq9smn9ipI4pUUPoJg46J3zf 1nQsf8eYXJeQXttac3lmDocfAj537/ErWsbY+spwQid7nP/eHrPJpTdG31WO+i5CwLe/ uJxCk82sZCm9rymxNU23JTFLj7aVItNM8iZk+zXM3JMALBOq9DvI1aWCGu71WwMvcDp4 N3qqU6AH1LjeBsy/Sscr6jw2UfMZ/sEjF03NTlHbZHpBlgBymr3u0u/LhwaX4k7A09MJ cbdQ== X-Gm-Message-State: APjAAAVhm2Egmfl4QfpDvGfIJLUEWTj5vuz8ZbKBY7dhVFDqeJL7YwME yHgg27WVLyEt63DywECbkZ/DtZTIRns= X-Google-Smtp-Source: APXvYqyrD16GZsSdZ/NZMC/tvezZJs7kY1WmL2Z9cu87PdvgMXKLb0wBZZXxLIAoDOQ/It5zaRZpFg== X-Received: by 2002:a50:90fa:: with SMTP id d55mr5690118eda.210.1559860081664; Thu, 06 Jun 2019 15:28:01 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:569e:0:3106:d637:d723:e855]) by smtp.gmail.com with ESMTPSA id z10sm54228edl.35.2019.06.06.15.28.00 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 06 Jun 2019 15:28:00 -0700 (PDT) From: Daniel Vetter To: DRI Development Subject: [PATCH 01/10] drm/vkms: Fix crc worker races Date: Fri, 7 Jun 2019 00:27:42 +0200 Message-Id: <20190606222751.32567-2-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190606222751.32567-1-daniel.vetter@ffwll.ch> References: <20190606222751.32567-1-daniel.vetter@ffwll.ch> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vQ7V/P5FFnDJXfv1tJb5nKMK43wXWwa030NP+k5b/b8=; b=eUqULvArI92+oduO5cgeszXWdEb1c30IwlIwJButpacKENrO21kWq2YSJscOLcEJoY ILMX1wDq0YcX3P833JYdpPjWrv8ZZUC9UKvDhH/w8+By9U5Ivt3PElmDJLSGecRdCyI4 yZ/TSqrhGJ7N+kGVfYzwWhelWAVMuU23rXJQQ= 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: Haneen Mohammed , Rodrigo Siqueira , Daniel Vetter , Shayenne Moura , Daniel Vetter Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP The issue we have is that the crc worker might fall behind. We've tried to handle this by tracking both the earliest frame for which it still needs to compute a crc, and the last one. Plus when the crtc_state changes, we have a new work item, which are all run in order due to the ordered workqueue we allocate for each vkms crtc. Trouble is there's been a few small issues in the current code: - we need to capture frame_end in the vblank hrtimer, not in the worker. The worker might run much later, and then we generate a lot of crc for which there's already a different worker queued up. - frame number might be 0, so create a new crc_pending boolean to track this without confusion. - we need to atomically grab frame_start/end and clear it, so do that all in one go. This is not going to create a new race, because if we race with the hrtimer then our work will be re-run. - only race that can happen is the following: 1. worker starts 2. hrtimer runs and updates frame_end 3. worker grabs frame_start/end, already reading the new frame_end, and clears crc_pending 4. hrtimer calls queue_work() 5. worker completes 6. worker gets re-run, crc_pending is false Explain this case a bit better by rewording the comment. v2: Demote warning level output to debug when we fail to requeue, this is expected under high load when the crc worker can't quite keep up. Cc: Shayenne Moura Cc: Rodrigo Siqueira Signed-off-by: Daniel Vetter Cc: Haneen Mohammed Cc: Daniel Vetter --- drivers/gpu/drm/vkms/vkms_crc.c | 27 +++++++++++++-------------- drivers/gpu/drm/vkms/vkms_crtc.c | 9 +++++++-- drivers/gpu/drm/vkms/vkms_drv.h | 2 ++ 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_crc.c b/drivers/gpu/drm/vkms/vkms_crc.c index d7b409a3c0f8..66603da634fe 100644 --- a/drivers/gpu/drm/vkms/vkms_crc.c +++ b/drivers/gpu/drm/vkms/vkms_crc.c @@ -166,16 +166,24 @@ void vkms_crc_work_handle(struct work_struct *work) struct drm_plane *plane; u32 crc32 = 0; u64 frame_start, frame_end; + bool crc_pending; unsigned long flags; spin_lock_irqsave(&out->state_lock, flags); frame_start = crtc_state->frame_start; frame_end = crtc_state->frame_end; + crc_pending = crtc_state->crc_pending; + crtc_state->frame_start = 0; + crtc_state->frame_end = 0; + crtc_state->crc_pending = false; spin_unlock_irqrestore(&out->state_lock, flags); - /* _vblank_handle() hasn't updated frame_start yet */ - if (!frame_start || frame_start == frame_end) - goto out; + /* + * We raced with the vblank hrtimer and previous work already computed + * the crc, nothing to do. + */ + if (!crc_pending) + return; drm_for_each_plane(plane, &vdev->drm) { struct vkms_plane_state *vplane_state; @@ -196,20 +204,11 @@ void vkms_crc_work_handle(struct work_struct *work) if (primary_crc) crc32 = _vkms_get_crc(primary_crc, cursor_crc); - frame_end = drm_crtc_accurate_vblank_count(crtc); - - /* queue_work can fail to schedule crc_work; add crc for - * missing frames + /* + * The worker can fall behind the vblank hrtimer, make sure we catch up. */ while (frame_start <= frame_end) drm_crtc_add_crc_entry(crtc, true, frame_start++, &crc32); - -out: - /* to avoid using the same value for frame number again */ - spin_lock_irqsave(&out->state_lock, flags); - crtc_state->frame_end = frame_end; - crtc_state->frame_start = 0; - spin_unlock_irqrestore(&out->state_lock, flags); } static int vkms_crc_parse_source(const char *src_name, bool *enabled) diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_crtc.c index 1bbe099b7db8..c727d8486e97 100644 --- a/drivers/gpu/drm/vkms/vkms_crtc.c +++ b/drivers/gpu/drm/vkms/vkms_crtc.c @@ -30,13 +30,18 @@ static enum hrtimer_restart vkms_vblank_simulate(struct hrtimer *timer) * has read the data */ spin_lock(&output->state_lock); - if (!state->frame_start) + if (!state->crc_pending) state->frame_start = frame; + else + DRM_DEBUG_DRIVER("crc worker falling behind, frame_start: %llu, frame_end: %llu\n", + state->frame_start, frame); + state->frame_end = frame; + state->crc_pending = true; spin_unlock(&output->state_lock); ret = queue_work(output->crc_workq, &state->crc_work); if (!ret) - DRM_WARN("failed to queue vkms_crc_work_handle"); + DRM_DEBUG_DRIVER("vkms_crc_work_handle already queued\n"); } spin_unlock(&output->lock); diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h index 81f1cfbeb936..3c7e06b19efd 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -56,6 +56,8 @@ struct vkms_plane_state { struct vkms_crtc_state { struct drm_crtc_state base; struct work_struct crc_work; + + bool crc_pending; u64 frame_start; u64 frame_end; }; From patchwork Thu Jun 6 22:27:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 10980519 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 E4A4A924 for ; Thu, 6 Jun 2019 22:28:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D2BC71FFE4 for ; Thu, 6 Jun 2019 22:28:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C68B627EE2; Thu, 6 Jun 2019 22:28:10 +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,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 809771FFE4 for ; Thu, 6 Jun 2019 22:28:10 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CA22F899DE; Thu, 6 Jun 2019 22:28:06 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8E366899DC for ; Thu, 6 Jun 2019 22:28:04 +0000 (UTC) Received: by mail-ed1-x543.google.com with SMTP id h10so5506435edi.13 for ; Thu, 06 Jun 2019 15:28:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1I9sMdTtsYXfYIr7rVQo1r0PCEJ8mmlZIw88kpA45qo=; b=Np+0uv5GKrc6lmo+Cb6MKdS6QlJDrEA+x3g7/a3hrtdwUbpWc3rIBTBnv4XbHP2hqs LLY0ToCzRNoKd1YJveipv5SYOVs5EPKBJquAsMA/7boU4g+iIM68JfQDxI1UYxOYQHcU cTokHIzXQ69IEyeWLTxVYhm6XYY/NLCm2oXTqIogeETU/yjmI4WFhQg1gYM4aBjYeO7e KuShHDLsgaX9p/GaoY7B2lpnwaaS8rp2wJGWIr2mZk3lDaPOKcFfR+K/j4pLwuMWGBdq SzE+cD8YYkuGxUcrQaTQ/s1WfqmrK1524SxPA7yr99iGfOinrz6OyRSiEBUnZD0d5Nnl nhjQ== X-Gm-Message-State: APjAAAVRJMWhkVSb6xAuiS6vSEt/C1cHTG5mkWutUTCfKAE8XhlgbRNL j5HXXreTYHNAivCD7fn53GAYNxuHybk= X-Google-Smtp-Source: APXvYqxiiMZqnvdDmL931VmKRhN7LSyDzl2GZzvV8oVEahTGrMuMjIiyY4uJDXKCXzAAqWjT2bK41A== X-Received: by 2002:a17:906:9256:: with SMTP id c22mr2586191ejx.172.1559860082918; Thu, 06 Jun 2019 15:28:02 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:569e:0:3106:d637:d723:e855]) by smtp.gmail.com with ESMTPSA id z10sm54228edl.35.2019.06.06.15.28.01 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 06 Jun 2019 15:28:02 -0700 (PDT) From: Daniel Vetter To: DRI Development Subject: [PATCH 02/10] drm/vkms: Use spin_lock_irq in process context Date: Fri, 7 Jun 2019 00:27:43 +0200 Message-Id: <20190606222751.32567-3-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190606222751.32567-1-daniel.vetter@ffwll.ch> References: <20190606222751.32567-1-daniel.vetter@ffwll.ch> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1I9sMdTtsYXfYIr7rVQo1r0PCEJ8mmlZIw88kpA45qo=; b=W/P2DUxM1+fk501VS2enDT/x/9MRepLNdmC+DjnJS7FOkNqL/TmL8hH4MUMuQjgd5c GGcqzqKEVS7xNebz2Gi6eqYc6Tk1q7ESAOCDhJRhU5/FW4XIIpVS+u3YbBT44C+qKlZm Bo768jZpwi7zoYOwJH04phINqZmXzzY7CRMlA= 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: Haneen Mohammed , Rodrigo Siqueira , Daniel Vetter , Shayenne Moura , Daniel Vetter Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP The worker is always in process context, no need for the _irqsafe version. Same for the set_source callback, that's only called from the debugfs handler in a syscall. Cc: Shayenne Moura Cc: Rodrigo Siqueira Signed-off-by: Daniel Vetter Cc: Haneen Mohammed Cc: Daniel Vetter Reviewed-by: Rodrigo Siqueira Tested-by: Rodrigo Siqueira --- drivers/gpu/drm/vkms/vkms_crc.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_crc.c b/drivers/gpu/drm/vkms/vkms_crc.c index 66603da634fe..883e36fe7b6e 100644 --- a/drivers/gpu/drm/vkms/vkms_crc.c +++ b/drivers/gpu/drm/vkms/vkms_crc.c @@ -167,16 +167,15 @@ void vkms_crc_work_handle(struct work_struct *work) u32 crc32 = 0; u64 frame_start, frame_end; bool crc_pending; - unsigned long flags; - spin_lock_irqsave(&out->state_lock, flags); + spin_lock_irq(&out->state_lock); frame_start = crtc_state->frame_start; frame_end = crtc_state->frame_end; crc_pending = crtc_state->crc_pending; crtc_state->frame_start = 0; crtc_state->frame_end = 0; crtc_state->crc_pending = false; - spin_unlock_irqrestore(&out->state_lock, flags); + spin_unlock_irq(&out->state_lock); /* * We raced with the vblank hrtimer and previous work already computed @@ -246,7 +245,6 @@ int vkms_set_crc_source(struct drm_crtc *crtc, const char *src_name) { struct vkms_output *out = drm_crtc_to_vkms_output(crtc); bool enabled = false; - unsigned long flags; int ret = 0; ret = vkms_crc_parse_source(src_name, &enabled); @@ -254,9 +252,9 @@ int vkms_set_crc_source(struct drm_crtc *crtc, const char *src_name) /* make sure nothing is scheduled on crtc workq */ flush_workqueue(out->crc_workq); - spin_lock_irqsave(&out->lock, flags); + spin_lock_irq(&out->lock); out->crc_enabled = enabled; - spin_unlock_irqrestore(&out->lock, flags); + spin_unlock_irq(&out->lock); return ret; } From patchwork Thu Jun 6 22:27:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 10980523 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 255FE924 for ; Thu, 6 Jun 2019 22:28:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 131DD1FFE4 for ; Thu, 6 Jun 2019 22:28:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 043DA27EE2; Thu, 6 Jun 2019 22:28:15 +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,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 9ED821FFE4 for ; Thu, 6 Jun 2019 22:28:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0675B89A14; Thu, 6 Jun 2019 22:28:11 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by gabe.freedesktop.org (Postfix) with ESMTPS id DEECF899DE for ; Thu, 6 Jun 2019 22:28:05 +0000 (UTC) Received: by mail-ed1-x544.google.com with SMTP id h10so5506510edi.13 for ; Thu, 06 Jun 2019 15:28:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9n5T0pbK/9rbszfRHEajQrYFqsuCJNcrkzXFCxa/AyY=; b=kEhRSGMZrllwWnTQ1WlO0ru9bd4sEdK9MGK9w5dlaRm0kOSCH+g9aTyRYInL8vaqkc wTI7oBsKCP7hwuTRP6BHA8/pN/SOAYAavWTc7N5y5Dpvp/wA0Evj7ac2++ua2tATU1av rNbKoOg66FuHIv6sYXBgzDK+0oq4xwXLMUfZgfHgupCqpHxsPmH+vi+XKfEeBK+bdB1S 29DivXlFL4CQvIl6GYnwFJjlaKyYHhU/AWvOLxdy8+F9Een/4DKVNM3KV2nW41C28qHK VU92+MhGlFyqu4O2Vciz2uTcrr1/eA7sE2w4ef2L6yy7PvH/aX7NsHr5jl/vJwJZzVdO COkQ== X-Gm-Message-State: APjAAAW25JIQe5mIhEZtvjnU+eQ51Wbuxw5Ast9KANb7D0mj95vEyqQT 4pDq4vamL3ZR7GcdQwv548+S67eUZkI= X-Google-Smtp-Source: APXvYqwVqUVWJSHJFusu/dy8XDlUe4N/K9Wog41VFGlqNQbqhzS1lOwUoFiiJ809Zp303ry9UzXaNg== X-Received: by 2002:aa7:c717:: with SMTP id i23mr14970613edq.26.1559860084188; Thu, 06 Jun 2019 15:28:04 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:569e:0:3106:d637:d723:e855]) by smtp.gmail.com with ESMTPSA id z10sm54228edl.35.2019.06.06.15.28.02 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 06 Jun 2019 15:28:03 -0700 (PDT) From: Daniel Vetter To: DRI Development Subject: [PATCH 03/10] drm/vkms: Rename vkms_output.state_lock to crc_lock Date: Fri, 7 Jun 2019 00:27:44 +0200 Message-Id: <20190606222751.32567-4-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190606222751.32567-1-daniel.vetter@ffwll.ch> References: <20190606222751.32567-1-daniel.vetter@ffwll.ch> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9n5T0pbK/9rbszfRHEajQrYFqsuCJNcrkzXFCxa/AyY=; b=a7PaLcaS03UrDMYAKB1DcTc0yxCI6chmpmTiQivH3ATj4rXAEcldIfRDxl25JD06ha O1RJkt/5YMWFrF7Bhtx4HxetqKW2Pe9OzkWjdrl4LW/lcKp+xDDYW4d3KIa/SpUIxIdD 7ru7Up2c20Tj8zrvo1MxBKQSQR3NNXdqJqiFQ= 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: Daniel Vetter , Haneen Mohammed , Rodrigo Siqueira , Daniel Vetter Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Plus add a comment about what it actually protects. It's very little. Signed-off-by: Daniel Vetter Cc: Rodrigo Siqueira Cc: Haneen Mohammed Cc: Daniel Vetter --- drivers/gpu/drm/vkms/vkms_crc.c | 4 ++-- drivers/gpu/drm/vkms/vkms_crtc.c | 6 +++--- drivers/gpu/drm/vkms/vkms_drv.h | 5 +++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_crc.c b/drivers/gpu/drm/vkms/vkms_crc.c index 883e36fe7b6e..96806cd35ad4 100644 --- a/drivers/gpu/drm/vkms/vkms_crc.c +++ b/drivers/gpu/drm/vkms/vkms_crc.c @@ -168,14 +168,14 @@ void vkms_crc_work_handle(struct work_struct *work) u64 frame_start, frame_end; bool crc_pending; - spin_lock_irq(&out->state_lock); + spin_lock_irq(&out->crc_lock); frame_start = crtc_state->frame_start; frame_end = crtc_state->frame_end; crc_pending = crtc_state->crc_pending; crtc_state->frame_start = 0; crtc_state->frame_end = 0; crtc_state->crc_pending = false; - spin_unlock_irq(&out->state_lock); + spin_unlock_irq(&out->crc_lock); /* * We raced with the vblank hrtimer and previous work already computed diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_crtc.c index c727d8486e97..55b16d545fe7 100644 --- a/drivers/gpu/drm/vkms/vkms_crtc.c +++ b/drivers/gpu/drm/vkms/vkms_crtc.c @@ -29,7 +29,7 @@ static enum hrtimer_restart vkms_vblank_simulate(struct hrtimer *timer) /* update frame_start only if a queued vkms_crc_work_handle() * has read the data */ - spin_lock(&output->state_lock); + spin_lock(&output->crc_lock); if (!state->crc_pending) state->frame_start = frame; else @@ -37,7 +37,7 @@ static enum hrtimer_restart vkms_vblank_simulate(struct hrtimer *timer) state->frame_start, frame); state->frame_end = frame; state->crc_pending = true; - spin_unlock(&output->state_lock); + spin_unlock(&output->crc_lock); ret = queue_work(output->crc_workq, &state->crc_work); if (!ret) @@ -224,7 +224,7 @@ int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc, drm_crtc_helper_add(crtc, &vkms_crtc_helper_funcs); spin_lock_init(&vkms_out->lock); - spin_lock_init(&vkms_out->state_lock); + spin_lock_init(&vkms_out->crc_lock); vkms_out->crc_workq = alloc_ordered_workqueue("vkms_crc_workq", 0); if (!vkms_out->crc_workq) diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h index 3c7e06b19efd..43d3f98289fe 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -57,6 +57,7 @@ struct vkms_crtc_state { struct drm_crtc_state base; struct work_struct crc_work; + /* below three are protected by vkms_output.crc_lock */ bool crc_pending; u64 frame_start; u64 frame_end; @@ -74,8 +75,8 @@ struct vkms_output { struct workqueue_struct *crc_workq; /* protects concurrent access to crc_data */ spinlock_t lock; - /* protects concurrent access to crtc_state */ - spinlock_t state_lock; + + spinlock_t crc_lock; }; struct vkms_device { From patchwork Thu Jun 6 22:27:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 10980521 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 375DB924 for ; Thu, 6 Jun 2019 22:28:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2564A1FFE4 for ; Thu, 6 Jun 2019 22:28:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 197FD27EE2; Thu, 6 Jun 2019 22:28:13 +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,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 CAC3C1FFE4 for ; Thu, 6 Jun 2019 22:28:12 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 664DD899F2; Thu, 6 Jun 2019 22:28:09 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) by gabe.freedesktop.org (Postfix) with ESMTPS id 05043899E8 for ; Thu, 6 Jun 2019 22:28:07 +0000 (UTC) Received: by mail-ed1-x543.google.com with SMTP id p26so5574353edr.2 for ; Thu, 06 Jun 2019 15:28:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JcC10ZyoZDavWbmDXKEQr+W/p2OzkIC6q2jW3fuhNlA=; b=CT8l3HLG4IPAThrjR9W1FlaY+yog/lMVqZY7QKyLmjkYQBL/e+iPbFHemgk9d5XorH zIWY079njwOreiIIjxnxBn6TC3A81es85MIT8k3+DJPjWgtRAfPkFZz8vkHuTvJb8UMy XUt9ogPXm6vubWrJHQxu2vMoe6n9pgnIHBOCgXE0oJ8IEopkq5Qe6aeT+J9Ali7YZBRq 4uHMgJ33K+i9GfkMcYvTLxzxez3oGmF2B+nQcKGdMPz3qv6FK70I+0hPDpsmjhGO7/X5 U5RkeR1rR+iIlKJ9w4iAH1zQT6MEz0bpSG6BJrNPyyaPVwgs1NNhV3A+mcGp7hdCXlyn yH0g== X-Gm-Message-State: APjAAAXRMryOhR7p1vBJpUBHpC6GhIdGdXIL6Z52eXiUnjUbcIeeemZt wFjXNeLhMO6Oydig8lTs1yMDgJkyVNE= X-Google-Smtp-Source: APXvYqymlEsL/nDKLYS4y8FANG1/CQzU63z6G7ewhxBdVhtYhDrm0O+3b6R/2PGZM77SnRn7S+Nqlw== X-Received: by 2002:a17:906:63c1:: with SMTP id u1mr43566484ejk.173.1559860085411; Thu, 06 Jun 2019 15:28:05 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:569e:0:3106:d637:d723:e855]) by smtp.gmail.com with ESMTPSA id z10sm54228edl.35.2019.06.06.15.28.04 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 06 Jun 2019 15:28:04 -0700 (PDT) From: Daniel Vetter To: DRI Development Subject: [PATCH 04/10] drm/vkms: Move format arrays to vkms_plane.c Date: Fri, 7 Jun 2019 00:27:45 +0200 Message-Id: <20190606222751.32567-5-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190606222751.32567-1-daniel.vetter@ffwll.ch> References: <20190606222751.32567-1-daniel.vetter@ffwll.ch> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JcC10ZyoZDavWbmDXKEQr+W/p2OzkIC6q2jW3fuhNlA=; b=hsAlW3OsRIjOtrES24cBdupyQ7buKf+X4op5wHPbYg/xTZntZsTtqarOblvbEZblN1 lyjwJL/+G0zETnrwbEyv4UpB4aFnUnxr/VdN7JUisgqqFRw9cfOFbW34kd1w5npoQ9zU xW1jYHZav6Wa4EZiNJo5H6F+gucumNJWw/f6E= 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: Daniel Vetter , Haneen Mohammed , Rodrigo Siqueira , Daniel Vetter Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP No need to have them multiple times. Signed-off-by: Daniel Vetter Cc: Rodrigo Siqueira Cc: Haneen Mohammed Cc: Daniel Vetter Reviewed-by: Rodrigo Siqueira Tested-by: Rodrigo Siqueira --- drivers/gpu/drm/vkms/vkms_drv.h | 8 -------- drivers/gpu/drm/vkms/vkms_plane.c | 8 ++++++++ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h index 43d3f98289fe..2a35299bfb89 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -20,14 +20,6 @@ extern bool enable_cursor; -static const u32 vkms_formats[] = { - DRM_FORMAT_XRGB8888, -}; - -static const u32 vkms_cursor_formats[] = { - DRM_FORMAT_ARGB8888, -}; - struct vkms_crc_data { struct drm_framebuffer fb; struct drm_rect src, dst; diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_plane.c index 0e67d2d42f0c..0fceb6258422 100644 --- a/drivers/gpu/drm/vkms/vkms_plane.c +++ b/drivers/gpu/drm/vkms/vkms_plane.c @@ -6,6 +6,14 @@ #include #include +static const u32 vkms_formats[] = { + DRM_FORMAT_XRGB8888, +}; + +static const u32 vkms_cursor_formats[] = { + DRM_FORMAT_ARGB8888, +}; + static struct drm_plane_state * vkms_plane_duplicate_state(struct drm_plane *plane) { From patchwork Thu Jun 6 22:27:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 10980527 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 A47EC14B6 for ; Thu, 6 Jun 2019 22:28:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 94F281FFE4 for ; Thu, 6 Jun 2019 22:28:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 890F127EE2; Thu, 6 Jun 2019 22:28: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,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 6E1CE1FFE4 for ; Thu, 6 Jun 2019 22:28:18 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6180289A1E; Thu, 6 Jun 2019 22:28:13 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ed1-x542.google.com (mail-ed1-x542.google.com [IPv6:2a00:1450:4864:20::542]) by gabe.freedesktop.org (Postfix) with ESMTPS id 62223899E8 for ; Thu, 6 Jun 2019 22:28:08 +0000 (UTC) Received: by mail-ed1-x542.google.com with SMTP id z25so5520822edq.9 for ; Thu, 06 Jun 2019 15:28:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=M8aVV8Ycuq5zy2NbzxYuNuov6VzzXc/ZD8f0NVGDkY4=; b=L9O9y6+5Kb3uDJlKTF+E447vLPzytK2bs97TtMjHlFkX5Tt8uZeBkz4UwUmjU5aWmp RxCwzmRQp/I0nhgxfrn7YpRApee/CUVhO+gGa7mNIyX6YSSSyS9RVwhuNgJKPRbofwMG 6odDod6JcVaDonR8oahFbJgj6MNmmTrXD9nnvYfRjaegV87VZBbVTLMlRwjwwt8zDwwz fZzzyTQQI7wUmmGCztOkaW/wQQNzRTI1NGnuX8vt2qQyatFH4o4YOc2SCV+iitcJgeNM f191Kh7C5M5dcbjaV+altNhrxHMkL3c+ZUrMwOKcTmr/jJnY2pn11qBvVNXoTG+2Xv+2 DR9Q== X-Gm-Message-State: APjAAAUvYRq+6bcuRfBNr1rZ9VVtV3yskya5LxLut7n0CzglFnAqnCRV 05CKYAZaPKqNvFuHJY/G9duUc5HhMB8= X-Google-Smtp-Source: APXvYqze8nixDCgbJZeZmta1OAUZvf3xuloQqTnO4cVn2C8/So0Qi4+nt8Hv0e5JZY7kj0vlmHJJGQ== X-Received: by 2002:a17:906:421a:: with SMTP id z26mr37200213ejk.6.1559860086548; Thu, 06 Jun 2019 15:28:06 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:569e:0:3106:d637:d723:e855]) by smtp.gmail.com with ESMTPSA id z10sm54228edl.35.2019.06.06.15.28.05 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 06 Jun 2019 15:28:05 -0700 (PDT) From: Daniel Vetter To: DRI Development Subject: [PATCH 05/10] drm/vkms: Add our own commit_tail Date: Fri, 7 Jun 2019 00:27:46 +0200 Message-Id: <20190606222751.32567-6-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190606222751.32567-1-daniel.vetter@ffwll.ch> References: <20190606222751.32567-1-daniel.vetter@ffwll.ch> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=M8aVV8Ycuq5zy2NbzxYuNuov6VzzXc/ZD8f0NVGDkY4=; b=A1kLRMnDvcFdxL9crW3qKCGX0rCjmJESBhvhw+OOWRXutSAgwVu/2wY69sdbnZ39/S hf3qg6aHY+ALVcr52hP2EF61rttWq4rpZQFpO5zC82P8SgTtKA4J0IA+F5LBZ6t5gOrk tY3o0t9wFp/UCtjJsD5uZo/EXlyGyKX9/P290= 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: Daniel Vetter , Haneen Mohammed , Rodrigo Siqueira , Daniel Vetter Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Just prep work, more will be done here in following patches. Signed-off-by: Daniel Vetter Cc: Rodrigo Siqueira Cc: Haneen Mohammed Cc: Daniel Vetter --- drivers/gpu/drm/vkms/vkms_drv.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c index 738dd6206d85..f677ab1d0094 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.c +++ b/drivers/gpu/drm/vkms/vkms_drv.c @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -58,6 +59,25 @@ static void vkms_release(struct drm_device *dev) destroy_workqueue(vkms->output.crc_workq); } +static void vkms_atomic_commit_tail(struct drm_atomic_state *old_state) +{ + struct drm_device *dev = old_state->dev; + + drm_atomic_helper_commit_modeset_disables(dev, old_state); + + drm_atomic_helper_commit_planes(dev, old_state, 0); + + drm_atomic_helper_commit_modeset_enables(dev, old_state); + + drm_atomic_helper_fake_vblank(old_state); + + drm_atomic_helper_commit_hw_done(old_state); + + drm_atomic_helper_wait_for_vblanks(dev, old_state); + + drm_atomic_helper_cleanup_planes(dev, old_state); +} + static struct drm_driver vkms_driver = { .driver_features = DRIVER_MODESET | DRIVER_ATOMIC | DRIVER_GEM, .release = vkms_release, @@ -80,6 +100,10 @@ static const struct drm_mode_config_funcs vkms_mode_funcs = { .atomic_commit = drm_atomic_helper_commit, }; +static const struct drm_mode_config_helper_funcs vkms_mode_config_helpers = { + .atomic_commit_tail = vkms_atomic_commit_tail, +}; + static int vkms_modeset_init(struct vkms_device *vkmsdev) { struct drm_device *dev = &vkmsdev->drm; @@ -91,6 +115,7 @@ static int vkms_modeset_init(struct vkms_device *vkmsdev) dev->mode_config.max_width = XRES_MAX; dev->mode_config.max_height = YRES_MAX; dev->mode_config.preferred_depth = 24; + dev->mode_config.helper_private = &vkms_mode_config_helpers; return vkms_output_init(vkmsdev); } From patchwork Thu Jun 6 22:27:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 10980529 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 CAD2714B6 for ; Thu, 6 Jun 2019 22:28:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B9DA0200E5 for ; Thu, 6 Jun 2019 22:28:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AE1E528942; Thu, 6 Jun 2019 22:28:20 +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,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 5F7C6200E5 for ; Thu, 6 Jun 2019 22:28:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5CACC89A34; Thu, 6 Jun 2019 22:28:15 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4BCF4899E8 for ; Thu, 6 Jun 2019 22:28:09 +0000 (UTC) Received: by mail-ed1-x544.google.com with SMTP id r18so5537422edo.7 for ; Thu, 06 Jun 2019 15:28:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mdVHhUEPyQ3YdnuuaIrRM+1lqOhVXRdBLWwFQABWNbM=; b=at7JMbS8vsnTGDqRaEs7mMNhyHbI7STHe8t/EUNQjNgCvBdt8YV51sMtiVXm2BSR4Y GL1rnKxDOtRETPNjRQ1p/5WMxHmRjWNIVJR9HFYgZQ7eJzws90uoynLX4op9SzokOklo wxaFBukIbRmDDhLl2x3KstZlamHuEBG5t+7Vn3JkhAFVQKLt24I12flNjzgbYc+UVsD1 iKQ8LhvMCYLY6NpN7UsPIVcLZT7t5hQlkJO99qpdguNO5j6cLlm4oDTA+9P2pYRhyJYb OC5tPbWbu8OyZ+vFoaUHG4rQXt//espkKpW1l3VzsNEdk9gsWjVRUnVzhcv+KRISm7iu 1yhg== X-Gm-Message-State: APjAAAVvWpH+jblpBguh7zCOzJtoSeSDHkjcnLpKF8EWd6uVQ49PazD8 0l4zfHPwudOjP7U+aYFPN5zghKNgOGg= X-Google-Smtp-Source: APXvYqwxZ0Rl/42tVCOCz3MdpjTDestlIY3cHmMG+jrJD6I8PhxJobTwdOz4B02m/CzeV3airKQQww== X-Received: by 2002:a05:6402:150c:: with SMTP id f12mr51244807edw.234.1559860087744; Thu, 06 Jun 2019 15:28:07 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:569e:0:3106:d637:d723:e855]) by smtp.gmail.com with ESMTPSA id z10sm54228edl.35.2019.06.06.15.28.06 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 06 Jun 2019 15:28:07 -0700 (PDT) From: Daniel Vetter To: DRI Development Subject: [PATCH 06/10] drm/vkms: flush crc workers earlier in commit flow Date: Fri, 7 Jun 2019 00:27:47 +0200 Message-Id: <20190606222751.32567-7-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190606222751.32567-1-daniel.vetter@ffwll.ch> References: <20190606222751.32567-1-daniel.vetter@ffwll.ch> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mdVHhUEPyQ3YdnuuaIrRM+1lqOhVXRdBLWwFQABWNbM=; b=BMN8rgqvpGhXpEHZY6vKA/51RBWX6x7t+aEHgdzMCZrvkWN9Hetl/UiKVZ+JLJOCQY aT56iqwocVufQWVy2+V22ljvYT2JLSJ+OWEWCoFIMMa7PGysillX0Qzc2gfCeu3pbHxP k3rkQDavg+kv5tL7XxUK5HDwWB3YYohhh14jE= 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: Daniel Vetter , Haneen Mohammed , Rodrigo Siqueira , Daniel Vetter Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Currently we flush pending crc workers very late in the commit flow, when we destry all the old crtc states. Unfortunately at that point the framebuffers are already unpinned (and our vaddr possible gone), so this isn't good. Also, the plane_states we need might also already be cleaned up, since cleanup order of state structures isn't well defined. Fix this by waiting for all crc workers of the old state to complete before we start any of the cleanup work. Note that this is not yet race-free, because the hrtimer and crc worker look at the wrong state pointers, but that will be fixed in subsequent patches. Signed-off-by: Daniel Vetter Cc: Rodrigo Siqueira Cc: Haneen Mohammed Cc: Daniel Vetter --- drivers/gpu/drm/vkms/vkms_crtc.c | 2 +- drivers/gpu/drm/vkms/vkms_drv.c | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_crtc.c index 55b16d545fe7..b6987d90805f 100644 --- a/drivers/gpu/drm/vkms/vkms_crtc.c +++ b/drivers/gpu/drm/vkms/vkms_crtc.c @@ -125,7 +125,7 @@ static void vkms_atomic_crtc_destroy_state(struct drm_crtc *crtc, __drm_atomic_helper_crtc_destroy_state(state); if (vkms_state) { - flush_work(&vkms_state->crc_work); + WARN_ON(work_pending(&vkms_state->crc_work)); kfree(vkms_state); } } diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c index f677ab1d0094..cc53ef88a331 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.c +++ b/drivers/gpu/drm/vkms/vkms_drv.c @@ -62,6 +62,9 @@ static void vkms_release(struct drm_device *dev) static void vkms_atomic_commit_tail(struct drm_atomic_state *old_state) { struct drm_device *dev = old_state->dev; + struct drm_crtc *crtc; + struct drm_crtc_state *old_crtc_state; + int i; drm_atomic_helper_commit_modeset_disables(dev, old_state); @@ -75,6 +78,13 @@ static void vkms_atomic_commit_tail(struct drm_atomic_state *old_state) drm_atomic_helper_wait_for_vblanks(dev, old_state); + for_each_old_crtc_in_state(old_state, crtc, old_crtc_state, i) { + struct vkms_crtc_state *vkms_state = + to_vkms_crtc_state(old_crtc_state); + + flush_work(&vkms_state->crc_work); + } + drm_atomic_helper_cleanup_planes(dev, old_state); } From patchwork Thu Jun 6 22:27:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 10980525 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 D2188924 for ; Thu, 6 Jun 2019 22:28:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C1A461FFE4 for ; Thu, 6 Jun 2019 22:28:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B517D27EE2; Thu, 6 Jun 2019 22:28:16 +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,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 5D6F21FFE4 for ; Thu, 6 Jun 2019 22:28:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5DA5C89A20; Thu, 6 Jun 2019 22:28:12 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) by gabe.freedesktop.org (Postfix) with ESMTPS id A838E89A08 for ; Thu, 6 Jun 2019 22:28:10 +0000 (UTC) Received: by mail-ed1-x543.google.com with SMTP id a8so5574747edx.3 for ; Thu, 06 Jun 2019 15:28:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kEwCoKMEU9hYC5cQlPLTZr8d/17Dvv8CqSbJ0oq0mBA=; b=AnL3q3yIrJV4CJ6ADFs7zOMR7ZV6/AK4TMhbyVwvINeGVHzTdycMvgZViq8hJvAMrT 5kGgkqH1DtLGtepjAPzH50s1Y5lTKJ+W0+RxeKjsLwL8pehXdmZE+6sntdzh85WkJ+F5 MKat4I3/Xy4EQRiBC6g8vcsz5sYjqKzW9O2Ay89zaskiWWNPTPNPLVmsOdKOunG09e8k ug4GMY4penLys+dhuwfLexmZEZ7B86TTTO44Q+Qu061iaVPweMwETCytpx4bh7vHW8XE EpDuDzBf046mqID1G0/7tekz7MCKNdFFap/UH9k3GjVkHSG0lBkufSQh8y6FcUAZyc1R RmvQ== X-Gm-Message-State: APjAAAVRU6ZnYfoPVCJI6mW+2ozyTKx332YIqVyz5Y3ZHpSVy6Ke6dNB zbUf1rIs6vHfre7l/CfhxzIsPyGF8rM= X-Google-Smtp-Source: APXvYqwLyX/DauxG+tOreWbM7W6K1M96l9h1v4GxpyRXMVqbJ+4bUBe3vdEIYaL2QhJGew3i9IT7/w== X-Received: by 2002:a17:906:2acf:: with SMTP id m15mr43817971eje.31.1559860088802; Thu, 06 Jun 2019 15:28:08 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:569e:0:3106:d637:d723:e855]) by smtp.gmail.com with ESMTPSA id z10sm54228edl.35.2019.06.06.15.28.07 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 06 Jun 2019 15:28:08 -0700 (PDT) From: Daniel Vetter To: DRI Development Subject: [PATCH 07/10] drm/vkms: Dont flush crc worker when we change crc status Date: Fri, 7 Jun 2019 00:27:48 +0200 Message-Id: <20190606222751.32567-8-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190606222751.32567-1-daniel.vetter@ffwll.ch> References: <20190606222751.32567-1-daniel.vetter@ffwll.ch> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kEwCoKMEU9hYC5cQlPLTZr8d/17Dvv8CqSbJ0oq0mBA=; b=UjjABmM5aKOzkwqOgwquO4ZPHTIxw1O7vdR7RJnRoQm3pRSvFYtRmPAaozfAce23OK MgQoaAcpUj6y758+j7ZL/kRM4Whk+nEHAXr7pp55SogKIcyAr9ndkP1XLUWFz0bi1HZZ 34LpvAlGXv/vFZPSjR9OaofqBapXrNkg04krQ= 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: Daniel Vetter , Haneen Mohammed , Rodrigo Siqueira , Daniel Vetter Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP The crc core code can cope with some late crc, the race is kinda unavoidable. So no need to flush pending workers, they'll complete in time. Signed-off-by: Daniel Vetter Cc: Rodrigo Siqueira Cc: Haneen Mohammed Cc: Daniel Vetter --- drivers/gpu/drm/vkms/vkms_crc.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_crc.c b/drivers/gpu/drm/vkms/vkms_crc.c index 96806cd35ad4..9d15e5e85830 100644 --- a/drivers/gpu/drm/vkms/vkms_crc.c +++ b/drivers/gpu/drm/vkms/vkms_crc.c @@ -249,9 +249,6 @@ int vkms_set_crc_source(struct drm_crtc *crtc, const char *src_name) ret = vkms_crc_parse_source(src_name, &enabled); - /* make sure nothing is scheduled on crtc workq */ - flush_workqueue(out->crc_workq); - spin_lock_irq(&out->lock); out->crc_enabled = enabled; spin_unlock_irq(&out->lock); From patchwork Thu Jun 6 22:27:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 10980531 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 BA0CB924 for ; Thu, 6 Jun 2019 22:28:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A7BFE1FFE4 for ; Thu, 6 Jun 2019 22:28:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9937A27EE2; Thu, 6 Jun 2019 22:28:22 +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,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 56A451FFE4 for ; Thu, 6 Jun 2019 22:28:22 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DE79A89A35; Thu, 6 Jun 2019 22:28:15 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ed1-x542.google.com (mail-ed1-x542.google.com [IPv6:2a00:1450:4864:20::542]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1D20589A08 for ; Thu, 6 Jun 2019 22:28:12 +0000 (UTC) Received: by mail-ed1-x542.google.com with SMTP id w13so5559843eds.4 for ; Thu, 06 Jun 2019 15:28:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XeDSyVtOXRXEHiR2W7B4DH9ZPXBdnhHGqP4dgrobpmo=; b=HJLVuHVakPg/kSNmhbHhTUndTrelbfEGZeFI3UxbialwyibasbzEHto9sP3w3DZ4ZV g/kOZn4bP6IUdaMx4yDj9pkTRk2Ra6K37Wh3AtoIGMNY/LoTHDVgtw7k8mlrMdYy/Nvq aka84h37n/qAX+aXNH384XYgmRjRjKSLQ8A33NcfeV8RLrWgcHUot4pzdiqu5Zhk4p+q 8TxWKCd+hMu+mkDROXSSOUt1oSzoLipMeMN4XMSL2V1nOnzF853UZxLZaFfLZkC5s6GY 7rfJJhMmn9mWxeFhLIlRlMuioXrGz1Fav8kDdhzwjLaD4p53Xxzf8izU2Bl1Upteq0B2 u57A== X-Gm-Message-State: APjAAAU7TK2UYN40aJqaoBm07LQRRW+CBVPKi7wn8fITiJkaRI9YIGlT +9h5b8Uj31vCgu2701pbiQtEFPMgGIA= X-Google-Smtp-Source: APXvYqzS2BVvGqtu3HGJ7jajln37Vr8QcwtLx1hDJn1g7LCVNa2z8TlQpJGaHavsPlgfCI/Fs5/W3Q== X-Received: by 2002:aa7:c402:: with SMTP id j2mr46664467edq.165.1559860089984; Thu, 06 Jun 2019 15:28:09 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:569e:0:3106:d637:d723:e855]) by smtp.gmail.com with ESMTPSA id z10sm54228edl.35.2019.06.06.15.28.08 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 06 Jun 2019 15:28:09 -0700 (PDT) From: Daniel Vetter To: DRI Development Subject: [PATCH 08/10] drm/vkms: No _irqsave within spin_lock_irq needed Date: Fri, 7 Jun 2019 00:27:49 +0200 Message-Id: <20190606222751.32567-9-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190606222751.32567-1-daniel.vetter@ffwll.ch> References: <20190606222751.32567-1-daniel.vetter@ffwll.ch> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XeDSyVtOXRXEHiR2W7B4DH9ZPXBdnhHGqP4dgrobpmo=; b=ceVHHuMhW3DSI1EL8qvoGn9laYfMHLlDtOzETk1/ebRTLtZWDcp68irwiKTPDYAwfO /wJp3x9zqvn2DcuatT9Gw38TFkpjEsFlSXbjRDB50w3vw3lca0mqpfsRb+M4CsFChFFb liFteu6lberZVyqDAVmLW5Ej+5qVK55qkeg6Y= 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: Daniel Vetter , Daniel Vetter Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP irqs are already off. Signed-off-by: Daniel Vetter Reviewed-by: Rodrigo Siqueira Tested-by: Rodrigo Siqueira --- drivers/gpu/drm/vkms/vkms_crtc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_crtc.c index b6987d90805f..48a793ba4030 100644 --- a/drivers/gpu/drm/vkms/vkms_crtc.c +++ b/drivers/gpu/drm/vkms/vkms_crtc.c @@ -183,17 +183,16 @@ static void vkms_crtc_atomic_flush(struct drm_crtc *crtc, struct drm_crtc_state *old_crtc_state) { struct vkms_output *vkms_output = drm_crtc_to_vkms_output(crtc); - unsigned long flags; if (crtc->state->event) { - spin_lock_irqsave(&crtc->dev->event_lock, flags); + spin_lock(&crtc->dev->event_lock); if (drm_crtc_vblank_get(crtc) != 0) drm_crtc_send_vblank_event(crtc, crtc->state->event); else drm_crtc_arm_vblank_event(crtc, crtc->state->event); - spin_unlock_irqrestore(&crtc->dev->event_lock, flags); + spin_unlock(&crtc->dev->event_lock); crtc->state->event = NULL; } From patchwork Thu Jun 6 22:27:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 10980533 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 676AB924 for ; Thu, 6 Jun 2019 22:28:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 56ACB1FFE4 for ; Thu, 6 Jun 2019 22:28:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4B0CC27EE2; Thu, 6 Jun 2019 22:28:24 +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,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 AD60A1FFE4 for ; Thu, 6 Jun 2019 22:28:23 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E190389A44; Thu, 6 Jun 2019 22:28:15 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) by gabe.freedesktop.org (Postfix) with ESMTPS id 888C589A34 for ; Thu, 6 Jun 2019 22:28:13 +0000 (UTC) Received: by mail-ed1-x543.google.com with SMTP id k8so3461037edr.11 for ; Thu, 06 Jun 2019 15:28:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SAiiI6VzkaAeDYl1tw4fgVAOH4SmvYxgGwYm8RdcpiY=; b=cCgM+WyVZgU0vGLXY2CwfiSGwVt3jocf0A3VhyX6kyfUtbn6gQvlZj7uf8c8+WYOQd evI7EyWjHZv0A4xbb484M0ppNNB2KNJZcyqL5ErEyoKHvZ6B+jLRXNRUbUNrLtGfIEIr rKTJ5wrt0LWyy3rZXepsq0kCBRngi5NaHW3ZvY1pirKZI2iIQ3rWBulKu95uZdmiFPkY c47mmpZkkN5kWZt02Xfn86+tATw0YwbUSv+W77YI4zoT7BpNDt9E5Cybg/5ueVKvUyD5 +dAWK32m8cTGqV2XkrroglXz9+9HdQcYEieNZ4rCN/PDk0KQqpKcBXvfkcm2vktzGYs3 4Dqw== X-Gm-Message-State: APjAAAV8pubeoSuql8tpz0dHLBjEpQ68aRGuoT2ADHwTA1vgddZ+QY/4 QlWVx8kJhkAeKPt+avz3t1H8ZulmZIE= X-Google-Smtp-Source: APXvYqxHNk2JTdfioKKSUuyPiNtWE/jv43ZBBcB3JNfIREvMhKkso8QEPbTm3pOv/fso8Qx5yb0pTg== X-Received: by 2002:a17:906:1f55:: with SMTP id d21mr42757738ejk.87.1559860091740; Thu, 06 Jun 2019 15:28:11 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:569e:0:3106:d637:d723:e855]) by smtp.gmail.com with ESMTPSA id z10sm54228edl.35.2019.06.06.15.28.10 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 06 Jun 2019 15:28:10 -0700 (PDT) From: Daniel Vetter To: DRI Development Subject: [PATCH 09/10] drm/vkms: totally reworked crc data tracking Date: Fri, 7 Jun 2019 00:27:50 +0200 Message-Id: <20190606222751.32567-10-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190606222751.32567-1-daniel.vetter@ffwll.ch> References: <20190606222751.32567-1-daniel.vetter@ffwll.ch> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SAiiI6VzkaAeDYl1tw4fgVAOH4SmvYxgGwYm8RdcpiY=; b=NngFIKOe+Kxi3Xi4NvzfKDuu36KAUR132mgkidS/r2/VFZND4ilEaTcoCF0ddpB4yD wnfIw6qyF13p3d0gJcDzUkLsLruhUobwhrOlntd3Q4vG8s0HBJtAV+rDehh+NTn9v7D3 mf1B1h27VTRq5myU+5k1ldCyVeyC8oaHuTZhk= 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: Daniel Vetter , Haneen Mohammed , Rodrigo Siqueira , Daniel Vetter Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP The crc computation worker needs to be able to get at some data structures and framebuffer mappings, while potentially more atomic updates are going on. The solution thus far is to copy relevant bits around, but that's very tedious. Here's a new approach, which tries to be more clever, but relies on a few not-so-obvious things: - crtc_state is always updated when a plane_state changes. Therefore we can just stuff plane_state pointers into a crtc_state. That solves the problem of easily getting at the needed plane_states. - with the flushing changes from previous patches the above also holds without races due to the next atomic update being a bit eager with cleaning up pending work - we always wait for all crc work items to complete before unmapping framebuffers. - we also need to make sure that the hrtimer fires off the right worker. Keep a new distinct crc_state pointer, under the vkms_output->lock protection for this. Note that crtc->state is updated very early in the atomic commit, way before we arm the vblank event - the vblank event should always match the buffers we use to compute the crc. This also solves an issue in the hrtimer, where we've accessed drm_crtc->state without holding the right locks (we held none - oops). - in the worker itself we can then just access the plane states we need, again solving a bunch of ordering and locking issues. Accessing plane->state requires locks, accessing the private vkms_crtc_state->active_planes pointer only requires that the memory doesn't get freed too early. The idea behind vkms_crtc_state->active_planes is that this would contain all visible planes, in z-order, as a first step towards a more generic blending implementation. Note that this patch also fixes races between prepare_fb/cleanup_fb and the crc worker accessing ->vaddr. Signed-off-by: Daniel Vetter Cc: Rodrigo Siqueira Cc: Haneen Mohammed Cc: Daniel Vetter --- drivers/gpu/drm/vkms/vkms_crc.c | 21 +++-------- drivers/gpu/drm/vkms/vkms_crtc.c | 60 +++++++++++++++++++++++++++++--- drivers/gpu/drm/vkms/vkms_drv.h | 9 ++++- 3 files changed, 67 insertions(+), 23 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_crc.c b/drivers/gpu/drm/vkms/vkms_crc.c index 9d15e5e85830..0d31cfc32042 100644 --- a/drivers/gpu/drm/vkms/vkms_crc.c +++ b/drivers/gpu/drm/vkms/vkms_crc.c @@ -159,11 +159,8 @@ void vkms_crc_work_handle(struct work_struct *work) crc_work); struct drm_crtc *crtc = crtc_state->base.crtc; struct vkms_output *out = drm_crtc_to_vkms_output(crtc); - struct vkms_device *vdev = container_of(out, struct vkms_device, - output); struct vkms_crc_data *primary_crc = NULL; struct vkms_crc_data *cursor_crc = NULL; - struct drm_plane *plane; u32 crc32 = 0; u64 frame_start, frame_end; bool crc_pending; @@ -184,21 +181,11 @@ void vkms_crc_work_handle(struct work_struct *work) if (!crc_pending) return; - drm_for_each_plane(plane, &vdev->drm) { - struct vkms_plane_state *vplane_state; - struct vkms_crc_data *crc_data; + if (crtc_state->num_active_planes >= 1) + primary_crc = crtc_state->active_planes[0]->crc_data; - vplane_state = to_vkms_plane_state(plane->state); - crc_data = vplane_state->crc_data; - - if (drm_framebuffer_read_refcount(&crc_data->fb) == 0) - continue; - - if (plane->type == DRM_PLANE_TYPE_PRIMARY) - primary_crc = crc_data; - else - cursor_crc = crc_data; - } + if (crtc_state->num_active_planes == 2) + cursor_crc = crtc_state->active_planes[1]->crc_data; if (primary_crc) crc32 = _vkms_get_crc(primary_crc, cursor_crc); diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_crtc.c index 48a793ba4030..14156ed70415 100644 --- a/drivers/gpu/drm/vkms/vkms_crtc.c +++ b/drivers/gpu/drm/vkms/vkms_crtc.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0+ #include "vkms_drv.h" +#include #include #include @@ -9,7 +10,7 @@ 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); + struct vkms_crtc_state *state; u64 ret_overrun; bool ret; @@ -23,6 +24,7 @@ static enum hrtimer_restart vkms_vblank_simulate(struct hrtimer *timer) if (!ret) DRM_ERROR("vkms failure on handling vblank"); + state = output->crc_state; if (state && output->crc_enabled) { u64 frame = drm_crtc_accurate_vblank_count(crtc); @@ -124,10 +126,9 @@ static void vkms_atomic_crtc_destroy_state(struct drm_crtc *crtc, __drm_atomic_helper_crtc_destroy_state(state); - if (vkms_state) { - WARN_ON(work_pending(&vkms_state->crc_work)); - kfree(vkms_state); - } + WARN_ON(work_pending(&vkms_state->crc_work)); + kfree(vkms_state->active_planes); + kfree(vkms_state); } static void vkms_atomic_crtc_reset(struct drm_crtc *crtc) @@ -156,6 +157,52 @@ static const struct drm_crtc_funcs vkms_crtc_funcs = { .verify_crc_source = vkms_verify_crc_source, }; +static int vkms_crtc_atomic_check(struct drm_crtc *crtc, + struct drm_crtc_state *state) +{ + struct vkms_crtc_state *vkms_state = to_vkms_crtc_state(state); + struct drm_plane *plane; + struct drm_plane_state *plane_state; + int i = 0, ret; + + if (vkms_state->active_planes) + return 0; + + ret = drm_atomic_add_affected_planes(state->state, crtc); + if (ret < 0) + return ret; + + drm_for_each_plane_mask(plane, crtc->dev, state->plane_mask) { + plane_state = drm_atomic_get_existing_plane_state(state->state, + plane); + WARN_ON(!plane_state); + + if (!plane_state->visible) + continue; + + i++; + } + + vkms_state->active_planes = kcalloc(i, sizeof(plane), GFP_KERNEL); + if (!vkms_state->active_planes) + return -ENOMEM; + vkms_state->num_active_planes = i; + + i = 0; + drm_for_each_plane_mask(plane, crtc->dev, state->plane_mask) { + plane_state = drm_atomic_get_existing_plane_state(state->state, + plane); + + if (!plane_state->visible) + continue; + + vkms_state->active_planes[i++] = + to_vkms_plane_state(plane_state); + } + + return 0; +} + static void vkms_crtc_atomic_enable(struct drm_crtc *crtc, struct drm_crtc_state *old_state) { @@ -197,10 +244,13 @@ static void vkms_crtc_atomic_flush(struct drm_crtc *crtc, crtc->state->event = NULL; } + vkms_output->crc_state = to_vkms_crtc_state(crtc->state); + spin_unlock_irq(&vkms_output->lock); } static const struct drm_crtc_helper_funcs vkms_crtc_helper_funcs = { + .atomic_check = vkms_crtc_atomic_check, .atomic_begin = vkms_crtc_atomic_begin, .atomic_flush = vkms_crtc_atomic_flush, .atomic_enable = vkms_crtc_atomic_enable, diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h index 2a35299bfb89..4e7450111d45 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -49,6 +49,10 @@ struct vkms_crtc_state { struct drm_crtc_state base; struct work_struct crc_work; + int num_active_planes; + /* stack of active planes for crc computation, should be in z order */ + struct vkms_plane_state **active_planes; + /* below three are protected by vkms_output.crc_lock */ bool crc_pending; u64 frame_start; @@ -62,12 +66,15 @@ struct vkms_output { struct hrtimer vblank_hrtimer; ktime_t period_ns; struct drm_pending_vblank_event *event; - bool crc_enabled; /* ordered wq for crc_work */ struct workqueue_struct *crc_workq; /* protects concurrent access to crc_data */ spinlock_t lock; + /* protected by @lock */ + bool crc_enabled; + struct vkms_crtc_state *crc_state; + spinlock_t crc_lock; }; From patchwork Thu Jun 6 22:27:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 10980535 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 1B39514B6 for ; Thu, 6 Jun 2019 22:28:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0B3DF200E5 for ; Thu, 6 Jun 2019 22:28:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F3ED228942; Thu, 6 Jun 2019 22:28:25 +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,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 A3D90200E5 for ; Thu, 6 Jun 2019 22:28:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BCF5889A5E; Thu, 6 Jun 2019 22:28:19 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7D91389A34 for ; Thu, 6 Jun 2019 22:28:14 +0000 (UTC) Received: by mail-ed1-x544.google.com with SMTP id m10so5543728edv.6 for ; Thu, 06 Jun 2019 15:28:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yYxrzPGYeHw5OKnXexCCG8lNOTvG3IHbPNWAvBtpsmI=; b=URVVIrAtm1HTCVi/Uf8XRpleIpjtRBahC4QhAGS3WXPEnnGKkV+YU+QWzg7UGI6e8R kCr1JTRMcPvGICKHY+B7v2+m8Q/9GJlpG+foNGTlTtqHnME/0X9ZxdWGPPC71I/+fPfD 1WmuTF4VjkKL0UsMB6ZAtO9MsSwL7T5QTkrvuZA23BYOsToENMIYeA7u/mf1IaGSuQQp Kkq9Js4xClorC2VQcvC1LAqlAVKNxkBuObai+cCGyNitplby6xSjls9zzZJcmoKH58qe kxP1jM/PkKZ0/A6lgaoCjKBIfT7Hd6hJ1VH4d7RQ4neR6P/iNry3Ho3OheYD6c11hyxl x81w== X-Gm-Message-State: APjAAAVOEnfENJ9fjwb4j3GBqsj9+FkLmzOuQxuRVKSSF/CcEOBdTUIA WsvrLTvXizAenI0DDpvRegc0dIXfDb0= X-Google-Smtp-Source: APXvYqya5iuaAVBG4/Y8pQZn1MIUN7WvXIgg0l+2jYiXmlKsCr0QTO5WDuvg20W4/5j4LhfZ8LqGEQ== X-Received: by 2002:a17:906:720e:: with SMTP id m14mr43943502ejk.84.1559860092786; Thu, 06 Jun 2019 15:28:12 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:569e:0:3106:d637:d723:e855]) by smtp.gmail.com with ESMTPSA id z10sm54228edl.35.2019.06.06.15.28.11 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 06 Jun 2019 15:28:12 -0700 (PDT) From: Daniel Vetter To: DRI Development Subject: [PATCH 10/10] drm/vkms: No need for ->pages_lock in crc work anymore Date: Fri, 7 Jun 2019 00:27:51 +0200 Message-Id: <20190606222751.32567-11-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190606222751.32567-1-daniel.vetter@ffwll.ch> References: <20190606222751.32567-1-daniel.vetter@ffwll.ch> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yYxrzPGYeHw5OKnXexCCG8lNOTvG3IHbPNWAvBtpsmI=; b=dPNMoNct0kA7A9xkJw+pe9BnOmIKZKimsUUdU+ILk47MVwLz4GSja4AZ2NpOBKi4BE g7bW2mZZiQlprq1A13wXN88BIH6eA6Jg2NKEIOJwCIQrWz0kTrla8RcBuv3xAfYo/zIV OeTpux51DgfEg/LBhZve+m+ShhzTKA5v2rMTQ= 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: Daniel Vetter , Haneen Mohammed , Rodrigo Siqueira , Daniel Vetter Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP We're now guaranteed to no longer race against prepare_fb/cleanup_fb, which means we can access ->vaddr without having to hold a lock. Before the previous patches it was fairly easy to observe the cursor ->vaddr being invalid, but that's now gone, so we can upgrade to a full WARN_ON. Signed-off-by: Daniel Vetter Cc: Rodrigo Siqueira Cc: Haneen Mohammed Cc: Daniel Vetter Reviewed-by: Rodrigo Siqueira Tested-by: Rodrigo Siqueira --- drivers/gpu/drm/vkms/vkms_crc.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_crc.c b/drivers/gpu/drm/vkms/vkms_crc.c index 0d31cfc32042..4b3146d83265 100644 --- a/drivers/gpu/drm/vkms/vkms_crc.c +++ b/drivers/gpu/drm/vkms/vkms_crc.c @@ -97,16 +97,10 @@ static void compose_cursor(struct vkms_crc_data *cursor_crc, cursor_obj = drm_gem_fb_get_obj(&cursor_crc->fb, 0); cursor_vkms_obj = drm_gem_to_vkms_gem(cursor_obj); - mutex_lock(&cursor_vkms_obj->pages_lock); - if (!cursor_vkms_obj->vaddr) { - DRM_WARN("cursor plane vaddr is NULL"); - goto out; - } + if (WARN_ON(!cursor_vkms_obj->vaddr)) + return; blend(vaddr_out, cursor_vkms_obj->vaddr, primary_crc, cursor_crc); - -out: - mutex_unlock(&cursor_vkms_obj->pages_lock); } static uint32_t _vkms_get_crc(struct vkms_crc_data *primary_crc, @@ -123,15 +117,12 @@ static uint32_t _vkms_get_crc(struct vkms_crc_data *primary_crc, return 0; } - mutex_lock(&vkms_obj->pages_lock); if (WARN_ON(!vkms_obj->vaddr)) { - mutex_unlock(&vkms_obj->pages_lock); kfree(vaddr_out); return crc; } memcpy(vaddr_out, vkms_obj->vaddr, vkms_obj->gem.size); - mutex_unlock(&vkms_obj->pages_lock); if (cursor_crc) compose_cursor(cursor_crc, primary_crc, vaddr_out);