Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp7169894rwn; Tue, 13 Sep 2022 15:17:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6w+9LRxuMjXyebGzyJLbM8+hVexxb7N2RoqdJ2Vs9RAQGJwV3IghAzIx9S8sMW2weYLvDF X-Received: by 2002:a17:90a:9f96:b0:1fa:b4fb:6297 with SMTP id o22-20020a17090a9f9600b001fab4fb6297mr1421934pjp.80.1663107443817; Tue, 13 Sep 2022 15:17:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663107443; cv=none; d=google.com; s=arc-20160816; b=yuO3Czqbxfuwz8zy4VMG9mJIChC6deF+Y5k0K/xsNDmY3bP5H2jDu48yl5e/fUrm1b 9UxZqk5S4m2VpFz6MVCu/AynTPcbI29RFCV2SyYvHlq5mI2BsNsZpJMFWJLakbXP3fXk LxXvdBp9o7Gt4+a/sBoLxybnLCehUld2SPYMnyngs0fqMn/b1cXM74/hJRRR8XrDCsA4 lghvHUQAwNgWE+gHjyxxzak2yEbkVJpSyZm0KwPGCEP1KYby+WWyWuGyuALZVSJj+U9m 7J3yq20zWGULF4TSTQ6o7EEyeXtNZ1DGdCpFF8ZjzmGxrzYhNO1PiI3pYvliSCGmENA+ IlnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=F/Lhqp1JWUkXQ2yb049nFnR3BgXC5vF+mPmJxxil2YI=; b=UCXCnwNAFBxuECN4IZ/gJrgGdA+YXOMjoL1k/ZdWaz3uAjkXLvc+rAB03zCcJIhB8H dntSyCbxExtHeoEGGW6Q0Bh5QqRxQ9hSfMWhQr5kSV50nDyh8p/Vptld3H/SjGZxjQbE S+Eam/bmfWAM4kd92OzVE4iDuG0Tt+XJbMI+zNIuy9n9QqZOFY2cbMo4nPYRMUVtxLBf v0H2IsYjgsSjllKjtgLOnUTop+HpdMd4XVFDX3V4SUYj5czty1iP8qQX19b3gF7B7Nlp R1OM/Gs/AtXXX6r4YyRq6pYqKIdVAWe/lzQHcUKOtYtmkvgpyd1wXW5wDTneRFaMFFhQ gaKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TNPUgafa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nk8-20020a17090b194800b001fdcb564d73si12222085pjb.79.2022.09.13.15.17.11; Tue, 13 Sep 2022 15:17:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TNPUgafa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229758AbiIMWPm (ORCPT + 99 others); Tue, 13 Sep 2022 18:15:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229698AbiIMWPW (ORCPT ); Tue, 13 Sep 2022 18:15:22 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09A6A1E3E6 for ; Tue, 13 Sep 2022 15:15:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663107319; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=F/Lhqp1JWUkXQ2yb049nFnR3BgXC5vF+mPmJxxil2YI=; b=TNPUgafaF8CV8vhXb2URh1PnUs5l2zqjTsHtE4tnhQ9uRIKN+qISzbzhsNhsHnih/3jzOc xaUgEhm5S8QlyGfTfX3sOAbMkKDWPYjp3lgFmzEiZGCMgKvfekb3RNiHK5e4GbCNru39kC phtNjFcjEthV9wlSubsjMSQDi3kxtoU= 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-256-4fTtX2yWPearACxRCwIElw-1; Tue, 13 Sep 2022 18:15:18 -0400 X-MC-Unique: 4fTtX2yWPearACxRCwIElw-1 Received: by mail-ej1-f72.google.com with SMTP id hr12-20020a1709073f8c00b0077e8371f847so3019150ejc.20 for ; Tue, 13 Sep 2022 15:15:18 -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 :subject:date; bh=F/Lhqp1JWUkXQ2yb049nFnR3BgXC5vF+mPmJxxil2YI=; b=HObwYgOQOaiVibWgiUztmHk62N60VYObBAo2sr9wygv9VPTOwggvIRyq+ajS03uDqm L/F6sfpnafSk86gkoUIMgspRcZq/EIDy2grSb9yZHTY4F2BOV/GDPyyd9w87TZBrsqmM XpSxmsyi2Kqij2dIgWU9i0HySEawdauyQhfxRpH9ajo+6tTcQOgJdCpPIyR84f+36nfs T6hsz8AERACpWsHzpimWWoxslo0TLdLTJhctiR+7HQ9uIq3lXsIbdyGX+ZBmZpfMHvhw c0COqcY1f2ymY1cK9qMRuzwQfgJXhW6c+5ZhvwJa6hIJ2mxgUyHHH9n2sV9C2W03YsEV M28Q== X-Gm-Message-State: ACgBeo3xLpsgIseKB5+bgM2CmJxoRh/xqqkkvjMe9aruaKuhd/Vb2vUr H4pVrNrZyF/AoaHBDDEVZEZWA2yAUWgU2A3M0H0WY8hgkJFcX5hYiPgnsphWX1f3xVUmBT6ITu5 L/WyXUh1muL7Vm5wIL8/LUPcg X-Received: by 2002:a05:6402:3550:b0:451:473a:5ca3 with SMTP id f16-20020a056402355000b00451473a5ca3mr15479848edd.48.1663107317637; Tue, 13 Sep 2022 15:15:17 -0700 (PDT) X-Received: by 2002:a05:6402:3550:b0:451:473a:5ca3 with SMTP id f16-20020a056402355000b00451473a5ca3mr15479839edd.48.1663107317503; Tue, 13 Sep 2022 15:15:17 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id z13-20020a1709060acd00b0077d371a8f29sm4121008ejf.204.2022.09.13.15.15.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Sep 2022 15:15:17 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org, liviu.dudau@arm.com, brian.starkey@arm.com Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Danilo Krummrich Subject: [PATCH drm-misc-next v2 5/6] drm/arm/hdlcd: crtc: protect device resources after removal Date: Wed, 14 Sep 2022 00:14:55 +0200 Message-Id: <20220913221456.147937-6-dakr@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913221456.147937-1-dakr@redhat.com> References: <20220913221456.147937-1-dakr@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org (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 didn't close 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(). Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/arm/hdlcd_crtc.c | 52 ++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/arm/hdlcd_crtc.c b/drivers/gpu/drm/arm/hdlcd_crtc.c index 1de0f7b23766..694adddc9f7c 100644 --- a/drivers/gpu/drm/arm/hdlcd_crtc.c +++ b/drivers/gpu/drm/arm/hdlcd_crtc.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -39,28 +40,49 @@ static void hdlcd_crtc_cleanup(struct drm_crtc *crtc) { struct hdlcd_drm_private *hdlcd = crtc_to_hdlcd_priv(crtc); + int idx; + + drm_crtc_cleanup(crtc); + + if (!drm_dev_enter(crtc->dev, &idx)) + return; /* stop the controller on cleanup */ hdlcd_write(hdlcd, HDLCD_REG_COMMAND, 0); - drm_crtc_cleanup(crtc); + + drm_dev_exit(idx); } static int hdlcd_crtc_enable_vblank(struct drm_crtc *crtc) { struct hdlcd_drm_private *hdlcd = crtc_to_hdlcd_priv(crtc); - unsigned int mask = hdlcd_read(hdlcd, HDLCD_REG_INT_MASK); + unsigned int mask; + int idx; + if (!drm_dev_enter(crtc->dev, &idx)) + return -ENODEV; + + mask = hdlcd_read(hdlcd, HDLCD_REG_INT_MASK); hdlcd_write(hdlcd, HDLCD_REG_INT_MASK, mask | HDLCD_INTERRUPT_VSYNC); + drm_dev_exit(idx); + return 0; } static void hdlcd_crtc_disable_vblank(struct drm_crtc *crtc) { struct hdlcd_drm_private *hdlcd = crtc_to_hdlcd_priv(crtc); - unsigned int mask = hdlcd_read(hdlcd, HDLCD_REG_INT_MASK); + unsigned int mask; + int idx; + + if (!drm_dev_enter(crtc->dev, &idx)) + return; + mask = hdlcd_read(hdlcd, HDLCD_REG_INT_MASK); hdlcd_write(hdlcd, HDLCD_REG_INT_MASK, mask & ~HDLCD_INTERRUPT_VSYNC); + + drm_dev_exit(idx); } static const struct drm_crtc_funcs hdlcd_crtc_funcs = { @@ -171,21 +193,33 @@ static void hdlcd_crtc_atomic_enable(struct drm_crtc *crtc, struct drm_atomic_state *state) { struct hdlcd_drm_private *hdlcd = crtc_to_hdlcd_priv(crtc); + int idx; + + if (!drm_dev_enter(crtc->dev, &idx)) + return; clk_prepare_enable(hdlcd->clk); hdlcd_crtc_mode_set_nofb(crtc); hdlcd_write(hdlcd, HDLCD_REG_COMMAND, 1); drm_crtc_vblank_on(crtc); + + drm_dev_exit(idx); } static void hdlcd_crtc_atomic_disable(struct drm_crtc *crtc, struct drm_atomic_state *state) { struct hdlcd_drm_private *hdlcd = crtc_to_hdlcd_priv(crtc); + int idx; + + if (!drm_dev_enter(crtc->dev, &idx)) + return; drm_crtc_vblank_off(crtc); hdlcd_write(hdlcd, HDLCD_REG_COMMAND, 0); clk_disable_unprepare(hdlcd->clk); + + drm_dev_exit(idx); } static enum drm_mode_status hdlcd_crtc_mode_valid(struct drm_crtc *crtc, @@ -193,6 +227,10 @@ static enum drm_mode_status hdlcd_crtc_mode_valid(struct drm_crtc *crtc, { struct hdlcd_drm_private *hdlcd = crtc_to_hdlcd_priv(crtc); long rate, clk_rate = mode->clock * 1000; + int idx; + + if (!drm_dev_enter(crtc->dev, &idx)) + return MODE_NOCLOCK; rate = clk_round_rate(hdlcd->clk, clk_rate); /* 0.1% seems a close enough tolerance for the TDA19988 on Juno */ @@ -201,6 +239,8 @@ static enum drm_mode_status hdlcd_crtc_mode_valid(struct drm_crtc *crtc, return MODE_NOCLOCK; } + drm_dev_exit(idx); + return MODE_OK; } @@ -268,6 +308,10 @@ static void hdlcd_plane_atomic_update(struct drm_plane *plane, struct hdlcd_drm_private *hdlcd; u32 dest_h; dma_addr_t scanout_start; + int idx; + + if (!drm_dev_enter(plane->dev, &idx)) + return; if (!fb) return; @@ -280,6 +324,8 @@ static void hdlcd_plane_atomic_update(struct drm_plane *plane, hdlcd_write(hdlcd, HDLCD_REG_FB_LINE_PITCH, fb->pitches[0]); hdlcd_write(hdlcd, HDLCD_REG_FB_LINE_COUNT, dest_h - 1); hdlcd_write(hdlcd, HDLCD_REG_FB_BASE, scanout_start); + + drm_dev_exit(idx); } static const struct drm_plane_helper_funcs hdlcd_plane_helper_funcs = { -- 2.37.3