mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Frank Li <Frank.li@oss.nxp.com>
To: Rosen Penev <rosenp@gmail.com>
Cc: dmaengine@vger.kernel.org, Vinod Koul <vkoul@kernel.org>,
	Frank Li <Frank.Li@kernel.org>, Stefan Roese <sr@denx.de>,
	open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCHv2] dmaengine: mv_xor: protect MBUS window access with a spinlock
Date: Tue, 20 Oct 2026 17:32:21 -0400	[thread overview]
Message-ID: <atfd5TfQKFlJLSqv@lizhi-Precision-Tower-5810> (raw)
In-Reply-To: <20260917232702.127923-1-rosenp@gmail.com>

On Thu, Sep 17, 2026 at 04:27:02PM -0700, Rosen Penev wrote:
> mv_xor_add_io_win() reads and writes shared MBUS window registers
> and updates the shared win_start/win_end arrays in mv_xor_device.
> Multiple DMA channels can call this function concurrently via
> mv_xor_prep_dma_xor(), leading to races where two threads can
> select the same free window slot, corrupt the registers, or produce
> inconsistent cached state.
>
> Add a spinlock to struct mv_xor_device and hold it across the
> register read-modify-write and cache update in mv_xor_add_io_win().
>
> Fixes: 77ff7a706f01 ("mv_xor: Add support for IO (PCIe) src/dst areas")
> Assisted-by: opencode:big-pickle
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
>  v2: use guard()
>  drivers/dma/mv_xor.c | 3 +++
>  drivers/dma/mv_xor.h | 1 +
>  2 files changed, 4 insertions(+)
>
> diff --git a/drivers/dma/mv_xor.c b/drivers/dma/mv_xor.c
> index c4e0dce3ca64..da8eea8789ae 100644
> --- a/drivers/dma/mv_xor.c
> +++ b/drivers/dma/mv_xor.c
> @@ -494,6 +494,8 @@ static int mv_xor_add_io_win(struct mv_xor_chan *mv_chan, u32 addr)
>  	if (xordev->xor_type == XOR_ARMADA_37XX)
>  		return 0;
>
> +	guard(spinlock_irqsave)(&xordev->win_lock);
> +
>  	/*
>  	 * Loop over the cached windows to check, if the requested area
>  	 * is already mapped. If this the case, nothing needs to be done
> @@ -1345,6 +1347,7 @@ static int mv_xor_probe(struct platform_device *pdev)
>
>  	platform_set_drvdata(pdev, xordev);
>
> +	spin_lock_init(&xordev->win_lock);
>
>  	/*
>  	 * We need to know which type of XOR device we use before
> diff --git a/drivers/dma/mv_xor.h b/drivers/dma/mv_xor.h
> index c87cefd38a07..034db4d0bfb1 100644
> --- a/drivers/dma/mv_xor.h
> +++ b/drivers/dma/mv_xor.h
> @@ -80,6 +80,7 @@ struct mv_xor_device {
>  	struct clk	     *clk;
>  	struct mv_xor_chan   *channels[MV_XOR_MAX_CHANNELS];
>  	int		     xor_type;
> +	spinlock_t	     win_lock;

check patch require all lock have comments for it.

Frank

>
>  	u32                  win_start[WINDOW_COUNT];
>  	u32                  win_end[WINDOW_COUNT];
> --
> 2.55.0
>

      reply	other threads:[~2026-10-20 21:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-17 23:27 Rosen Penev
2026-10-20 21:32 ` Frank Li [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=atfd5TfQKFlJLSqv@lizhi-Precision-Tower-5810 \
    --to=frank.li@oss.nxp.com \
    --cc=Frank.Li@kernel.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rosenp@gmail.com \
    --cc=sr@denx.de \
    --cc=vkoul@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

all inboxes | Powered by JetHome®