Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp786445pxb; Thu, 17 Feb 2022 14:56:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJwrH/hC0bSOpG6WYeag6tPwk2Ey8prVbkYiYPJjNnMc/29xwN9L8ahe7776MQVLckKb/FuE X-Received: by 2002:a63:3487:0:b0:373:4c14:59b1 with SMTP id b129-20020a633487000000b003734c1459b1mr4157489pga.68.1645138608328; Thu, 17 Feb 2022 14:56:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645138608; cv=none; d=google.com; s=arc-20160816; b=FuSAUP3sh5Sy0Hxw6BfGBHyNkTqKiJKPrKNdgeQPy9h9EE0VPfyCsQRJx5aFm1CX59 Z3Hqp3VHFme3dbOCO7PSUvxm/s5O8/JijkmNCxmOoRz+4hsKQZ864bZTxefy2nhEXQwb v/A0CN7qy34r0FBhGtLJCbzEiR5/r8Xi2wVP7ZirWNrk2zTdyCx6czxdpNhnQEg4xfsx AMaDTt6zkzRHIDi0zuhosLFOU9eiQp2I7rN91ASXL2f5jfQyXg+e0dPRli0LO9JZrCu0 mR73R5lG4KXuDNaCCKs4LNbyTpPsK+ozoTot0Gxb4mZ3p/HuR03IfuQJIBADfOkX89CF Nxrg== 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:message-id:subject:cc:to:from:date:dkim-signature; bh=VD8H9XEccLJ1gEJ8HFd5QAYd/aMwLkrTq6BJhjDSisU=; b=y7u59hleF7rSpNY/j0sCm9KR5LX9zlPrzLwfNBLPhYaBPsVcNKG04J6UklTInV1UbG tLYf2xZcL9JopMXV9egAdCjbq24UmU2K8QaF3rdJznLh56H5sstClWtoBBGZLsnUoIg5 JJyanr4DO0RRFXvky4fUfwWTTYp2IBSTHDu/wM8Nj0Dt8wjNtTxXIvbtAFaX+m29dpYr +BBLn7KosAf9zmRPG1IB4por4nxjL8mE84I3e+Tjk6KdLOTCH0gy6EwltjZAbS5uIAIW weHrbrfAx2HOKcxQrCtRj+ydppROMgGZ1ihnU+fYmizDdfRZ4Qg+kfGDE7KKnBbPt/Tc NJsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=F2rnoQOU; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id q20si10415755pgt.761.2022.02.17.14.56.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Feb 2022 14:56:48 -0800 (PST) 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=@linaro.org header.s=google header.b=F2rnoQOU; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1EDBB275AC4; Thu, 17 Feb 2022 14:55:58 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236505AbiBQQJN (ORCPT + 99 others); Thu, 17 Feb 2022 11:09:13 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:50342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229447AbiBQQJK (ORCPT ); Thu, 17 Feb 2022 11:09:10 -0500 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0491178BC1 for ; Thu, 17 Feb 2022 08:08:55 -0800 (PST) Received: by mail-pl1-x636.google.com with SMTP id y18so4937530plb.11 for ; Thu, 17 Feb 2022 08:08:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=VD8H9XEccLJ1gEJ8HFd5QAYd/aMwLkrTq6BJhjDSisU=; b=F2rnoQOUj5vrdaK05HWLiQ7Dayy2FS/VLwwppCjteGUtmVGphPSPL1yNlR/PsVhO4Q SGeRoVRv5Uus+p4dn8QbXAGf80LP4h24IJAa0YKQc/bBrJA2mgvX6k6S+QaZhSinsQPe o216cTDDHjXReLeUyM4oLkcXFtL1l/32drgLI8Q3Ol851JV0AFiUSkZYV96ZmH6yoaRz AKOTAqvSoj03fN1c6IOu25o9+GmlKYmh8Tz/z/Z1zg3CfaJqHt1e0AWkINesw/Pf2V0l g76JZRFDHXvhz1CCgn1/99do97O3lEyvZTQa1XyJAFrLSbwg3bv9oVKn+Ugr30Tfha1B 919w== 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:references :mime-version:content-disposition:in-reply-to; bh=VD8H9XEccLJ1gEJ8HFd5QAYd/aMwLkrTq6BJhjDSisU=; b=AeNas6HpI7/8Ol9jzD8NRE9EfERTGfZgKyGebecNqQaM4Q8KE2kQM66vzx3INMCNqk yby76lwD7DpOmbefErTqV4vvVTNSJ6XXWCiT21FqawklnGJ3PmYbET/Qwf/o4OLK+VNR ZiYi7p5m2Av6DP4l7Pm272C8z7/wya0h1RFD8DOS9hXmlgcqnZQjzqINDpw00YNyXGBh IRDfiCAKPmSjz/P74hRD9Z33k9ZUu7JjG+w19N5lNclGq9eOcWzS7YgRmHjg4orlLgN2 Phzzvu3Ltjce0PBnFUxDsiRSFpRKI6s88T3UMwhH5DJ79mh7YbFk23NaCGaVrYbr7cMK V1PA== X-Gm-Message-State: AOAM533uM9Uek4MnatfVHpQLFKSqRHtNae8L5M9UTVd+f8E3/7NlT0BL w6viVEPyEPNJMwXBF1+XTrTF/iUu7OKmaA== X-Received: by 2002:a17:90a:4dc7:b0:1b9:ca2:311e with SMTP id r7-20020a17090a4dc700b001b90ca2311emr3717927pjl.175.1645114135171; Thu, 17 Feb 2022 08:08:55 -0800 (PST) Received: from p14s (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id h9sm51611pfv.135.2022.02.17.08.08.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Feb 2022 08:08:53 -0800 (PST) Date: Thu, 17 Feb 2022 09:08:51 -0700 From: Mathieu Poirier To: AngeloGioacchino Del Regno Cc: bjorn.andersson@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 Subject: Re: [PATCH] rpmsg: mtk_rpmsg: Fix circular locking dependency Message-ID: <20220217160851.GA474184@p14s> References: <20220114144737.375621-1-angelogioacchino.delregno@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 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, Feb 16, 2022 at 05:06:22PM +0100, AngeloGioacchino Del Regno wrote: > Il 14/01/22 15:47, AngeloGioacchino Del Regno ha scritto: > > 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 > > Friendly ping for an important fix... :) > This seems to have slipped through the cracks... I will take a look later today. Thanks, Mathieu > > --- > > 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; > >