Received: by 2002:a05:6a10:83d0:0:0:0:0 with SMTP id o16csp44544pxh; Thu, 7 Apr 2022 13:28:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzp0HYpQ7m6ZbuUwB1O/3TbckF5cX4NMhoCavaRlPfPWb6CsICUOwGWOajhvpCQ2KPdep3H X-Received: by 2002:a17:902:9304:b0:155:eb5a:8dd4 with SMTP id bc4-20020a170902930400b00155eb5a8dd4mr15808738plb.117.1649363333295; Thu, 07 Apr 2022 13:28:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649363333; cv=none; d=google.com; s=arc-20160816; b=PZCQTYJbOvIs6FdIUxUj3aKIbuzRNHVs4P0SdrFVPK9vcP42u+2GNKJ8h7nbCscUW4 IglHmZhzbcuretmMffNglUaeB2BJI8b0gZj5ombOuUvSTAVh9WTzqz7741h4eSsDKSGB GVAurgveV4+Vm0bbJE7df9yIGRkphyaSdmDak3fP7Hschhlmi90WU3FKUawP2XsUWnu+ 64qRwLaEb/EBNYKfgOnhKPmeLwYOtMPjlAd6QxKXx5RoMsSk9p1aI/hScRO8VBdJEjSR 8Q72B67lDIOaZhmILNNtjH4R7p8caTwIoFRbYdJlwSRjrQDiMhdk515R5ld/gXyVwevt AmbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:mail-followup-to:message-id:subject:cc:to:from:date :dkim-signature; bh=RUqwFRBKiy3Of7LlIlozTAVQBDGmsY1swdmuSjymSg4=; b=RrOApN+BHQkrUJ/7ERl3b4VESaCAzAzLigGxAJ6qhwisGmh9ql2Hihp3cN5qV3lFrt uF9bfE80Y/+FmINWKdpL+T1glEiD5PPzN09s4k9oP2SCM6/zyqI6Giu5YnXVS7xgI1Wg lfh/GKn9zOMnTCilwsf+Qrp9G7zyc839V62bES7vRxMpilRM5yVkJDrBUgXue3rYx8Hf 9SRNC4OKfJHSum9pwDIWm7dVutqNVQVhz76Gy5otdTriR8n8VvubBlQHALwZ9lE6NCbX NbjN0c1WBcu6nkYPH9yi9fKRLlZONhYkRDW7BvGYCEHPbcZT+w/Pv0ZOpB8kM2D1zgI3 7nTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=Dwig1lDH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id w15-20020aa7954f000000b004fa661777fdsi18917539pfq.298.2022.04.07.13.28.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 13:28:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=Dwig1lDH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 20904369E3B; Thu, 7 Apr 2022 12:43:49 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243678AbiDGJO3 (ORCPT + 99 others); Thu, 7 Apr 2022 05:14:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243624AbiDGJNl (ORCPT ); Thu, 7 Apr 2022 05:13:41 -0400 Received: from mail-ej1-x644.google.com (mail-ej1-x644.google.com [IPv6:2a00:1450:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E94D3C90D1 for ; Thu, 7 Apr 2022 02:11:33 -0700 (PDT) Received: by mail-ej1-x644.google.com with SMTP id a6so9596883ejk.0 for ; Thu, 07 Apr 2022 02:11:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=RUqwFRBKiy3Of7LlIlozTAVQBDGmsY1swdmuSjymSg4=; b=Dwig1lDH/CD6wp+0muFEkyqscS1kh60CsqsPd4pTvM38WbbpVW7g0SpyiRvJIHG2KA x8oT4fL3umaFDzh74fKUR/e2xEdy+hwOHWGwVhNnOECj4TF9o5VF3kjtTa+4PP8ECxxY pIsmR9GqdtZ7VZLoUaMmOHyE8pbibPWyjXGnM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to; bh=RUqwFRBKiy3Of7LlIlozTAVQBDGmsY1swdmuSjymSg4=; b=70pEWlwkuX3bN8fRBLWYIN92wqk1s1QthoVIyDJw36wGBskFkwUXcE+fwmUDRUiyJy vRH/Stj2tg+ruRRSFSmwycjhUOFkNmXTgQVth936ee5tHpvH3OyW/vZCuDmHJgPzrKFU E3ojpalExAjyh9pgK+mSi4zVWd7CVRcLttvd55FOw2kh7fRGwUwlBSPwwsm+VDRrw/9C SHd1j7RIago7qowy3UJt7/d73CUIT4KU+jrvTscFVa7mWMi80GBBF0f2bNTNKmF0nHtu L++ArRI4wKg5/D24/mMT8qxv/943dalG1Lu7edeygQ6CRV/sUhenSRZaB9Ka9DoBRLKU lOqw== X-Gm-Message-State: AOAM5333kVSJhKTnqAPToNNgkAa8kdHS8I10sGnx7oZQgwefsQ5LIKD6 UtRucMrbYjUG8Ye8m/yfxQOb9g== X-Received: by 2002:a17:906:1b46:b0:6e8:4cc:b381 with SMTP id p6-20020a1709061b4600b006e804ccb381mr12205836ejg.563.1649322692479; Thu, 07 Apr 2022 02:11:32 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id s11-20020a1709066c8b00b006e7ca6f0401sm4982037ejr.136.2022.04.07.02.11.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 02:11:31 -0700 (PDT) Date: Thu, 7 Apr 2022 11:11:30 +0200 From: Daniel Vetter To: Javier Martinez Canillas Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Thomas Zimmermann , Daniel Vetter , Alex Deucher , Guenter Roeck , Helge Deller , Sam Ravnborg , Xiyu Yang , Zhen Lei , linux-fbdev@vger.kernel.org Subject: Re: [RESEND RFC PATCH 4/5] fbdev: Fix some race conditions between fbmem and sysfb Message-ID: Mail-Followup-To: Javier Martinez Canillas , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Thomas Zimmermann , Alex Deucher , Guenter Roeck , Helge Deller , Sam Ravnborg , Xiyu Yang , Zhen Lei , linux-fbdev@vger.kernel.org References: <20220406213919.600294-1-javierm@redhat.com> <20220406213919.600294-5-javierm@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220406213919.600294-5-javierm@redhat.com> X-Operating-System: Linux phenom 5.10.0-8-amd64 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=no 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 On Wed, Apr 06, 2022 at 11:39:18PM +0200, Javier Martinez Canillas wrote: > 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 two issues that this patch fixes: > > 1) It is a layering violation for the fbdev core to unregister a device > that was registered by sysfb. > > Instead, the sysfb_try_unregister() helper function can be called for > sysfb to attempt unregistering the device if is the one registered. > > 2) The sysfb_init() function could be called after a DRM driver is probed > and requested to unregister devices for drivers with a conflicting fb. > > To prevent this, disable any future sysfb platform device registration > by calling sysfb_disable(), if a driver requested to remove conflicting > framebuffers with remove_conflicting_framebuffers(). > > Suggested-by: Daniel Vetter > Signed-off-by: Javier Martinez Canillas > --- > > drivers/video/fbdev/core/fbmem.c | 17 ++++++++++++++++- > 1 file changed, 16 insertions(+), 1 deletion(-) > > diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c > index c1bfb8df9cba..acf641b05d11 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 > @@ -1588,7 +1589,10 @@ static void do_remove_conflicting_framebuffers(struct apertures_struct *a, > * unregister_framebuffer() function that takes it. > */ > mutex_unlock(®istration_lock); > - platform_device_unregister(to_platform_device(device)); > + if (!sysfb_try_unregister(device)) { > + /* sysfb didn't register this device, unregister it */ Maybe explain in the commit message that this is still needed for drivers which set up their platform_dev themselves, like vga16fb. Also I'm not sure we want to have an assumption encoded in fbmem.c here that the sysfb device is always a platform device. I think it would be better to call sysfb_try_unregister on any device, and then fall back to the forced removal on our own if it's a platform device. Also maybe change the comment to /* FIXME: Not all platform fb drivers use sysfb yet */ > + platform_device_unregister(to_platform_device(device)); > + } > mutex_lock(®istration_lock); > /* > * Restart the removal now that the platform device > @@ -1781,6 +1785,17 @@ int remove_conflicting_framebuffers(struct apertures_struct *a, > do_free = true; > } > > + /* > + * If a driver asked to unregister a platform device registered by > + * sysfb, then can be assumed that this is a driver for a display > + * that is set up by the system firmware and has a generic driver. > + * > + * Drivers for devices that don't have a generic driver will never > + * ask for this, so let's assume that a real driver for the display > + * was already probed and prevent sysfb to register devices later. > + */ Yeah it's disappointing, but no worse than the piles of hacks we have now. With the bikesheds addressed above: Reviewed-by: Daniel Vetter > + sysfb_disable(); > + > mutex_lock(®istration_lock); > do_remove_conflicting_framebuffers(a, name, primary); > mutex_unlock(®istration_lock); > -- > 2.35.1 > -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch