From patchwork Wed Aug 24 16:13:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12953796 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0447DC00140 for ; Wed, 24 Aug 2022 16:16:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9DEA2BA490; Wed, 24 Aug 2022 16:16:14 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id 14719B9FBB for ; Wed, 24 Aug 2022 16:13:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661357617; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZdQAnurZVFdXXS4WbKVSyp7TafzRJAbZ0GKKLX98Mwk=; b=bVQijYKGkGPqFmKsF0QqFV1gOX2KkTaRDQdJb0IEzZhzNJ4ifJNKS/uApWOHKLtrAFWK/V DiYlwz3a/lt2hCyeqTWXwfMBU9vTERJWoM0zX1eter1CnTMX5q+fAAUpIGlkR0M4+AHK7I chTriMOpWB3VCeUDzufKvXrq5gb38Rs= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-583-tlDqaBz2Nv2QMkENSTdYJA-1; Wed, 24 Aug 2022 12:13:36 -0400 X-MC-Unique: tlDqaBz2Nv2QMkENSTdYJA-1 Received: by mail-ej1-f70.google.com with SMTP id sd6-20020a1709076e0600b0073315809fb5so5363488ejc.10 for ; Wed, 24 Aug 2022 09:13:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=ZdQAnurZVFdXXS4WbKVSyp7TafzRJAbZ0GKKLX98Mwk=; b=kbC0nauzaD/pUqzBFfE4suNJz0+665ttVjOBg1AiXPVFN5joRjC32Q+0Jg5JcrwXi1 9+cLYS36lAexh/7xP/ZPTw5W3x0F0D8voTkuQjYRtTeJoEedM/QFgCr8vPHzLjrfG0rZ s7ca/QcKolhckcvPiVH0C2tU5WFYNXmGDlpdugi4a8OxG4PJnM1zDPaV4oeLTZZAK5SH V5deVkFDujVJ5PIECdnOkVkXvO+Fsh3aw1C1B2kiU9tsiG0RyJsXxPAmm9jigzFLtkdD +dPO8KE7pvAA3ZIpKqTexANK4GdAH4jAzpY3PTBghv77qqDP63lw3jN6euk3+VzOZb7p 9dvA== X-Gm-Message-State: ACgBeo3UgLo+loXTXQosZHzEoTWU91VumZVbyg/47dhVC6zhN6zbqrJ2 2uRVeGAHE59/oC8xOINxShCjoCgWsNq6e5Jx/Ps46hUFzaV4/VHnDYDdtdWnWWvjNoZA2Al64lr pgycPNEt7cTdM7sp6PtymiwY6A5NE X-Received: by 2002:a17:906:9c82:b0:6e1:2c94:1616 with SMTP id fj2-20020a1709069c8200b006e12c941616mr3454487ejc.64.1661357615194; Wed, 24 Aug 2022 09:13:35 -0700 (PDT) X-Google-Smtp-Source: AA6agR4Mb+JsUJPSZ781aWuV8ZoottRuEPEwvAH6ZrSbdG24VdAHADDW9+L0oDsP/xOp2REIksyfBg== X-Received: by 2002:a17:906:9c82:b0:6e1:2c94:1616 with SMTP id fj2-20020a1709069c8200b006e12c941616mr3454478ejc.64.1661357615040; Wed, 24 Aug 2022 09:13:35 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id da12-20020a056402176c00b004478fdbe190sm791536edb.10.2022.08.24.09.13.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Aug 2022 09:13:34 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org Subject: [PATCH drm-misc-next v3 1/4] drm/vc4: hdmi: unlock mutex when device is unplugged Date: Wed, 24 Aug 2022 18:13:24 +0200 Message-Id: <20220824161327.330627-2-dakr@redhat.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220824161327.330627-1-dakr@redhat.com> References: <20220824161327.330627-1-dakr@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Danilo Krummrich , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" In vc4_hdmi_encoder_{pre,post}_crtc_enable() commit cd00ed5187bf ("drm/vc4: hdmi: Protect device resources after removal") missed to unlock the mutex before returning due to drm_dev_enter() indicating the device being unplugged. Fixes: cd00ed5187bf ("drm/vc4: hdmi: Protect device resources after removal") Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/vc4/vc4_hdmi.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c index 84e5a91c2ea7..4d3ff51ad2a8 100644 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c @@ -1425,7 +1425,7 @@ static void vc4_hdmi_encoder_pre_crtc_enable(struct drm_encoder *encoder, mutex_lock(&vc4_hdmi->mutex); if (!drm_dev_enter(drm, &idx)) - return; + goto out; if (vc4_hdmi->variant->csc_setup) vc4_hdmi->variant->csc_setup(vc4_hdmi, conn_state, mode); @@ -1436,6 +1436,7 @@ static void vc4_hdmi_encoder_pre_crtc_enable(struct drm_encoder *encoder, drm_dev_exit(idx); +out: mutex_unlock(&vc4_hdmi->mutex); } @@ -1455,7 +1456,7 @@ static void vc4_hdmi_encoder_post_crtc_enable(struct drm_encoder *encoder, mutex_lock(&vc4_hdmi->mutex); if (!drm_dev_enter(drm, &idx)) - return; + goto out; spin_lock_irqsave(&vc4_hdmi->hw_lock, flags); @@ -1516,6 +1517,8 @@ static void vc4_hdmi_encoder_post_crtc_enable(struct drm_encoder *encoder, vc4_hdmi_enable_scrambling(encoder); drm_dev_exit(idx); + +out: mutex_unlock(&vc4_hdmi->mutex); } From patchwork Wed Aug 24 16:13:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12953794 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 79C3CC38142 for ; Wed, 24 Aug 2022 16:14:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C8D41BA111; Wed, 24 Aug 2022 16:14:08 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8B679B9FC9 for ; Wed, 24 Aug 2022 16:13:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661357621; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=shnv9nDHn9uoBkujzrrhLdUD67s9BTHB9Z1Ctk5SIAU=; b=Zq4nFlr7SaFgj1oYWXw9tGDx0rOl2nctt9PXYhJPBiCd+SK4g8rXETx6RYAnGEql1wCS7v R1ihd8v0hhSBqqPojfHC8ityJuPd13px6Rj1FhJhKBLOnMo45Ckxh3NSjkYcXIxf7poQao HxR+kSk6RBeryX2MTCnxEK7ZLzJP4Kc= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-637-DHPYrg-XMauS8e75Kqcz2w-1; Wed, 24 Aug 2022 12:13:39 -0400 X-MC-Unique: DHPYrg-XMauS8e75Kqcz2w-1 Received: by mail-ed1-f69.google.com with SMTP id f20-20020a05640214d400b004470930f180so4057047edx.10 for ; Wed, 24 Aug 2022 09:13:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=shnv9nDHn9uoBkujzrrhLdUD67s9BTHB9Z1Ctk5SIAU=; b=25bR4X6md5FiKo53UQcM63ymWyV1JumkYe2ORDu3Nvj0vs+qTlxn1ggvTsgWLZOdaa 4GaEEAWKjkIAZXgxJbI3zw6YDePClC9X58sdqtGY5EE4aAV9Z5HNGAN0hN5kIX2zsp8I MZqPZ2eBLz8X8IZ+VyEXuQIK4eOd2Av1DlBz02Ub3PjVq/eQO5f3NXhDkTGNND3oj35r 3qxCd5cNVB3hoWaEt9TlP6u8vx7NBbI/YviD7KJ7qOVgOyEqYhDbaLE7Xj4J28wlFg56 IMBounOX+meN7U3llVw/WLexgJnQ+uNH+s2f+MWKPuh9q97CmSnN00G7hdkKj9vNe9L/ bfFA== X-Gm-Message-State: ACgBeo3QbeEXEJ8PMtkaF5qLlAX+Uc0b6tJltU2001Wq5uCViRgtmBl/ AKrxVDu8AcEc4c4h6eTgjQbFFtsEuA4dATMenWncShY4IxaaMRepuKKGy9QQh0D/khU11t634ga zeOku4Ee2hyRmYsmSUJ/3Pj1UgmUq X-Received: by 2002:a17:907:b06:b0:73d:c534:1ac3 with SMTP id h6-20020a1709070b0600b0073dc5341ac3mr1007067ejl.194.1661357618755; Wed, 24 Aug 2022 09:13:38 -0700 (PDT) X-Google-Smtp-Source: AA6agR51vE5rD3Cnr43VGXz6apFS+AbCm8Q7NybadVKzLFntNtPDrnwpSizgYigjC19GqW+ewQ6s0Q== X-Received: by 2002:a17:907:b06:b0:73d:c534:1ac3 with SMTP id h6-20020a1709070b0600b0073dc5341ac3mr1007059ejl.194.1661357618587; Wed, 24 Aug 2022 09:13:38 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id j2-20020a170906410200b007308bdef04bsm1359102ejk.103.2022.08.24.09.13.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Aug 2022 09:13:38 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org Subject: [PATCH drm-misc-next v3 2/4] drm/vc4: plane: protect device resources after removal Date: Wed, 24 Aug 2022 18:13:25 +0200 Message-Id: <20220824161327.330627-3-dakr@redhat.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220824161327.330627-1-dakr@redhat.com> References: <20220824161327.330627-1-dakr@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Danilo Krummrich , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" (Hardware) resources which are bound to the driver and device lifecycle must not be accessed after the device and driver are unbound. However, the DRM device isn't freed as long as the last user closed it, hence userspace can still call into the driver. Therefore protect the critical sections which are accessing those resources with drm_dev_enter() and drm_dev_exit(). Fixes: 9872c7a31921 ("drm/vc4: plane: Switch to drmm_universal_plane_alloc()") Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/vc4/vc4_plane.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/gpu/drm/vc4/vc4_plane.c b/drivers/gpu/drm/vc4/vc4_plane.c index eff9c63adfa7..8b92a45a3c89 100644 --- a/drivers/gpu/drm/vc4/vc4_plane.c +++ b/drivers/gpu/drm/vc4/vc4_plane.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -1219,6 +1220,10 @@ u32 vc4_plane_write_dlist(struct drm_plane *plane, u32 __iomem *dlist) { struct vc4_plane_state *vc4_state = to_vc4_plane_state(plane->state); int i; + int idx; + + if (!drm_dev_enter(plane->dev, &idx)) + goto out; vc4_state->hw_dlist = dlist; @@ -1226,6 +1231,9 @@ u32 vc4_plane_write_dlist(struct drm_plane *plane, u32 __iomem *dlist) for (i = 0; i < vc4_state->dlist_count; i++) writel(vc4_state->dlist[i], &dlist[i]); + drm_dev_exit(idx); + +out: return vc4_state->dlist_count; } @@ -1245,6 +1253,10 @@ void vc4_plane_async_set_fb(struct drm_plane *plane, struct drm_framebuffer *fb) struct vc4_plane_state *vc4_state = to_vc4_plane_state(plane->state); struct drm_gem_dma_object *bo = drm_fb_dma_get_gem_obj(fb, 0); uint32_t addr; + int idx; + + if (!drm_dev_enter(plane->dev, &idx)) + return; /* We're skipping the address adjustment for negative origin, * because this is only called on the primary plane. @@ -1263,6 +1275,8 @@ void vc4_plane_async_set_fb(struct drm_plane *plane, struct drm_framebuffer *fb) * also use our updated address. */ vc4_state->dlist[vc4_state->ptr0_offset] = addr; + + drm_dev_exit(idx); } static void vc4_plane_atomic_async_update(struct drm_plane *plane, @@ -1271,6 +1285,10 @@ static void vc4_plane_atomic_async_update(struct drm_plane *plane, struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state, plane); struct vc4_plane_state *vc4_state, *new_vc4_state; + int idx; + + if (!drm_dev_enter(plane->dev, &idx)) + return; swap(plane->state->fb, new_plane_state->fb); plane->state->crtc_x = new_plane_state->crtc_x; @@ -1333,6 +1351,8 @@ static void vc4_plane_atomic_async_update(struct drm_plane *plane, &vc4_state->hw_dlist[vc4_state->pos2_offset]); writel(vc4_state->dlist[vc4_state->ptr0_offset], &vc4_state->hw_dlist[vc4_state->ptr0_offset]); + + drm_dev_exit(idx); } static int vc4_plane_atomic_async_check(struct drm_plane *plane, From patchwork Wed Aug 24 16:13:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12953793 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9B286C00140 for ; Wed, 24 Aug 2022 16:14:15 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8C510BA0C0; Wed, 24 Aug 2022 16:14:00 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id 60C8BBA00D for ; Wed, 24 Aug 2022 16:13:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661357622; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jFR3xFdwN9i2Cd3/9jTqWPHspBtbjbbUfilDsWbGEig=; b=LLUUBllnibnXKdaRbdPKynsArHP+Y/mfl1NImn3bv4ZKFZ8OhsJx5mayLcD2R7KIVAwSWW oU7t8L6pLDARL5EExOVx99QX1kgT7r32ROIm2iIlRN/l31ZrGnc1DBIdOpf9mptvLyu1KE 1llBogJz/Wno2++1cQ7PclFppU5Fh9Q= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-483-oxf9Ti4hPUOXgY_5_WJd4A-1; Wed, 24 Aug 2022 12:13:41 -0400 X-MC-Unique: oxf9Ti4hPUOXgY_5_WJd4A-1 Received: by mail-ej1-f71.google.com with SMTP id hq37-20020a1709073f2500b0073d8e17f434so3057732ejc.2 for ; Wed, 24 Aug 2022 09:13:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=jFR3xFdwN9i2Cd3/9jTqWPHspBtbjbbUfilDsWbGEig=; b=1UEQNWI7DfphgOzYvekCLMR8rgvQ8DynwAp6n/SLWG1ACPp3c8cPABq38fL/8ISZQu LcQWb/83hQ3kJruqj9aAIG0s4zPUQQoE2UF9FPrea33ugCZNag62QFZz3+Wc1x8aoDjK KULsPgGXFoMRZUkoPiZumq8/BkEXx1XCbKksx6yhmwlOwiAdpPbfa+XJ0IF/oWcHa0Za oyj3dy8WUJc1qGJ0/+2iipclQHCbr91LbZ5Fmn10yCFfbaxvlbGzwf1uZfbzK+KdBoJS bEHSqMYvzzhotOv3iBYF6Dcy3LJnA74GUYlAGiAffCBrw+KES1ry/ouP2LhjjdX41hDM oTzg== X-Gm-Message-State: ACgBeo156ioOG85n7C6L4N6KVgJ7MZMzrHlGkgsgDMDxS6QmABdqh4up MKLcjNu+BI1AeRpkgVbvFs6I06OqFDejeU88RItDSAErhPL80tvzYnyX6vZufiUscvjH6RMgyVV +BhXog0O9uAjkPNhzHUUJmeIXr6ee X-Received: by 2002:a17:906:dc90:b0:73d:670d:5975 with SMTP id cs16-20020a170906dc9000b0073d670d5975mr3262118ejc.515.1661357620167; Wed, 24 Aug 2022 09:13:40 -0700 (PDT) X-Google-Smtp-Source: AA6agR4uS8NKqFvOYpGt5/IICUeLEiPTWIJ6o1anfDey5Pn39rH290LhaS+49A2XCUc3biABKcqT4A== X-Received: by 2002:a17:906:dc90:b0:73d:670d:5975 with SMTP id cs16-20020a170906dc9000b0073d670d5975mr3262109ejc.515.1661357620000; Wed, 24 Aug 2022 09:13:40 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id j2-20020a170906410200b007308bdef04bsm1359102ejk.103.2022.08.24.09.13.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Aug 2022 09:13:39 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org Subject: [PATCH drm-misc-next v3 3/4] drm/vc4: crtc: protect device resources after removal Date: Wed, 24 Aug 2022 18:13:26 +0200 Message-Id: <20220824161327.330627-4-dakr@redhat.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220824161327.330627-1-dakr@redhat.com> References: <20220824161327.330627-1-dakr@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Danilo Krummrich , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" (Hardware) resources which are bound to the driver and device lifecycle must not be accessed after the device and driver are unbound. However, the DRM device isn't freed as long as the last user closed it, hence userspace can still call into the driver. Therefore protect the critical sections which are accessing those resources with drm_dev_enter() and drm_dev_exit(). Fixes: 7cc4214c27cf ("drm/vc4: crtc: Switch to drmm_kzalloc") Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/vc4/vc4_crtc.c | 41 +++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/vc4/vc4_crtc.c b/drivers/gpu/drm/vc4/vc4_crtc.c index 2def6e2ad6f0..0108613e79d5 100644 --- a/drivers/gpu/drm/vc4/vc4_crtc.c +++ b/drivers/gpu/drm/vc4/vc4_crtc.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -295,10 +296,17 @@ struct drm_encoder *vc4_get_crtc_encoder(struct drm_crtc *crtc, static void vc4_crtc_pixelvalve_reset(struct drm_crtc *crtc) { struct vc4_crtc *vc4_crtc = to_vc4_crtc(crtc); + struct drm_device *dev = crtc->dev; + int idx; + + if (!drm_dev_enter(dev, &idx)) + return; /* The PV needs to be disabled before it can be flushed */ CRTC_WRITE(PV_CONTROL, CRTC_READ(PV_CONTROL) & ~PV_CONTROL_EN); CRTC_WRITE(PV_CONTROL, CRTC_READ(PV_CONTROL) | PV_CONTROL_FIFO_CLR); + + drm_dev_exit(idx); } static void vc4_crtc_config_pv(struct drm_crtc *crtc, struct drm_encoder *encoder, @@ -321,6 +329,10 @@ static void vc4_crtc_config_pv(struct drm_crtc *crtc, struct drm_encoder *encode u32 format = is_dsi1 ? PV_CONTROL_FORMAT_DSIV_24 : PV_CONTROL_FORMAT_24; u8 ppc = pv_data->pixels_per_clock; bool debug_dump_regs = false; + int idx; + + if (!drm_dev_enter(dev, &idx)) + return; if (debug_dump_regs) { struct drm_printer p = drm_info_printer(&vc4_crtc->pdev->dev); @@ -410,6 +422,8 @@ static void vc4_crtc_config_pv(struct drm_crtc *crtc, struct drm_encoder *encode drm_crtc_index(crtc)); drm_print_regset32(&p, &vc4_crtc->regset); } + + drm_dev_exit(idx); } static void require_hvs_enabled(struct drm_device *dev) @@ -430,7 +444,10 @@ static int vc4_crtc_disable(struct drm_crtc *crtc, struct vc4_crtc *vc4_crtc = to_vc4_crtc(crtc); struct drm_device *dev = crtc->dev; struct vc4_dev *vc4 = to_vc4_dev(dev); - int ret; + int idx, ret; + + if (!drm_dev_enter(dev, &idx)) + return -ENODEV; CRTC_WRITE(PV_V_CONTROL, CRTC_READ(PV_V_CONTROL) & ~PV_VCONTROL_VIDEN); @@ -464,6 +481,8 @@ static int vc4_crtc_disable(struct drm_crtc *crtc, if (vc4_encoder && vc4_encoder->post_crtc_powerdown) vc4_encoder->post_crtc_powerdown(encoder, state); + drm_dev_exit(idx); + return 0; } @@ -588,10 +607,14 @@ static void vc4_crtc_atomic_enable(struct drm_crtc *crtc, struct vc4_crtc *vc4_crtc = to_vc4_crtc(crtc); struct drm_encoder *encoder = vc4_get_crtc_encoder(crtc, new_state); struct vc4_encoder *vc4_encoder = to_vc4_encoder(encoder); + int idx; drm_dbg(dev, "Enabling CRTC %s (%u) connected to Encoder %s (%u)", crtc->name, crtc->base.id, encoder->name, encoder->base.id); + if (!drm_dev_enter(dev, &idx)) + return; + require_hvs_enabled(dev); /* Enable vblank irq handling before crtc is started otherwise @@ -619,6 +642,8 @@ static void vc4_crtc_atomic_enable(struct drm_crtc *crtc, if (vc4_encoder->post_crtc_enable) vc4_encoder->post_crtc_enable(encoder, state); + + drm_dev_exit(idx); } static enum drm_mode_status vc4_crtc_mode_valid(struct drm_crtc *crtc, @@ -711,17 +736,31 @@ static int vc4_crtc_atomic_check(struct drm_crtc *crtc, static int vc4_enable_vblank(struct drm_crtc *crtc) { struct vc4_crtc *vc4_crtc = to_vc4_crtc(crtc); + struct drm_device *dev = crtc->dev; + int idx; + + if (!drm_dev_enter(dev, &idx)) + return -ENODEV; CRTC_WRITE(PV_INTEN, PV_INT_VFP_START); + drm_dev_exit(idx); + return 0; } static void vc4_disable_vblank(struct drm_crtc *crtc) { struct vc4_crtc *vc4_crtc = to_vc4_crtc(crtc); + struct drm_device *dev = crtc->dev; + int idx; + + if (!drm_dev_enter(dev, &idx)) + return; CRTC_WRITE(PV_INTEN, 0); + + drm_dev_exit(idx); } static void vc4_crtc_handle_page_flip(struct vc4_crtc *vc4_crtc) From patchwork Wed Aug 24 16:13:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12953795 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 52269C00140 for ; Wed, 24 Aug 2022 16:15:34 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 54F13BA3A3; Wed, 24 Aug 2022 16:15:26 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id 44725BA04A for ; Wed, 24 Aug 2022 16:13:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661357626; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xeNvcv3iZHDY3QjzCkS4zy97GwENP8IMr7bik18mtU0=; b=eoJA7KfOSBM8kk9kj8eiNFFAJjttaHxXMuyeMpXY3U0AxI5xN2Z4DxD2l/Ke3pPS8J8qk2 cd5AJKjL9nL6nkbB8X6ZfAu1kkj0PFfwI3ORRJxpERVo9XoXAYuXUe+Dy1eb1ATDU6nF31 ZtNZFNw+QkIQYdqRr4KOVUa6ykeu4ms= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-26-Uw9xkqvXNAmRfVNf_IpUug-1; Wed, 24 Aug 2022 12:13:45 -0400 X-MC-Unique: Uw9xkqvXNAmRfVNf_IpUug-1 Received: by mail-ej1-f72.google.com with SMTP id qa35-20020a17090786a300b0073d4026a97dso4254597ejc.9 for ; Wed, 24 Aug 2022 09:13:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=xeNvcv3iZHDY3QjzCkS4zy97GwENP8IMr7bik18mtU0=; b=WHOdpmMB7OUhnWF2V3ZAYIcDeZdFsm3HmyQRrc+kM/PTtH06516h+r9Ebf6rHHGt8F fiVmUf3ZW++OYcOU1tnLomXyjxqTVqhGJVK1arq60IdGESnSZZpV3blb1H9u3AfOIChd cVKfTtde75CsJQ+Zo7CP/FswiqiC5irUCmPlXRKBYVEciHAedduuK2nxWuh1mFPJCphZ bvAwSHgfA85+tdEjaqznEA8+8ayCLwpIKUvLGywbSKMs5zBqux8jxd6qQjE/oaDcY4Wj fWdxDKbkIQuk95SDBrpnJTQgIu/CmNz6SVuucdepvntRLa51a2ama3+6MX1/pzFq3rD/ QtIw== X-Gm-Message-State: ACgBeo32ry5VuOZGdDyWEHsvS3JQMtg6PgwfVNHEBilkbEM1sqA8xSTS gg2U/3GCG82VStn+le333lrqic4VxXYifdmaXfZrE/QKnZYZYMzBJG5aovDBnen2A+tV6Tj+0Ui g63jqGmIYlto7tW2F1cza1BeGJ8Vi X-Received: by 2002:a17:907:75f9:b0:73d:6285:4c94 with SMTP id jz25-20020a17090775f900b0073d62854c94mr3284820ejc.698.1661357624194; Wed, 24 Aug 2022 09:13:44 -0700 (PDT) X-Google-Smtp-Source: AA6agR42pUAoJZIfv+Mz3pexbh+1Dso9JV7rlJIRNC0EIEP7SQm5xsOetB8XyvkV6EeX7//wS1zU/g== X-Received: by 2002:a17:907:75f9:b0:73d:6285:4c94 with SMTP id jz25-20020a17090775f900b0073d62854c94mr3284812ejc.698.1661357624000; Wed, 24 Aug 2022 09:13:44 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id b9-20020a1709063f8900b0072aa009aa68sm1350511ejj.36.2022.08.24.09.13.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Aug 2022 09:13:43 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org Subject: [PATCH drm-misc-next v3 4/4] drm/vc4: hvs: protect drm_print_regset32() Date: Wed, 24 Aug 2022 18:13:27 +0200 Message-Id: <20220824161327.330627-5-dakr@redhat.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220824161327.330627-1-dakr@redhat.com> References: <20220824161327.330627-1-dakr@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Danilo Krummrich , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" In vc4_hvs_dump_state() potentially freed resources are protected from being accessed with drm_dev_enter()/drm_dev_exit(). Also include drm_print_regset32() in the protected section, since drm_print_regset32() does access memory that is typically mapped via devm_* calls. Fixes: 969cfae1f01d ("drm/vc4: hvs: Protect device resources after removal") Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/vc4/vc4_hvs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/vc4/vc4_hvs.c b/drivers/gpu/drm/vc4/vc4_hvs.c index 9e823e0de197..4ac9f5a2d5f9 100644 --- a/drivers/gpu/drm/vc4/vc4_hvs.c +++ b/drivers/gpu/drm/vc4/vc4_hvs.c @@ -71,11 +71,11 @@ void vc4_hvs_dump_state(struct vc4_hvs *hvs) struct drm_printer p = drm_info_printer(&hvs->pdev->dev); int idx, i; - drm_print_regset32(&p, &hvs->regset); - if (!drm_dev_enter(drm, &idx)) return; + drm_print_regset32(&p, &hvs->regset); + DRM_INFO("HVS ctx:\n"); for (i = 0; i < 64; i += 4) { DRM_INFO("0x%08x (%s): 0x%08x 0x%08x 0x%08x 0x%08x\n",