Linux Tegra architecture development
 help / color / mirror / Atom feed
From: Thierry Reding <thierry.reding@kernel.org>
To: jaidevshastri@vt.edu
Cc: Jonathan Hunter <jonathanh@nvidia.com>,
	linux-tegra@vger.kernel.org,  linux-kernel@vger.kernel.org
Subject: Re: [PATCH] soc: tegra: cbb: walk cbb_list under cbb_lock in the debugfs path
Date: Tue, 22 Sep 2026 12:37:33 +0200	[thread overview]
Message-ID: <arJU0GNEZaDa7HrU@orome> (raw)
In-Reply-To: <20260921-mb-tegra-cbb-v1-1-67aa3712aa4b@vt.edu>

[-- Attachment #1: Type: text/plain, Size: 2729 bytes --]

On Mon, Sep 21, 2026 at 09:08:41PM -0400, Jaidev Shastri via B4 Relay wrote:
> From: Jaidev Shastri <jaidevshastri@vt.edu>
> 
> tegra194_cbb_probe() and tegra194_cbb_remove() add and remove cbb_list
> entries under cbb_lock, and the error interrupt handler walks the list
> under the same lock. tegra194_cbb_debugfs_show() walks it holding only
> cbb_err_mutex, which the writers never take.
> 
> A debugfs read of one CBB instance can therefore run while another
> instance is probed or removed. list_add() publishes the node with a
> plain store, so the walker can see a node before its links and private
> data are visible, or step onto a node that remove is freeing.
> 
> Take cbb_lock around the walk. cbb_err_mutex keeps its existing job of
> serialising the error log output.
> 
> Found with MBCheck, a static herd7-based memory consistency checker.
> 
> Signed-off-by: Jaidev Shastri <jaidevshastri@vt.edu>
> ---
>  drivers/soc/tegra/cbb/tegra194-cbb.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/drivers/soc/tegra/cbb/tegra194-cbb.c b/drivers/soc/tegra/cbb/tegra194-cbb.c
> index 69ef929e0..d1a80b0b5 100644
> --- a/drivers/soc/tegra/cbb/tegra194-cbb.c
> +++ b/drivers/soc/tegra/cbb/tegra194-cbb.c
> @@ -1990,9 +1990,16 @@ static DEFINE_MUTEX(cbb_err_mutex);
>  static int tegra194_cbb_debugfs_show(struct tegra_cbb *cbb, struct seq_file *file, void *data)
>  {
>  	struct tegra_cbb *noc;
> +	unsigned long flags;
>  
>  	mutex_lock(&cbb_err_mutex);
>  
> +	/*
> +	 * cbb_list is modified under cbb_lock by the probe and remove paths of
> +	 * the other CBB instances; cbb_err_mutex alone does not exclude them.
> +	 */
> +	spin_lock_irqsave(&cbb_lock, flags);
> +
>  	list_for_each_entry(noc, &cbb_list, node) {
>  		struct tegra194_cbb *priv = to_tegra194_cbb(noc);
>  		u32 status;
> @@ -2002,6 +2009,8 @@ static int tegra194_cbb_debugfs_show(struct tegra_cbb *cbb, struct seq_file *fil
>  			print_errlog(file, priv, status);
>  	}
>  
> +	spin_unlock_irqrestore(&cbb_lock, flags);
> +
>  	mutex_unlock(&cbb_err_mutex);

cbb_err_mutex no longer serves any purpose (though, honestly, it never
really did), so it can be removed entirely.

There's a slight issue with this patch, though it also previously
existed already (partially). print_errlog() ends up calling the
tegra_cbb_print_err(), which in turn is quite slow when it goes out to
the debug serial. On the other hand, we can't use a mutex for the dumps
during the interrupt handling.

Probably best to get rid of the mutex for now since it's obviously not
needed and maybe revisit this at some point to get rid of the spin lock
around the slow UART operations.

Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

      reply	other threads:[~2026-09-22 10:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-22  1:08 [PATCH] soc: tegra: cbb: walk cbb_list under cbb_lock in the debugfs path Jaidev Shastri via B4 Relay
2026-09-22 10:37 ` Thierry Reding [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=arJU0GNEZaDa7HrU@orome \
    --to=thierry.reding@kernel.org \
    --cc=jaidevshastri@vt.edu \
    --cc=jonathanh@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox