From nobody Thu Apr 9 19:00:50 2026 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A6FAC26B755 for ; Fri, 6 Mar 2026 12:41:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772800901; cv=none; b=WUgEJ/zqbWuR/lwWEEIGLJeieHsDTHuG7xU6OK+TM1uQerJhC0tqoF1jxboL/3FpuDRr7IbNyaCznuoT2fo8HAF36SABDDI9uG6qpV0hjCn1Rwupsui+sb5PVBT+uycbj6+yWwAwObx8U7LGVRMFBUODxcGRhXUCVrZKZ3/1GWY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772800901; c=relaxed/simple; bh=RN3Xvj39V/yKMYYPWCiHYcUQb1LTVs8M5GbjU78OU3c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tsBMOsFvU8nqDLCgSwSVBZiuAhzLfSpgEXRJ9YnUmv2H7xQNrHzWSfOdDpBmWvyAS3nojNiI/SB679px+rJ463PahLhrMlKJUeJSeS9rl77fKzyJ4Aly9ZEdiSZTeeTGFfFM9ljEghcRbfhi5FA0VXecESNNfmM9bHDgHs3+aD4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=RVWOeo7C; arc=none smtp.client-ip=209.85.221.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="RVWOeo7C" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-439c9eb5d36so2733762f8f.2 for ; Fri, 06 Mar 2026 04:41:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1772800898; x=1773405698; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JtXHbNPdEBg9KTwTT66W1+1GRh4EUiwex5QWGP93Nrc=; b=RVWOeo7CE058x4pBoPeHmEvS293hHs+QKwqnHkENZwvtidN7/KMhlnwHt+mGd/VQ5Q X5lbP7fQ/fGFjRfM0PifMT/Hz3kxtjMiNXwOoJMam4H9MIduxKGUkTOFdObcOt/AMKWV HsSN8lFae/NrXks2R0u+txhrnl6gVoFcJ4w0vjFP+sVubZ+ZgOb6ijVoF+c+Nz2bWtxo 2AzAsaf1D7i6cBB0FzTYW7LCyR7LXIjZKQqYFyxNWLFZJI8G9qy20xEMo36VMQ/aDIMW WCe3qOaLmdEZj6nbzb3EZFo/8Nem5z6/mKWi06TzHE/Cg1n1+NYWydTVeoqIjSWgB9iR vRJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772800898; x=1773405698; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=JtXHbNPdEBg9KTwTT66W1+1GRh4EUiwex5QWGP93Nrc=; b=ob7zTWVScjN5IeWoOArWDhd8RPbXgvlh7gZ88lzJJKcobWDA71X8poQYSsgs+u6n/K GgwoVoaF/sDKnspniXlDbXKXkY+HdLzba5Ud6iQ0E+Hqs790hE7xrNCDLfkqKQRi4xEf Vza61sEMJQb/MsmAwqV4Dn7qOLfDu09GQrMm3QfrAS3MEwN5hhmrN9MdPSCw0WdrHPLW MnZI5DQK1clrNi0R76F/KYCaY512xYx974v1yXXf5KRqNDtA2GN+MYhGWktY6zm0ti8c EfYAQvLJbn3wKqw+M77TyjMj7KYBS5IWTQ3+c2mQoyBJtiQ1CLkw8RTgbEYdVaa/SJlP rrAw== X-Forwarded-Encrypted: i=1; AJvYcCVhlK+UXc15apgl910GMJtWrZolipMi3ov4fz4Kf0ZXcWasw/+AOSE/X98SICEj1GFXFO/sT8mYbz4f9wU=@vger.kernel.org X-Gm-Message-State: AOJu0Yw60RKqyCg66gsjyGDO/0BNnLHmpnwOAQ8e0oB8U7FVuHB4Ivpn tUY7i4kPoDo5ZzJLHa1/25INr2719Q+GOZdtPgXJia6EL+DdftEB0ChAl9r3OFfFNJE= X-Gm-Gg: ATEYQzyDSR/v96e2UiEvapdvmd4BsXHaZSvmmrmR2u6tRlYByXAf683qk3jhGfxRy12 g6es4QJZa/GPcgEqBPREXrUNWSwM8QrCDY2spSRbUgOvRta3/k//hxqmgWbd8Sf/8FQx73hdm1Z 1RVxrnBayIORv0lKHr3BFGHaQbZfqHhWH43VUwOHDtA6IKyMdx3mu9WmS/C+TuoZtwv0P8ubdxF 1LzaSQCz23dxbxADIfTjEXD9jGwpkPX/7u9oAeaZLRcMpisgLpe3FenYQpbvJn9fV2Ay26V9ZhX RUl2UvXra1xqVAxMX757Cb0HsECI7DHo6KwcQ0xl5f2QtFbnf6FH7ZLc7Wn/wDjqoOe/yCIMb4U EKJYJELwbd5yT9Vh2giKsRGnGWIP1gQrLMlRnHWITTGgbkmendgYu5k903jwUU/Y2qAppy2xuRK CguBq29dNd4tREmQKGCZ/Hkz6h/sVGlJypRNnpzB5za2aWJnKjav51 X-Received: by 2002:a05:600c:a086:b0:483:75f1:54f with SMTP id 5b1f17b1804b1-48526982991mr30474875e9.31.1772800898064; Fri, 06 Mar 2026 04:41:38 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.134]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-485276b0c38sm38150505e9.9.2026.03.06.04.41.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Mar 2026 04:41:37 -0800 (PST) From: Claudiu X-Google-Original-From: Claudiu To: vkoul@kernel.org, Frank.Li@kernel.org, biju.das.jz@bp.renesas.com, geert+renesas@glider.be, fabrizio.castro.jz@renesas.com, prabhakar.mahadev-lad.rj@bp.renesas.com Cc: claudiu.beznea@tuxon.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, Claudiu Beznea , stable@vger.kernel.org, Frank Li Subject: [PATCH v9 1/8] dmaengine: sh: rz-dmac: Protect the driver specific lists Date: Fri, 6 Mar 2026 14:41:26 +0200 Message-ID: <20260306124133.2304687-2-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260306124133.2304687-1-claudiu.beznea.uj@bp.renesas.com> References: <20260306124133.2304687-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea The driver lists (ld_free, ld_queue) are used in rz_dmac_free_chan_resources(), rz_dmac_terminate_all(), rz_dmac_issue_pending(), and rz_dmac_irq_handler_thread(), all under the virtual channel lock. Take the same lock in rz_dmac_prep_slave_sg() and rz_dmac_prep_dma_memcpy() as well to avoid concurrency issues, since these functions also check whether the lists are empty and update or remove list entries. Fixes: 5000d37042a6 ("dmaengine: sh: Add DMAC driver for RZ/G2L SoC") Cc: stable@vger.kernel.org Reviewed-by: Frank Li Signed-off-by: Claudiu Beznea --- Changes in v9: - collected tags Changes in v8: - none Changes in v7: - none Changes in v6: - none Changes in v5: - none, this patch is new drivers/dma/sh/rz-dmac.c | 57 ++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index d84ca551b2bf..089e1ab29159 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -10,6 +10,7 @@ */ =20 #include +#include #include #include #include @@ -447,6 +448,7 @@ static int rz_dmac_alloc_chan_resources(struct dma_chan= *chan) if (!desc) break; =20 + /* No need to lock. This is called only for the 1st client. */ list_add_tail(&desc->node, &channel->ld_free); channel->descs_allocated++; } @@ -502,18 +504,21 @@ rz_dmac_prep_dma_memcpy(struct dma_chan *chan, dma_ad= dr_t dest, dma_addr_t src, dev_dbg(dmac->dev, "%s channel: %d src=3D0x%pad dst=3D0x%pad len=3D%zu\n", __func__, channel->index, &src, &dest, len); =20 - if (list_empty(&channel->ld_free)) - return NULL; + scoped_guard(spinlock_irqsave, &channel->vc.lock) { + if (list_empty(&channel->ld_free)) + return NULL; + + desc =3D list_first_entry(&channel->ld_free, struct rz_dmac_desc, node); =20 - desc =3D list_first_entry(&channel->ld_free, struct rz_dmac_desc, node); + desc->type =3D RZ_DMAC_DESC_MEMCPY; + desc->src =3D src; + desc->dest =3D dest; + desc->len =3D len; + desc->direction =3D DMA_MEM_TO_MEM; =20 - desc->type =3D RZ_DMAC_DESC_MEMCPY; - desc->src =3D src; - desc->dest =3D dest; - desc->len =3D len; - desc->direction =3D DMA_MEM_TO_MEM; + list_move_tail(channel->ld_free.next, &channel->ld_queue); + } =20 - list_move_tail(channel->ld_free.next, &channel->ld_queue); return vchan_tx_prep(&channel->vc, &desc->vd, flags); } =20 @@ -529,27 +534,29 @@ rz_dmac_prep_slave_sg(struct dma_chan *chan, struct s= catterlist *sgl, int dma_length =3D 0; int i =3D 0; =20 - if (list_empty(&channel->ld_free)) - return NULL; + scoped_guard(spinlock_irqsave, &channel->vc.lock) { + if (list_empty(&channel->ld_free)) + return NULL; =20 - desc =3D list_first_entry(&channel->ld_free, struct rz_dmac_desc, node); + desc =3D list_first_entry(&channel->ld_free, struct rz_dmac_desc, node); =20 - for_each_sg(sgl, sg, sg_len, i) { - dma_length +=3D sg_dma_len(sg); - } + for_each_sg(sgl, sg, sg_len, i) + dma_length +=3D sg_dma_len(sg); =20 - desc->type =3D RZ_DMAC_DESC_SLAVE_SG; - desc->sg =3D sgl; - desc->sgcount =3D sg_len; - desc->len =3D dma_length; - desc->direction =3D direction; + desc->type =3D RZ_DMAC_DESC_SLAVE_SG; + desc->sg =3D sgl; + desc->sgcount =3D sg_len; + desc->len =3D dma_length; + desc->direction =3D direction; =20 - if (direction =3D=3D DMA_DEV_TO_MEM) - desc->src =3D channel->src_per_address; - else - desc->dest =3D channel->dst_per_address; + if (direction =3D=3D DMA_DEV_TO_MEM) + desc->src =3D channel->src_per_address; + else + desc->dest =3D channel->dst_per_address; + + list_move_tail(channel->ld_free.next, &channel->ld_queue); + } =20 - list_move_tail(channel->ld_free.next, &channel->ld_queue); return vchan_tx_prep(&channel->vc, &desc->vd, flags); } =20 --=20 2.43.0