From patchwork Wed Apr 6 16:06:31 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: 12803721 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 054C0C433F5 for ; Wed, 6 Apr 2022 16:06:54 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 03C2D10E3CF; Wed, 6 Apr 2022 16:06:53 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id E4FDF10E5B3 for ; Wed, 6 Apr 2022 16:06:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649261210; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U2QzSBkwn7Yafa/16sbGGbBUM4FbySeU5GGeHJm/Jx0=; b=Y8YLG5QnpujSQRaDbmAuMSle09h+uwuyStf/6tz8tmEr7Rn6pemArQosey5V6GUHdJicAR 2YP4GeyFI8foAmmM5tn7aZiB/X77scwCbj6ne7GY/R6ffyqDLaxqJBgC+ocIVcKBjjyBvD 0JmNHzSw3uF1f4TJkdWjdXaZwDaHa2Y= 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-612-F-JjWjyrO-Kjdr_JK0bhQQ-1; Wed, 06 Apr 2022 12:06:49 -0400 X-MC-Unique: F-JjWjyrO-Kjdr_JK0bhQQ-1 Received: by mail-wr1-f72.google.com with SMTP id z16-20020adff1d0000000b001ef7dc78b23so648579wro.12 for ; Wed, 06 Apr 2022 09:06:49 -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=U2QzSBkwn7Yafa/16sbGGbBUM4FbySeU5GGeHJm/Jx0=; b=NY+QFYT8N6iqpvcA6YPvrMXxj686UxKT4+2cab60/1Px3DhghqCH40uDJOeVO02K7W Djra5GLm2TM5KvRPoqSTBDfwPNXPpcqQrvbVShHim40FIGroFDtpnMAqQaeqSK/tRxw2 7NdJ592SNh6Zk8WKTjhuTnQNvOWgTwJHkuPK22OrpXFjT1NP7pjuSWSbyXURTvwcqIFM kq6Hu0o4o2iLdE6So4TmbUaFX2WM+r8q5vIRj9ISZ6uCDzKhdXc9sfUfsiB9uFdclDEY 0fx6pLnXijaiyBp8hD3fVCG7FDnIcd3514spEdvaimH8IkfdMZ77Aud9lOc4unKYAAb5 /SeQ== X-Gm-Message-State: AOAM532a7xNjrp+nxv0FJ95xglJG7G3Ireuv+pjSQI4rfmitJfudiQWw o+tbDrcXdRQfa7XKbHtexBHSoNKdrTHF+UT1eLo/DRF3Vk6zzDasijfGkBZqj2aQky08wswpelj vp+tri3p1YR4dbZ38Pyp6mzU4xAsf X-Received: by 2002:a05:600c:3b26:b0:38c:8358:4b84 with SMTP id m38-20020a05600c3b2600b0038c83584b84mr8262621wms.185.1649261208656; Wed, 06 Apr 2022 09:06:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwrWRPcdVNxxa0OQoFxVtMgEvN6P53Xni3VcPZinWUwk/8XrPqG2DL56DBxegaE9MICKK7T2Q== X-Received: by 2002:a05:600c:3b26:b0:38c:8358:4b84 with SMTP id m38-20020a05600c3b2600b0038c83584b84mr8262596wms.185.1649261208370; Wed, 06 Apr 2022 09:06:48 -0700 (PDT) Received: from minerva.home ([92.176.231.205]) by smtp.gmail.com with ESMTPSA id f1-20020a1c6a01000000b0038c9f6a3634sm5038899wmc.7.2022.04.06.09.06.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 09:06:48 -0700 (PDT) From: Javier Martinez Canillas To: linux-kernel@vger.kernel.org Subject: [RFC PATCH 4/5] fbdev: Fix some race conditions between fbmem and sysfb Date: Wed, 6 Apr 2022 18:06:31 +0200 Message-Id: <20220406160632.496684-5-javierm@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220406160632.496684-1-javierm@redhat.com> References: <20220406160632.496684-1-javierm@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=javierm@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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: linux-fbdev@vger.kernel.org, Xiyu Yang , Daniel Vetter , Helge Deller , Zheyu Ma , Javier Martinez Canillas , dri-devel@lists.freedesktop.org, Hans de Goede , Thomas Zimmermann , Zhen Lei , Alex Deucher , Sam Ravnborg Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 */ + 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. + */ + sysfb_disable(); + mutex_lock(®istration_lock); do_remove_conflicting_framebuffers(a, name, primary); mutex_unlock(®istration_lock);