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: 12374039 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 0EAC8C07E95 for ; Tue, 13 Jul 2021 13:59:58 +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 CA42C608FE for ; Tue, 13 Jul 2021 13:59:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CA42C608FE Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 05D136E0AF; Tue, 13 Jul 2021 13:59:56 +0000 (UTC) Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by gabe.freedesktop.org (Postfix) with ESMTPS id EEDC36E0AF for ; Tue, 13 Jul 2021 13:59:54 +0000 (UTC) Received: by mail-wr1-x433.google.com with SMTP id i94so30601825wri.4 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=G9sZBc8pxJOXdRyUdqJ0C2ZABSyXVLKrb2Nq71cf/mhXI0u2KOSzEu82VnBE59T1W6 zCI9EMmZT+i6flMONbsgm37pZFBOkbux5V62qL18HBz0ktsvwXwwxQsOyNisyE39afve KQgOdiVkBO3mLTrxTBI8zNlDBxMiBxHvkRwBwmtwgQ7OU/bLCVtR+0chTgYpq4QYfdj/ zEbRdBCc6mJJpEr8aVj1KrxK6msWcJG8mbTvcVzQ2v7AIoGQkKteO+peWeKH7tpwvwZ5 l5C+aOwryEBvkSDQVNs1OAW94GcIoyrtOkr5gk5laf0olBuNGfCakza2StoBzr1wu+D3 gntA== X-Gm-Message-State: AOAM53105DJuO8pM2J9pyrXNVdDtHqtmvg0YnA9yXF6qeqN1v7uoLsFR d1u6YQUZ9K9eTgP/vnROf5KYgy+U+CcHXg== 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 Subject: [PATCH] drm/fb-helper: Try to protect cleanup against delayed setup 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 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: David Airlie , Daniel Vetter , Intel Graphics Development , Chris Wilson , Thomas Zimmermann , Daniel Vetter Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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);