Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp666731pxb; Fri, 14 Jan 2022 13:34:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJzR4T9jewzdo/YlmwQukw+RAEn4m/6jt7J+X53mDB2beA4UjYtEYulUGBSwSnJx8NvwJtpe X-Received: by 2002:a17:902:e752:b0:14a:4743:be6e with SMTP id p18-20020a170902e75200b0014a4743be6emr11706002plf.122.1642196040322; Fri, 14 Jan 2022 13:34:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642196040; cv=none; d=google.com; s=arc-20160816; b=RsuSXH2rKz8a0P1WH+mMGUgm6Xy4ATRwEpx3F6QFJs7xkuXQSPdpcNRGDnxFymGLKC XxSly7jxWh1kHofWZfW1RLX+KDb5njDvfBn5kjRJ94ZD5efH7vs/3JRrIs1ukxwxqW2Y H4b1mEHl9OctlM0Ay0NPPByFnT6OOOT5Q378k9p8KOyocFbqAO6lHwHuFEacK7YvrunM rODDeXo9g2I+uQyuP99EYdwFG4qLlWOL/TFBxrIb95+uVNMUJhJGeq6235qe4nYu4/Kt bQ9bJfuJxBKbgpLl4CIG/mi5Ajpt34qiBzd4IGJVPvf5V/chACFWHrU9b2qDPoMyXCQ3 vobw== 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=OhmHjxYEAlQk04T9O6nMAB8Vv4iNH9fQP4rX/PFRRjk=; b=QoF05lwcrDggmVP+kmjZVMwPyEq2aT/BziP8Tyfpde3OxiduGhemnJGPKLO9CpHIpr O7Oe6Pf+lzkGKYGt6QpoiOzJWTzmecSrRFaPRAgSZ7iCKZtdQlcuCHoP5dEaovl+EB8a Vi4OU3X/JYbn1jHV7u1vNwnU51eaZsWMIQ2vH5MOyGpMege+e9P4huQS+8pQXpW2Wh94 hww7hoKn93A5r4uNCemHOWd+OVwn6OWNCGC5sxcv1hhHUWpiLVr+/R52QdLSUy4Ie6rT tTO4UyaP7Hu5RVHE8qAyY2Dm58LzaZHw9VfA3Q7RH+m18XxD9R26tsdAtJptvBeYetW1 HyXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=D8AJQ4G4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g38si5818715pgb.150.2022.01.14.13.33.47; Fri, 14 Jan 2022 13:34:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=D8AJQ4G4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S242020AbiANOrw (ORCPT + 99 others); Fri, 14 Jan 2022 09:47:52 -0500 Received: from bhuna.collabora.co.uk ([46.235.227.227]:58570 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241999AbiANOrt (ORCPT ); Fri, 14 Jan 2022 09:47:49 -0500 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: kholk11) with ESMTPSA id A6C881F46A72 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1642171668; bh=cTHqww4IZbi5PdxScVJ5RmgEFWGNWZU4AMAqnvnN1vM=; h=From:To:Cc:Subject:Date:From; b=D8AJQ4G4r14QCgGUpRCWn6AKwg2pAfphNZFKn9dWfT35vWJoI66KVSW7wOn/gXH8F 8+A7uBI3Sn2tDAHAu12zTel7evWbULUfMEnbsbcxcD7qYOmoOwRj5QuEa6f11pCGRl 5TKGmqC9UO3H/KHxP4s6DO9sC+IGFySuqpp0mit5cnsdk9mYk37bFOnzi4dGPnKHZv ANmplostgKQQYVTggvCRI3XtxFzRbJFVi+xojzgODipky/Se7m9u57A3wmx0z3RvM+ VgAMkZairRwIwTkLmvYFbS+bM97KSZJjTomHxGawqHkf0W88KMMwmKbb8P1u8d1H3U 7bYait9ekDf5w== From: AngeloGioacchino Del Regno To: bjorn.andersson@linaro.org Cc: mathieu.poirier@linaro.org, matthias.bgg@gmail.com, pihsun@chromium.org, linux-remoteproc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, kernel@collabora.com, AngeloGioacchino Del Regno Subject: [PATCH] rpmsg: mtk_rpmsg: Fix circular locking dependency Date: Fri, 14 Jan 2022 15:47:37 +0100 Message-Id: <20220114144737.375621-1-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.33.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org During execution of the worker that's used to register rpmsg devices we are safely locking the channels mutex but, when creating a new endpoint for such devices, we are registering a IPI on the SCP, which then makes the SCP to trigger an interrupt, lock its own mutex and in turn register more subdevices. This creates a circular locking dependency situation, as the mtk_rpmsg channels_lock will then depend on the SCP IPI lock. [ 18.014514] Possible unsafe locking scenario: [ 18.014515] CPU0 CPU1 [ 18.014517] ---- ---- [ 18.045467] lock(&mtk_subdev->channels_lock); [ 18.045474] lock(&scp->ipi_desc[i].lock); [ 18.228399] lock(&mtk_subdev->channels_lock); [ 18.228405] lock(&scp->ipi_desc[i].lock); [ 18.264405] To solve this, simply unlock the channels_lock mutex before calling mtk_rpmsg_register_device() and relock it right after, as safety is still ensured by the locking mechanism that happens right after through SCP. Notably, mtk_rpmsg_register_device() does not even require locking. Fixes: 7017996951fd ("rpmsg: add rpmsg support for mt8183 SCP.") Signed-off-by: AngeloGioacchino Del Regno --- drivers/rpmsg/mtk_rpmsg.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/rpmsg/mtk_rpmsg.c b/drivers/rpmsg/mtk_rpmsg.c index 5b4404b8be4c..d1213c33da20 100644 --- a/drivers/rpmsg/mtk_rpmsg.c +++ b/drivers/rpmsg/mtk_rpmsg.c @@ -234,7 +234,9 @@ static void mtk_register_device_work_function(struct work_struct *register_work) if (info->registered) continue; + mutex_unlock(&subdev->channels_lock); ret = mtk_rpmsg_register_device(subdev, &info->info); + mutex_lock(&subdev->channels_lock); if (ret) { dev_err(&pdev->dev, "Can't create rpmsg_device\n"); continue; -- 2.33.1