From patchwork Fri Apr 29 08:42:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Martinez Canillas X-Patchwork-Id: 567610 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CDF34C433FE for ; Fri, 29 Apr 2022 08:43:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355924AbiD2Iqx (ORCPT ); Fri, 29 Apr 2022 04:46:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355940AbiD2Iqi (ORCPT ); Fri, 29 Apr 2022 04:46:38 -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 ESMTP id 69494C4010 for ; Fri, 29 Apr 2022 01:43:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651221797; 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=Brj5kPf1vp2+xvAmZf1o0QRVBdqqcyn2KbRWKGy9p24=; b=a+hDDMr6mTkutZ/P/YSEBH7FMSY1GHc3Z0BttLiq1aSQ+Xbk6L0xDrq4RB+2yui5tPInHF fWW4NZvrZ36BNP0ObM/kwodxEXnOjIJEZDSXJ3ucMfkiqkEyDC0Cm//bwFxObKvhn805DB nRF7GJbjxie9pAvE76y/A5IjOsZcUvA= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-634-uqj8Epz7NeO_9OtBomscYg-1; Fri, 29 Apr 2022 04:43:16 -0400 X-MC-Unique: uqj8Epz7NeO_9OtBomscYg-1 Received: by mail-wr1-f72.google.com with SMTP id e21-20020adfa455000000b0020ae075cf35so2828481wra.11 for ; Fri, 29 Apr 2022 01:43:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Brj5kPf1vp2+xvAmZf1o0QRVBdqqcyn2KbRWKGy9p24=; b=pkFVlCA4Oi71V0BqO7Xr1Vw6+3zN/mM0c1HmHcAR0ZYqcoUs0YqTSMG669THXN0Ksf 8Zo1WlFH3rAg+ccp8SbfbC/XTzSu3OcQ2rGwLOToAW/A2UBPK9LACu8PgaOGg4cwjy+A ijyrUAQbfIGG2LtdUWHx0OAXYHRUbWfGMBZtvsPO0TRy6EjWs4V8XrljdWPjlZ80Gf9m hupOYd+CMxkltlO3AEI8Ki90jL3aCqB/qjy6xSN8PLQB2QPMnBdan63JyLsmEaIDsA4Y lEZcoY1oWbF17W0h2k0RvEOZYkWUaoC0WoVWr38OJSZJNmnbChFg7HewAz2YuH2kfjTF gg8w== X-Gm-Message-State: AOAM533LBhABcYvnt4BdOngbFmq+VP3xjNAofbKp1OgtV/at3WSayN1V vf1MGCZyu3xZQGmVa45j4eKcoNYJ6XSBiRXfihYHtGK3YqqVeTi+VDl6yUING9Kyp+oyF6dOMK2 /i0s3ehYLzu0JcZQAnvqhn8c= X-Received: by 2002:a05:600c:1d9b:b0:393:ffc8:a09b with SMTP id p27-20020a05600c1d9b00b00393ffc8a09bmr2179619wms.40.1651221795059; Fri, 29 Apr 2022 01:43:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrVFdFCXeRphGLRkfrU/+tc/H0r7qF9nFcGL4D+eRkGaWuTGNr1P6BVgMPY5uynZbJ2i3UmQ== X-Received: by 2002:a05:600c:1d9b:b0:393:ffc8:a09b with SMTP id p27-20020a05600c1d9b00b00393ffc8a09bmr2179599wms.40.1651221794848; Fri, 29 Apr 2022 01:43:14 -0700 (PDT) Received: from minerva.home ([92.176.231.205]) by smtp.gmail.com with ESMTPSA id f7-20020a05600c4e8700b00393f1393abfsm7199256wmq.41.2022.04.29.01.43.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Apr 2022 01:43:14 -0700 (PDT) From: Javier Martinez Canillas To: linux-kernel@vger.kernel.org Cc: dri-devel@lists.freedesktop.org, Daniel Vetter , Greg Kroah-Hartman , Thomas Zimmermann , Javier Martinez Canillas , Alex Deucher , Changcheng Deng , Daniel Vetter , Helge Deller , Sam Ravnborg , Zhen Lei , linux-fbdev@vger.kernel.org Subject: [RFC PATCH v4 06/11] fbdev: Restart conflicting fb removal loop when unregistering devices Date: Fri, 29 Apr 2022 10:42:48 +0200 Message-Id: <20220429084253.1085911-7-javierm@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220429084253.1085911-1-javierm@redhat.com> References: <20220429084253.1085911-1-javierm@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org Drivers that want to remove registered conflicting framebuffers prior to register their own framebuffer, calls remove_conflicting_framebuffers(). This function takes the registration_lock mutex, to prevent a races when drivers register framebuffer devices. But if a conflicting framebuffer device is found, the underlaying platform device is unregistered and this will lead to the platform driver .remove callback to be called, which in turn will call to the unregister_framebuffer() that takes the same lock. To prevent this, a struct fb_info.forced_out field was used as indication to unregister_framebuffer() whether the mutex has to be grabbed or not. A cleaner solution is to drop the lock before platform_device_unregister() so unregister_framebuffer() can take it when called from the fbdev driver, and just grab the lock again after the device has been registered and do a removal loop restart. Since the framebuffer devices will already be removed, the loop would just finish when no more conflicting framebuffers are found. Suggested-by: Daniel Vetter Signed-off-by: Javier Martinez Canillas Reviewed-by: Daniel Vetter --- (no changes since v1) drivers/video/fbdev/core/fbmem.c | 22 +++++++++++++++------- include/linux/fb.h | 1 - 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c index 84427470367b..0bb459258df3 100644 --- a/drivers/video/fbdev/core/fbmem.c +++ b/drivers/video/fbdev/core/fbmem.c @@ -1553,6 +1553,7 @@ static void do_remove_conflicting_framebuffers(struct apertures_struct *a, { int i; +restart_removal: /* check all firmware fbs and kick off if the base addr overlaps */ for_each_registered_fb(i) { struct apertures_struct *gen_aper; @@ -1585,12 +1586,23 @@ static void do_remove_conflicting_framebuffers(struct apertures_struct *a, pr_warn("fb%d: no device set\n", i); do_unregister_framebuffer(registered_fb[i]); } else if (dev_is_platform(device)) { - registered_fb[i]->forced_out = true; + /* + * Drop the lock because if the device is unregistered, its + * driver will call to unregister_framebuffer(), that takes + * this lock. + */ + mutex_unlock(®istration_lock); platform_device_unregister(to_platform_device(device)); + mutex_lock(®istration_lock); } else { pr_warn("fb%d: cannot remove device\n", i); do_unregister_framebuffer(registered_fb[i]); } + /* + * Restart the removal loop now that the device has been + * unregistered and its associated framebuffer gone. + */ + goto restart_removal; } } } @@ -1897,13 +1909,9 @@ EXPORT_SYMBOL(register_framebuffer); void unregister_framebuffer(struct fb_info *fb_info) { - bool forced_out = fb_info->forced_out; - - if (!forced_out) - mutex_lock(®istration_lock); + mutex_lock(®istration_lock); do_unregister_framebuffer(fb_info); - if (!forced_out) - mutex_unlock(®istration_lock); + mutex_unlock(®istration_lock); } EXPORT_SYMBOL(unregister_framebuffer); diff --git a/include/linux/fb.h b/include/linux/fb.h index f95da1af9ff6..b781bc721113 100644 --- a/include/linux/fb.h +++ b/include/linux/fb.h @@ -502,7 +502,6 @@ struct fb_info { } *apertures; bool skip_vt_switch; /* no VT switch on suspend/resume required */ - bool forced_out; /* set when being removed by another driver */ }; static inline struct apertures_struct *alloc_apertures(unsigned int max_num) { From patchwork Fri Apr 29 08:42:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Martinez Canillas X-Patchwork-Id: 567611 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA3E6C43217 for ; Fri, 29 Apr 2022 08:43:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355987AbiD2Iqs (ORCPT ); Fri, 29 Apr 2022 04:46:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355972AbiD2Iqp (ORCPT ); Fri, 29 Apr 2022 04:46:45 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2E5C1C4014 for ; Fri, 29 Apr 2022 01:43:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651221806; 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=32BFmTqPr/eVAc9kmYw/jW8gg2xRyq+gsg/BzILupkI=; b=VQKSIlpcLbE8WcjyX/HDTLXu1pjVtxrAaRPoNThzt/PxofjEalsYnICTfld474Gkduu1D5 6vMif2LECUSumcksE/RFqL1QyN6wxVIIeKag0lJhG11wZyhCopGGkqvHMg/fsFaxHNmkQG q6+P+NemMTDvuAQag92adzSpdjLZjjY= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-411-UBlmFApCNNen6O3OUoOMrQ-1; Fri, 29 Apr 2022 04:43:17 -0400 X-MC-Unique: UBlmFApCNNen6O3OUoOMrQ-1 Received: by mail-wm1-f72.google.com with SMTP id k5-20020a05600c0b4500b003941ca130f9so551038wmr.0 for ; Fri, 29 Apr 2022 01:43:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=32BFmTqPr/eVAc9kmYw/jW8gg2xRyq+gsg/BzILupkI=; b=pmrTk11ynRkM5PoDomRF2Zu2GJbm6QLxghJ8chpJmDDTqXhWOaqu+GRRAK7MfPobpM 1S9dYTC31Lh86fLOj5VjhirFBtpzodYBR83/nEsVA2Eqr/FoEyLZ4xC41yVQd83QH1BQ EBlvG+IdVSC3C8QC1kezI/hxr0j8w1HoCvB2OMNTXiPKbPLmXvFOlLfE6A5Dlu9wNrZY VV8C4T71RTGty8UsZg3DCmLRkDBzWOdvp2kLKaSLudu156Tnp0of4dmq9c6/UcGiB4Hn 2RzPxEf2tOu8GJEbVKwR2RigRsCWYhXLOxY/ivZ0kYtKOk2R9CJwBVbEbKRWlOLo64nj u/Ig== X-Gm-Message-State: AOAM5300jP8D/57qBE166U1Vi98zkFXmvpnbNG3ALcSiap7O3aSkefPN B2Di707V8kEFKl9OESaOzzml8XvtUo8GAGWvryj51VScWTmlkhhukrPIqLZ/TTI8QoMrpiGw9rh Blq39bfrHNN1zFGUWH1vb4sw= X-Received: by 2002:a05:600c:29c4:b0:393:fdfa:9baf with SMTP id s4-20020a05600c29c400b00393fdfa9bafmr2106703wmd.26.1651221796246; Fri, 29 Apr 2022 01:43:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpb9GJOon/VWE7cLIvn3hOO2k4R3a9ThVl9BjzphxKGmE7ttlSfqH3kxxBUwJ+8zmSamy6eA== X-Received: by 2002:a05:600c:29c4:b0:393:fdfa:9baf with SMTP id s4-20020a05600c29c400b00393fdfa9bafmr2106674wmd.26.1651221795966; Fri, 29 Apr 2022 01:43:15 -0700 (PDT) Received: from minerva.home ([92.176.231.205]) by smtp.gmail.com with ESMTPSA id f7-20020a05600c4e8700b00393f1393abfsm7199256wmq.41.2022.04.29.01.43.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Apr 2022 01:43:15 -0700 (PDT) From: Javier Martinez Canillas To: linux-kernel@vger.kernel.org Cc: dri-devel@lists.freedesktop.org, Daniel Vetter , Greg Kroah-Hartman , Thomas Zimmermann , Javier Martinez Canillas , Alex Deucher , Changcheng Deng , Daniel Vetter , Helge Deller , Sam Ravnborg , Zhen Lei , linux-fbdev@vger.kernel.org Subject: [RFC PATCH v4 07/11] fbdev: Make sysfb to unregister its own registered devices Date: Fri, 29 Apr 2022 10:42:49 +0200 Message-Id: <20220429084253.1085911-8-javierm@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220429084253.1085911-1-javierm@redhat.com> References: <20220429084253.1085911-1-javierm@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org The platform devices registered in sysfb match with a firmware-based fbdev or DRM driver, that are used to have early graphics using framebuffers set up by the system firmware. Real DRM drivers later are probed and remove all conflicting framebuffers, leading to these platform devices for generic drivers to be unregistered. But the current solution has the problem that sysfb doesn't know when the device that registered is unregistered. This means that is not able to do any cleanup if needed since the device pointer may not be valid anymore. Not all platforms use sysfb to register the simple framebuffer devices, so an unregistration has to be forced by fbmem if sysfb_try_unregister() does not succeed at unregister the device. Suggested-by: Daniel Vetter Signed-off-by: Javier Martinez Canillas Reviewed-by: Daniel Vetter --- Changes in v4: - Drop call to sysfb_disable() in fbmem since is done in other places now. Changes in v2: - Explain in the commit message that fbmem has to unregister the device as fallback if a driver registered the device itself (Daniel Vetter). - Also explain that fallback in a comment in the code (Daniel Vetter). - Don't encode in fbmem the assumption that sysfb will always register platform devices (Daniel Vetter). - Add a FIXME comment about drivers registering devices (Daniel Vetter). drivers/video/fbdev/core/fbmem.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c index 0bb459258df3..d6ae33990f40 100644 --- a/drivers/video/fbdev/core/fbmem.c +++ b/drivers/video/fbdev/core/fbmem.c @@ -1585,18 +1585,35 @@ static void do_remove_conflicting_framebuffers(struct apertures_struct *a, if (!device) { pr_warn("fb%d: no device set\n", i); do_unregister_framebuffer(registered_fb[i]); - } else if (dev_is_platform(device)) { + } else { /* * Drop the lock because if the device is unregistered, its * driver will call to unregister_framebuffer(), that takes * this lock. */ mutex_unlock(®istration_lock); - platform_device_unregister(to_platform_device(device)); + /* + * First attempt the device to be unregistered by sysfb. + */ + if (!sysfb_try_unregister(device)) { + if (dev_is_platform(device)) { + /* + * FIXME: sysfb didn't register this device, the platform + * device was registered in other platform code. + */ + platform_device_unregister(to_platform_device(device)); + } else { + /* + * If is not a platform device, at least print a warning. A + * fix would add to make the code that registered the device + * to also unregister it. + */ + pr_warn("fb%d: cannot remove device\n", i); + /* call unregister_framebuffer() since the lock was dropped */ + unregister_framebuffer(registered_fb[i]); + } + } mutex_lock(®istration_lock); - } else { - pr_warn("fb%d: cannot remove device\n", i); - do_unregister_framebuffer(registered_fb[i]); } /* * Restart the removal loop now that the device has been From patchwork Fri Apr 29 08:42:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Martinez Canillas X-Patchwork-Id: 567612 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73A63C433FE for ; Fri, 29 Apr 2022 08:43:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356001AbiD2Iqq (ORCPT ); Fri, 29 Apr 2022 04:46:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355974AbiD2Iqn (ORCPT ); Fri, 29 Apr 2022 04:46:43 -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 ESMTP id D5846C3EA5 for ; Fri, 29 Apr 2022 01:43:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651221800; 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=u/nkZHXCBB5ZrJnB24ro/1pCmNvdbhB1vwTZ80wJLns=; b=eETKrAnUtaKf3YNwNIkU0gjWjnir1lCPhqv2nHuZC4i11qP3ZZWMZkuocy8mkQtQ7BcT5l czLU8lU43hE/CNCpxq1hZ9qeupK0I3eHT71uHbTmVV6VdX18ZPT4+Zwsg4GLvckdJ5Cz2s 49ceEQFfVrk7RjFzixtklAr+mwjVQq0= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-564-kR9SQXwEOcK_RoSmpJeshA-1; Fri, 29 Apr 2022 04:43:19 -0400 X-MC-Unique: kR9SQXwEOcK_RoSmpJeshA-1 Received: by mail-wm1-f72.google.com with SMTP id bh11-20020a05600c3d0b00b003928fe7ba07so2222539wmb.6 for ; Fri, 29 Apr 2022 01:43:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=u/nkZHXCBB5ZrJnB24ro/1pCmNvdbhB1vwTZ80wJLns=; b=Wc6zPS+C0Q9T4yLLPoin8HOpVvBcFzOLiqIfkCIsNrPibzVM22elmjMHlHUVvy6rNw hM/CyX146Z+yjKljihtx5vJQ/5ppEbyEy9MsQpKuMU42j3T514acsFbvrya7lc382fFB +zM9RnWwoTRqQMm8lFZ7RXMHbFOlr+qNvtPpiPVI7Q8Oh/vyqLMc2593L8dJaTDBs8mq rzGQINKtZGrzwaFkOU8j3huDkqeLAN4rGtqT7fWBVS3WCFzZu/N79wp5xI7Gax2hPccj d9Yr7or5Pf+glMOxBehSp1N6L2B9IC9ItsmXEXWrxqNqTihrAsZhnyYBQ9Y1Qd6k1n1e 8ULw== X-Gm-Message-State: AOAM533xdqolwQ9b36p50jk4eBAA+ce9j5czmPkqRK+DO/FCuK5RyNpS iRXyFEr/tUSAYpukh6XaGaBQmY+BmKX3CfBKYj6F2GLAu8A/dOPTuuyG9Es3FdPA9e2T09td5ez MdrnZnmyGtk1lPO1Su42nHrY= X-Received: by 2002:adf:decb:0:b0:20a:c975:8eec with SMTP id i11-20020adfdecb000000b0020ac9758eecmr28946000wrn.438.1651221797471; Fri, 29 Apr 2022 01:43:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8Bnodipm9XVNni3rYsFrTH34G/LMUhH0fq+PeE59BdcIE+fgw0hrkNZbBfqT2Hiuz7RWIbw== X-Received: by 2002:adf:decb:0:b0:20a:c975:8eec with SMTP id i11-20020adfdecb000000b0020ac9758eecmr28945970wrn.438.1651221797201; Fri, 29 Apr 2022 01:43:17 -0700 (PDT) Received: from minerva.home ([92.176.231.205]) by smtp.gmail.com with ESMTPSA id f7-20020a05600c4e8700b00393f1393abfsm7199256wmq.41.2022.04.29.01.43.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Apr 2022 01:43:16 -0700 (PDT) From: Javier Martinez Canillas To: linux-kernel@vger.kernel.org Cc: dri-devel@lists.freedesktop.org, Daniel Vetter , Greg Kroah-Hartman , Thomas Zimmermann , Javier Martinez Canillas , Alex Deucher , Changcheng Deng , Daniel Vetter , Helge Deller , Sam Ravnborg , Zhen Lei , linux-fbdev@vger.kernel.org Subject: [RFC PATCH v4 08/11] fbdev: Fix race between sysfb and framebuffer devices registration Date: Fri, 29 Apr 2022 10:42:50 +0200 Message-Id: <20220429084253.1085911-9-javierm@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220429084253.1085911-1-javierm@redhat.com> References: <20220429084253.1085911-1-javierm@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org The platform devices registered by sysfb match with firmware-based DRM or fbdev drivers, that are used to have early graphics using a framebuffer provided by the system firmware. DRM or fbdev drivers later are probed and remove all conflicting framebuffers, leading to these platform devices for generic drivers to be unregistered. But the current solution has a race, since the sysfb_init() function could be called after a DRM driver is probed and requested to unregister devices for drivers with conflicting framebuffes. To prevent this, disable any future sysfb platform device registration by calling sysfb_disable(), if either a framebuffer device or a DRM device is registered. Since in that case a display will already be present. Suggested-by: Daniel Vetter Signed-off-by: Javier Martinez Canillas --- (no changes since v3) Changes in v3: - Call sysfb_disable() when a fbdev framebuffer is registered rather than when conflicting framebuffers are removed (Thomas Zimmermann). - Drop Daniel Vetter's Reviewed-by tag since patch changed a lot. Changes in v2: - Explain in the commit message that fbmem has to unregister the device as fallback if a driver registered the device itself (Daniel Vetter). - Also explain that fallback in a comment in the code (Daniel Vetter). - Don't encode in fbmem the assumption that sysfb will always register platform devices (Daniel Vetter). - Add a FIXME comment about drivers registering devices (Daniel Vetter). drivers/video/fbdev/core/fbmem.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c index d6ae33990f40..7583296481b0 100644 --- a/drivers/video/fbdev/core/fbmem.c +++ b/drivers/video/fbdev/core/fbmem.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -1903,6 +1904,17 @@ register_framebuffer(struct fb_info *fb_info) ret = do_register_framebuffer(fb_info); mutex_unlock(®istration_lock); + /* + * If a driver registers a framebuffer device, then it can be assumed + * that a display will be present and there is no need for a generic + * driver using the firmware setup system framebuffer. + * + * Disable sysfb and prevent registering simple framebuffer devices, + * but only do it for framebuffers that are not provided by firmware. + */ + if (!(fb_info->flags & FBINFO_MISC_FIRMWARE)) + sysfb_disable(); + return ret; } EXPORT_SYMBOL(register_framebuffer); From patchwork Fri Apr 29 08:42:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Martinez Canillas X-Patchwork-Id: 568437 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9BDF1C433EF for ; Fri, 29 Apr 2022 08:43:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355974AbiD2Iqr (ORCPT ); Fri, 29 Apr 2022 04:46:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355984AbiD2Iqn (ORCPT ); Fri, 29 Apr 2022 04:46:43 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7060AC42CE for ; Fri, 29 Apr 2022 01:43:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651221803; 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=UDplaZMb5YseJ+Hq/qs3ip7VsbbgryHldJFcbzukwP8=; b=U7i50dcwnuVcFg7vzfU0Odeyc2piyfq7FGbYmQLgAeMThQ5bcHxHu1/eKjl3TfVdokUn94 6Yib/O6obMEgArnquFQDmF3Vu/p/VAjt3VUh+PJpPcYmuJDa2iRvE5Ref8odRTBdOgDfi3 xPprOQZKM9C0AV8crvVI03LwKEVdJvU= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-135--tqRpApdN_GPB4ltMmKkVg-1; Fri, 29 Apr 2022 04:43:21 -0400 X-MC-Unique: -tqRpApdN_GPB4ltMmKkVg-1 Received: by mail-wr1-f69.google.com with SMTP id o11-20020adfca0b000000b0020adc114131so2804881wrh.8 for ; Fri, 29 Apr 2022 01:43:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UDplaZMb5YseJ+Hq/qs3ip7VsbbgryHldJFcbzukwP8=; b=J/nQMROjkaUar8yW0+yd6m288U7xKPozORWdFvebzduRo1zu2LwkBqLHF1Bkzf8PlZ CPychKGZgRbGMD8VedmAWhhG09r6GqA2/dUJXNPs1AbY9gKPqFfL63wdc6HYopXMEc4Z mJ2HaIUAdOikiZR0VMNosg/1KNFLPNdNt16KAuD+havxBI1NkkezdTvC+NfZgSJjjXRd peq8jli2/VSVwp6zyEUfeY/9YAPC8TWgQ6ZiG7OBu7mZlmydgZhsobrH/2MVXpCCwiyM AUDrEHE9TyOgjlg+4YTktxZde4/Zmw3rmXeD6ZmEsF2nkN5vjz6NWg37uTFR5vbmh9v9 XvvQ== X-Gm-Message-State: AOAM531PKZZLU0qMzCCwN+qZm7+svkeKCp4ZROg120zQPwj/Ta37PgBv CtgNYu0eyAfsFAvJkJlk0cw5O5g3IW52EIzfXk2BDx+kR63eaf42ZdoiNFUw8CF94bXR8VMsE5Y DURy3Vgh6E+PAkGeLWZjtp9w= X-Received: by 2002:a05:600c:502b:b0:38f:f7c6:3609 with SMTP id n43-20020a05600c502b00b0038ff7c63609mr2151323wmr.15.1651221800681; Fri, 29 Apr 2022 01:43:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUhJr7adxWPTzLPcLhzy6SAp4kBXCJcXEMXapEUCxJwsbfEcTFBfqvmjks4+3ERNh1qQu2xw== X-Received: by 2002:a05:600c:502b:b0:38f:f7c6:3609 with SMTP id n43-20020a05600c502b00b0038ff7c63609mr2151311wmr.15.1651221800430; Fri, 29 Apr 2022 01:43:20 -0700 (PDT) Received: from minerva.home ([92.176.231.205]) by smtp.gmail.com with ESMTPSA id f7-20020a05600c4e8700b00393f1393abfsm7199256wmq.41.2022.04.29.01.43.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Apr 2022 01:43:20 -0700 (PDT) From: Javier Martinez Canillas To: linux-kernel@vger.kernel.org Cc: dri-devel@lists.freedesktop.org, Daniel Vetter , Greg Kroah-Hartman , Thomas Zimmermann , Zack Rusin , Javier Martinez Canillas , Hans de Goede , Ilya Trukhanov , Daniel Vetter , Peter Jones , linux-fbdev@vger.kernel.org, Helge Deller Subject: [RFC PATCH v4 10/11] Revert "fbdev: Prevent probing generic drivers if a FB is already registered" Date: Fri, 29 Apr 2022 10:42:52 +0200 Message-Id: <20220429084253.1085911-11-javierm@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220429084253.1085911-1-javierm@redhat.com> References: <20220429084253.1085911-1-javierm@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org From: Daniel Vetter This reverts commit fb561bf9abde49f7e00fdbf9ed2ccf2d86cac8ee. With commit 27599aacbaefcbf2af7b06b0029459bbf682000d Author: Thomas Zimmermann Date: Tue Jan 25 10:12:18 2022 +0100 fbdev: Hot-unplug firmware fb devices on forced removal this should be fixed properly and we can remove this somewhat hackish check here (e.g. this won't catch drm drivers if fbdev emulation isn't enabled). Cc: Thomas Zimmermann Cc: Zack Rusin Cc: Javier Martinez Canillas Cc: Zack Rusin Cc: Hans de Goede Cc: Ilya Trukhanov Signed-off-by: Daniel Vetter Signed-off-by: Daniel Vetter Reviewed-by: Javier Martinez Canillas Cc: Peter Jones Cc: linux-fbdev@vger.kernel.org Signed-off-by: Javier Martinez Canillas --- (no changes since v1) drivers/video/fbdev/efifb.c | 11 ----------- drivers/video/fbdev/simplefb.c | 11 ----------- 2 files changed, 22 deletions(-) diff --git a/drivers/video/fbdev/efifb.c b/drivers/video/fbdev/efifb.c index ea42ba6445b2..edca3703b964 100644 --- a/drivers/video/fbdev/efifb.c +++ b/drivers/video/fbdev/efifb.c @@ -351,17 +351,6 @@ static int efifb_probe(struct platform_device *dev) char *option = NULL; efi_memory_desc_t md; - /* - * Generic drivers must not be registered if a framebuffer exists. - * If a native driver was probed, the display hardware was already - * taken and attempting to use the system framebuffer is dangerous. - */ - if (num_registered_fb > 0) { - dev_err(&dev->dev, - "efifb: a framebuffer is already registered\n"); - return -EINVAL; - } - if (screen_info.orig_video_isVGA != VIDEO_TYPE_EFI || pci_dev_disabled) return -ENODEV; diff --git a/drivers/video/fbdev/simplefb.c b/drivers/video/fbdev/simplefb.c index 94fc9c6d0411..0ef41173325a 100644 --- a/drivers/video/fbdev/simplefb.c +++ b/drivers/video/fbdev/simplefb.c @@ -413,17 +413,6 @@ static int simplefb_probe(struct platform_device *pdev) struct simplefb_par *par; struct resource *res, *mem; - /* - * Generic drivers must not be registered if a framebuffer exists. - * If a native driver was probed, the display hardware was already - * taken and attempting to use the system framebuffer is dangerous. - */ - if (num_registered_fb > 0) { - dev_err(&pdev->dev, - "simplefb: a framebuffer is already registered\n"); - return -EINVAL; - } - if (fb_get_options("simplefb", NULL)) return -ENODEV; From patchwork Fri Apr 29 08:42:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Martinez Canillas X-Patchwork-Id: 568436 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63AA8C433F5 for ; Fri, 29 Apr 2022 08:43:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355907AbiD2Iqv (ORCPT ); Fri, 29 Apr 2022 04:46:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355961AbiD2Iqo (ORCPT ); Fri, 29 Apr 2022 04:46:44 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 00CBAC400F for ; Fri, 29 Apr 2022 01:43:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651221806; 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=GpZJ4wX7kOe8KNr9fDnXvQai/0Kn9GYbVZ0gMqgfC8g=; b=duY4kW6OR2jlslzH/efDe0mnfkyisEJGZ04jZ9oF6/d0bJT+jDGUpS8dGhqAeZfDefGofn Xd+BQqUpuzVndJdE0Ed5UlYD43+Jsof0JcUhdx7nU+K6HLwZCG3sXUwlUTl3nBMobXFgEO S7aFoU5xRqBmxav4+MVe7oBV4sGCx2Y= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-453-fnt9mg_JP-Ku4AqjLkQ5Hg-1; Fri, 29 Apr 2022 04:43:24 -0400 X-MC-Unique: fnt9mg_JP-Ku4AqjLkQ5Hg-1 Received: by mail-wm1-f72.google.com with SMTP id bh7-20020a05600c3d0700b003940829b48dso3113281wmb.1 for ; Fri, 29 Apr 2022 01:43:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GpZJ4wX7kOe8KNr9fDnXvQai/0Kn9GYbVZ0gMqgfC8g=; b=DzorNLrqUhMsATNXyCeBGc2Uwrb61367n9iWCisIrdnf7w5NOesrAHeRoZrByy0EkO KeNIRCgr3iHK3QiCr7qXHJHUwxXdoS26Xnh9CUCm64aD96qAmf9ZuWbg+MroUkPZrtOw 7uiDx6O05VblVIJ8WcogCiYWDUkTEMiajoDGQJe/4hjtDQ1loK+oMuTlxEOo2zMx9jfc 6CSVa2uJNuLzESkE2/caIxaOo/jWoU0HYOm752b363/3Swf7p/Bw2YQEHJ1uLWXmOlAr DsK0ZMhUgt34F/AF6FLc5P47cKuVvox2ExZVBpdKZBoPwigQv0fhyxqnFDn3OraMkV0p +vnQ== X-Gm-Message-State: AOAM531uPu6nqwuY5VzrDJFFQn/EEFoPEfcxQ6i72nVaVk9hJCtfxmmm QA1TyFjbHSJEg2rAF+x3km72D1+3ZhLqToFiwX/wSX6dOLL4bcV8/pwtAzFffeV7U7S/3t52Qi6 ZGTFc1zB7jtwhvAWbE91qEjg= X-Received: by 2002:a05:600c:4ec6:b0:394:1f35:4c69 with SMTP id g6-20020a05600c4ec600b003941f354c69mr1752575wmq.61.1651221802221; Fri, 29 Apr 2022 01:43:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwhmIBm7Rgju2BXAxf7jfHuCnxn2Uoy7l4mQ/iKVv2qM/3Q7Bt+zoSMdfHM0/61ANAlGkIsNA== X-Received: by 2002:a05:600c:4ec6:b0:394:1f35:4c69 with SMTP id g6-20020a05600c4ec600b003941f354c69mr1752548wmq.61.1651221802012; Fri, 29 Apr 2022 01:43:22 -0700 (PDT) Received: from minerva.home ([92.176.231.205]) by smtp.gmail.com with ESMTPSA id f7-20020a05600c4e8700b00393f1393abfsm7199256wmq.41.2022.04.29.01.43.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Apr 2022 01:43:21 -0700 (PDT) From: Javier Martinez Canillas To: linux-kernel@vger.kernel.org Cc: dri-devel@lists.freedesktop.org, Daniel Vetter , Greg Kroah-Hartman , Thomas Zimmermann , kernel test robot , Jens Frederich , Jon Nettleton , linux-staging@lists.linux.dev, Daniel Vetter , Javier Martinez Canillas , Daniel Vetter , Helge Deller , Matthew Wilcox , Sam Ravnborg , Tetsuo Handa , Zhen Lei , Alex Deucher , Xiyu Yang , linux-fbdev@vger.kernel.org, Zheyu Ma , Guenter Roeck , Changcheng Deng Subject: [RFC PATCH v4 11/11] fbdev: Make registered_fb[] private to fbmem.c Date: Fri, 29 Apr 2022 10:42:53 +0200 Message-Id: <20220429084253.1085911-12-javierm@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220429084253.1085911-1-javierm@redhat.com> References: <20220429084253.1085911-1-javierm@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org From: Daniel Vetter Well except when the olpc dcon fbdev driver is enabled, that thing digs around in there in rather unfixable ways. Cc oldc_dcon maintainers as fyi. v2: I typoed the config name (0day) Cc: kernel test robot Cc: Jens Frederich Cc: Jon Nettleton Cc: Greg Kroah-Hartman Cc: linux-staging@lists.linux.dev Signed-off-by: Daniel Vetter Signed-off-by: Daniel Vetter Reviewed-by: Javier Martinez Canillas Cc: Daniel Vetter Cc: Helge Deller Cc: Matthew Wilcox Cc: Sam Ravnborg Cc: Tetsuo Handa Cc: Zhen Lei Cc: Alex Deucher Cc: Xiyu Yang Cc: linux-fbdev@vger.kernel.org Cc: Zheyu Ma Cc: Guenter Roeck Signed-off-by: Javier Martinez Canillas --- (no changes since v1) drivers/video/fbdev/core/fbmem.c | 8 ++++++-- include/linux/fb.h | 7 +++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c index 7583296481b0..1ce5b0f3abd4 100644 --- a/drivers/video/fbdev/core/fbmem.c +++ b/drivers/video/fbdev/core/fbmem.c @@ -50,10 +50,14 @@ static DEFINE_MUTEX(registration_lock); struct fb_info *registered_fb[FB_MAX] __read_mostly; -EXPORT_SYMBOL(registered_fb); - int num_registered_fb __read_mostly; +#if IS_ENABLED(CONFIG_FB_OLPC_DCON) +EXPORT_SYMBOL(registered_fb); EXPORT_SYMBOL(num_registered_fb); +#endif +#define for_each_registered_fb(i) \ + for (i = 0; i < FB_MAX; i++) \ + if (!registered_fb[i]) {} else bool fb_center_logo __read_mostly; diff --git a/include/linux/fb.h b/include/linux/fb.h index b781bc721113..208bca693b33 100644 --- a/include/linux/fb.h +++ b/include/linux/fb.h @@ -623,16 +623,15 @@ extern int fb_get_color_depth(struct fb_var_screeninfo *var, extern int fb_get_options(const char *name, char **option); extern int fb_new_modelist(struct fb_info *info); +#if IS_ENABLED(CONFIG_FB_OLPC_DCON) extern struct fb_info *registered_fb[FB_MAX]; + extern int num_registered_fb; +#endif extern bool fb_center_logo; extern int fb_logo_count; extern struct class *fb_class; -#define for_each_registered_fb(i) \ - for (i = 0; i < FB_MAX; i++) \ - if (!registered_fb[i]) {} else - static inline void lock_fb_info(struct fb_info *info) { mutex_lock(&info->lock);