From patchwork Tue Jul 13 13:59:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 12374037 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFD3EC11F69 for ; Tue, 13 Jul 2021 14:00:00 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 8792460C40 for ; Tue, 13 Jul 2021 14:00:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8792460C40 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 738C16E0B6; Tue, 13 Jul 2021 13:59:56 +0000 (UTC) Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by gabe.freedesktop.org (Postfix) with ESMTPS id 051896E0B6 for ; Tue, 13 Jul 2021 13:59:55 +0000 (UTC) Received: by mail-wr1-x434.google.com with SMTP id g16so20721841wrw.5 for ; Tue, 13 Jul 2021 06:59:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=9YydAG2DcMEmgxcLivuTtxWGeOd7fbFGRECd/sa24wQ=; b=F0ZCsLuvDZbH1NpL9Gr8BR4m7vPWuJoj2pxLHSMHE0jfMa7Z0qaez9/Mpy1mjvXBl9 7Qz4+MaMVubEkwDD/Xn2dkGltVI/9wAMgZi0RASsIxWaRziwmfrOF9VuMTI/xtk1L0oK FE1lfIvEgStA04R+4uXa/RaoiNqOSNFUNBJ8Q= 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:mime-version :content-transfer-encoding; bh=9YydAG2DcMEmgxcLivuTtxWGeOd7fbFGRECd/sa24wQ=; b=LDoa/rH40y1coygSOxu14ABDuiXwVtVPG/i4PTZBWHnP2+ekaem/SunT/+jBMfdlSN a7+L1cSK0Elsn6gbzSvdnum4wN6fzVFQYne+1vFyfxN+Ip6GZmo+FCx+J62t92aEs/kg k5onvjDJYO2TkNFWLm0gcGESmc7HGcGKw8bPwOCUbwTOwQ1nGBovqH8Yu7ytJGkW4vUm lDObkOyC//aHeW/kQcEfSVokUTi9Cjz7vSdHCaJ7gZo3JTn5NikafafwKaAR5upKXA2Z b/qwX7QchDF959u9c9lo/iofGjd/XDOp5kkzatytZV1Wq7HwhqeYPpw3DYAnOQGhkN0u xecA== X-Gm-Message-State: AOAM530cvFBUHETiYbKNpK/zjTVKfb3/hv6H8v8mU3arZBC40SyQG3lJ pk7um6Mdv7hr6dtiMH1cM8WNUA== X-Google-Smtp-Source: ABdhPJzwXAzU2cpdYTqZ3JYfNKp8ntaA14B4FhpXI+wfK3KsiogYVTJfuXOFUIsZYWMn7szF8KW7jA== X-Received: by 2002:a5d:4e4e:: with SMTP id r14mr6084401wrt.251.1626184793688; Tue, 13 Jul 2021 06:59:53 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id u18sm15260452wmj.15.2021.07.13.06.59.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jul 2021 06:59:52 -0700 (PDT) From: Daniel Vetter To: DRI Development Date: Tue, 13 Jul 2021 15:59:22 +0200 Message-Id: <20210713135922.1384264-1-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH] drm/fb-helper: Try to protect cleanup against delayed setup X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: David Airlie , Daniel Vetter , Intel Graphics Development , Maxime Ripard , Chris Wilson , Thomas Zimmermann , Daniel Vetter Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Some vague evidences suggests this can go wrong. Try to prevent it by holding the right mutex and clearing ->deferred_setup to make sure we later on don't accidentally try to re-register the fbdev when the driver thought it had it all cleaned up already. v2: I realized that this is fundamentally butchered, and CI complained about lockdep splats. So limit the critical section again and just add a few notes what the proper fix is. References: https://intel-gfx-ci.01.org/tree/linux-next/next-20201215/fi-byt-j1900/igt@i915_pm_rpm@module-reload.html Signed-off-by: Daniel Vetter Cc: Ville Syrjälä Cc: Chris Wilson Cc: Maarten Lankhorst Cc: Maxime Ripard Cc: Thomas Zimmermann Cc: David Airlie Cc: Daniel Vetter Acked-by: Sam Ravnborg Acked-by: Thomas Zimmermann Reviewed-by: Andrzej Hajda --- drivers/gpu/drm/drm_fb_helper.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c index 9d82fda274eb..8f11e5abb222 100644 --- a/drivers/gpu/drm/drm_fb_helper.c +++ b/drivers/gpu/drm/drm_fb_helper.c @@ -598,6 +598,9 @@ EXPORT_SYMBOL(drm_fb_helper_alloc_fbi); * A wrapper around unregister_framebuffer, to release the fb_info * framebuffer device. This must be called before releasing all resources for * @fb_helper by calling drm_fb_helper_fini(). + * + * Note that this is fundamentally racy on hotunload because it doen't handle + * open fbdev file descriptors at all. Use drm_fbdev_generic_setup() instead. */ void drm_fb_helper_unregister_fbi(struct drm_fb_helper *fb_helper) { @@ -611,6 +614,9 @@ EXPORT_SYMBOL(drm_fb_helper_unregister_fbi); * @fb_helper: driver-allocated fbdev helper, can be NULL * * This cleans up all remaining resources associated with @fb_helper. + * + * Note that this is fundamentally racy on hotunload because it doen't handle + * open fbdev file descriptors at all. Use drm_fbdev_generic_setup() instead. */ void drm_fb_helper_fini(struct drm_fb_helper *fb_helper) { @@ -2382,6 +2388,10 @@ static void drm_fbdev_client_unregister(struct drm_client_dev *client) { struct drm_fb_helper *fb_helper = drm_fb_helper_from_client(client); + mutex_lock(&fb_helper->lock); + fb_helper->deferred_setup = false; + mutex_unlock(&fb_helper->lock); + if (fb_helper->fbdev) /* drm_fbdev_fb_destroy() takes care of cleanup */ drm_fb_helper_unregister_fbi(fb_helper);