Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp685816pxp; Fri, 11 Mar 2022 12:23:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJxR/z4pNem9p5yq/xLDVqAoHp8Htsv9TzNlZiiR6jqnOEi4oFB75Bepzk5VL/u+ZilLhRUM X-Received: by 2002:a17:903:24f:b0:153:32c0:7d6f with SMTP id j15-20020a170903024f00b0015332c07d6fmr5696675plh.36.1647030199408; Fri, 11 Mar 2022 12:23:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1647030199; cv=none; d=google.com; s=arc-20160816; b=ZVUVOHGBJi6GxtWbOdd/am4d68cPhPoRO7gaBqk88Ss9Ro31B62AgnOrAmVaIUx1zK 3BiZnksvZrYS7WpXivjRxPOeUJEMi3FgP9MiHBNZ1nhHnbh5RRJS5Fn7heQa8rckkTPV i3kTIFXvi6Z6gL7SPQdceQJ+s+b82NvB4FvgPeLlf3j1KRyo2+so4TUQHw4M4on04xIf V8CpZRCjFQdvr7hFRtVNzSE8Ay1w1jCwhkF+ZTyCgk7/Sa+IBCMeLLhK2sHel2PwL3wr q7TGfmaqGxT0aRuaVPRv57dv8WnYphhfbelD+e6XV4FN8GKtQbHNarSKeur3nmxv0nMa /ztA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=9wYKto1d7ZYwEEExQdFyMvSXZBeKzgysfuVY2LxCL4Y=; b=LoNQk0NHmLAPgompZ8Peaw5l7+3gvSXkxAF8N4rVKSary5wZUpZUpZgFdHxTq0lV8q w8bXZavStZChE/JTFPEYAdWedtrMGu8EiXmzH1UsGXU9scjfht2yyZJxsNNi/xl5D1Zy iiPQvFn2TBxa1vM5FHoPFT8noGqcfvsPSu3yAQ85dBBnecDonUjTMfYxNc5sNN7hu6YW 0+8c3RM4pdda2n1alf8XTxsVwhFxIIYC8KnjNB+v0xubdBA86XhsiISMICH5gPLO9YSR QXncpGnKbbZhLbsqmON6D3Oje3v9D/MS6cSA17OjrOz76KaALlcNisdhUtHLVNYBozSx ZPMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=IpFgOc0T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s207-20020a632cd8000000b0037c5f979ebbsi8541439pgs.476.2022.03.11.12.22.53; Fri, 11 Mar 2022 12:23:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=IpFgOc0T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347540AbiCKJfk (ORCPT + 99 others); Fri, 11 Mar 2022 04:35:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245495AbiCKJfi (ORCPT ); Fri, 11 Mar 2022 04:35:38 -0500 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2CF31BE0ED for ; Fri, 11 Mar 2022 01:34:35 -0800 (PST) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: rcn) with ESMTPSA id 2CCEC1F46496 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1646991274; bh=Jse5jslyQwK8jYrGmsf8TVyXCyfWaI4dN1Xg9g/UKcA=; h=From:To:Cc:Subject:Date:From; b=IpFgOc0TudE0KJyzh7uv590XVGZF6klHXcFh6GrFFLQyRGb/YAofcmFwQ+BjhVEbw TbmFtww7jSInDHtYABfZbAIXJLwkAwwf2fc3I+jAAnV23uItwiZMmAqtoQr1JZzTFr oqaGb/Uch5ozrOKkk4nfOT8lvzrsJCisO4KM5bh8XJMB3HVVkYuIrHD9kFMMdT28mX MR6UWePzBT8als4P/ngrk66/on8Q1Kak/rTTMMd7nbUDHz0UCS3qhPs9CkH0kmEH5G ImflviUi5gPK+n31hBNaCBNIRnjrv1PCLbMHWE8IDk/RitGJperU5lHrWHTJgeLbvr ya8JKpVqTlGRQ== From: =?UTF-8?q?Ricardo=20Ca=C3=B1uelo?= To: dri-devel@lists.freedesktop.org Cc: linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, kernel@collabora.com, andrzej.hajda@intel.com, narmstrong@baylibre.com, maarten.lankhorst@linux.intel.com, mripard@kernel.org Subject: [PATCH 0/2 RESEND] Mitigate race condition problems when unbinding DRM driver Date: Fri, 11 Mar 2022 10:34:04 +0100 Message-Id: <20220311093406.4068019-1-ricardo.canuelo@collabora.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham 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 Hi all, I'm sending these patches to try to improve the current situation for a particular corner case (DRM driver unbinding). I could reproduce a specific race condition during the unbinding of the mediatek-drm driver that caused an invalid memory address. The race condition is triggered by a userspace event (gnome-shell requesting a DRM GET_CONNECTOR ioctl) while the encoders and drivers are in the process of being disabled. While I tried to mitigate this by making a small change in the parade-ps8640 driver (for the bridge I'm testing on) and by making a couple of functions in drm_bridge.c more robust, this is only a symptom of a larger problem that might not be getting enough attention, understandably, because this is an unusual corner case. The scenario looks like this: : unbind mediatek-drm --------------------+ | | | | | ... | | ... mtk_dsi_unbind | | | `- drm_encoder_cleanup v | | gnome-shell ... `- drm_bridge_detach *<------ ioctl (GET_CONNECTOR) | | ... | | ps8640_bridge_get_edid | `drm_bridge_chain_post_disable which causes drm_bridge_chain_post_disable() to walk the bridge chain after the bridge has already been detached and removed from the list. I guess a more radical and subsystem-wide solution would be to not allow or to block certain ioctl calls once the driver has started to unbind, but I'd like to hear your opinion on this. This was tested on an Acer Chromebook R13 (Elm, MT8173) running Debian Sid, the command that triggers the race condition is echo mediatek-drm.12.auto > /sys/bus/platform/drivers/mediatek-drm/unbind Cheers, Ricardo Ricardo CaƱuelo (2): drm/bridge: parade-ps8640: avoid race condition on driver unbinding drm/bridge: Add extra checks in pre_enable and post_enable drivers/gpu/drm/bridge/parade-ps8640.c | 6 +++--- drivers/gpu/drm/drm_bridge.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) -- 2.25.1