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 2D65BC4332F for ; Wed, 6 Apr 2022 16:06:56 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6328610E461; 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 C73F310E3CF for ; Wed, 6 Apr 2022 16:06:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649261209; 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=KV4A7vxPY5Ri/A7ExTRv30H1oUVvMjyO4SRhZ4A4Rkc=; b=RIznz/B0HEvydFXlrxgSX99d+zp8VBNnjWHlvZ3P6ihViBQMevsXgY4ivsbvx3kBuNBoVT Im25a+oHn2/FeITtaBeolfpwfAH66EN59LRKztC+w7DukMQdamWLKCZIDU8hD5QrzyVLF2 OFVmnZePwhIfOYVxH/49IyvvyhJR5V0= 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-412-1mlSNRppOai-yzPJPMQG9A-1; Wed, 06 Apr 2022 12:06:48 -0400 X-MC-Unique: 1mlSNRppOai-yzPJPMQG9A-1 Received: by mail-wr1-f72.google.com with SMTP id d10-20020adfa40a000000b0020608fb395eso655343wra.11 for ; Wed, 06 Apr 2022 09:06:48 -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=KV4A7vxPY5Ri/A7ExTRv30H1oUVvMjyO4SRhZ4A4Rkc=; b=zum9ZCEodQUz/z5hZuC32bg+Bm7La57MaFBxldvlfUnTltVJyFLbINql1lU0CVLiGL GAzfF3rai1MIbpDHhTszNBs9+BPe3AAr7Nqc9wwadlbiFlZn4gN9eU60WPNW3NgUhpK1 Pk3+Nr8ROWQtzQ1v04gMzWgoHQD7CJaHZ0jelHkFAJvTMKOgbZi4O76xcHTpnP9cZpNg IWmiWje69rX/VkosbMiLQJ5uUIcnyxdP5meG/dmL3glAHpMzUQWTGGumQOMJZ1s/MW6Y ezGMyFLKDfIThWbyAa11E0F2ibhKnJUmzFEhWA626XijlNzXzzVgvQjAgZzphCBVgknW rI4A== X-Gm-Message-State: AOAM530uaYh9PvVMBR+8NFZKkCBcKNC3AjiF/lhodx3VQuY3L14w2Ygf 67jB6xYZgsIdZJwYOxvpw4IeHDxOLfNSvRG17DT7DJ/U1zNrR+xz9LFu/dKbXqBxwhZ9HcShkFH +thbHstkLtHM2ZMgBBROu/RMUGycX X-Received: by 2002:adf:f94d:0:b0:1e5:5ca1:2b80 with SMTP id q13-20020adff94d000000b001e55ca12b80mr7358636wrr.323.1649261207512; Wed, 06 Apr 2022 09:06:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4iqTGXWAmr0kVXiSaBoH7zqLfupO6IvuwBcok5RYqdCJJH/FQ8YSgWM4GphZdzl59KrH3Wg== X-Received: by 2002:adf:f94d:0:b0:1e5:5ca1:2b80 with SMTP id q13-20020adff94d000000b001e55ca12b80mr7358600wrr.323.1649261207193; Wed, 06 Apr 2022 09:06:47 -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.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 09:06:46 -0700 (PDT) From: Javier Martinez Canillas To: linux-kernel@vger.kernel.org Subject: [RFC PATCH 3/5] fbdev: Restart conflicting fb removal loop when unregistering devices Date: Wed, 6 Apr 2022 18:06:30 +0200 Message-Id: <20220406160632.496684-4-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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 , Javier Martinez Canillas , dri-devel@lists.freedesktop.org, Thomas Zimmermann , Zhen Lei , Alex Deucher , Sam Ravnborg , Guenter Roeck Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 --- drivers/video/fbdev/core/fbmem.c | 21 ++++++++++++++------- include/linux/fb.h | 1 - 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c index b585339509b0..c1bfb8df9cba 100644 --- a/drivers/video/fbdev/core/fbmem.c +++ b/drivers/video/fbdev/core/fbmem.c @@ -1555,6 +1555,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; @@ -1582,8 +1583,18 @@ static void do_remove_conflicting_framebuffers(struct apertures_struct *a, * fix would add code to remove the device from the system. */ if (dev_is_platform(device)) { - registered_fb[i]->forced_out = true; + /* + * Drop the lock since the driver will call to the + * unregister_framebuffer() function that takes it. + */ + mutex_unlock(®istration_lock); platform_device_unregister(to_platform_device(device)); + mutex_lock(®istration_lock); + /* + * Restart the removal now that the platform device + * has been unregistered and its associated fb gone. + */ + goto restart_removal; } else { pr_warn("fb%d: cannot remove device\n", i); do_unregister_framebuffer(registered_fb[i]); @@ -1917,13 +1928,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 39baa9a70779..f1e0cd751b06 100644 --- a/include/linux/fb.h +++ b/include/linux/fb.h @@ -503,7 +503,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) { -- 2.35.1