From nobody Tue Feb 10 22:18:06 2026 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 403B437A3C5 for ; Wed, 17 Dec 2025 13:52:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765979553; cv=none; b=XikBiu8Aw+OI23QOcRGRh1qeJ/wgruNfVJQtWYrWTt15JHhGEhMLzOa85Ue/CxkRveuEVGHiSB+6NJzFUxEq8V/ODzWudhXeA5AquHGMvRjI0R4mT8xVcScvuDNhlvwpT1iPvfavv1ggEIJ7/O+LurjiafR4WQHgl/XDhZD9Xn8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765979553; c=relaxed/simple; bh=wu45FRjAX5rr5XwRhmViBxUJ1/TuJ66eIVeI/gV2slw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eGhfz5kkTPCnpDVVRENIZDtoaU7AY92Pt5T5rLMcHBLSOTEGrqrBUOCvY/zCkY+iTbwa3Je1fieTShnxopdXcZiPzs7WPQoYrr27m1lFfPgNSp3lq/GNAj4JgoZ/gVL//dyx+2MCqJXixbmr9FVcZD6xDUgcq3p0faznggcpZyY= 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=PJNOqyrK; arc=none smtp.client-ip=209.85.128.49 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="PJNOqyrK" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-4775ae77516so68638805e9.1 for ; Wed, 17 Dec 2025 05:52:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1765979547; x=1766584347; 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=1dmhSbGa11aoCwa2QR/4pZlPF5BdvQSf+YWgIGdjTtY=; b=PJNOqyrKYpSL6m+VlK/lFhP2/JrwSDRhD+pFYQsPgufCOYbK3FuIgXVlu+Z5vHqzik 3awWcliwdqnCqnilf7nhlGmkVhvktoIMVUwIvrVC1DjYh+8SGXInBoOnX1weillXIpSX uGvRXrWLteFW6Rs1ZjfRFQQUc2egSHJxmbufv8o+BXfl6HeLaSI0BKYIBjxPny5R4ON/ UjJg+FMp4AM+u83bMBNi5eBWjUJw6cCn83DYyen7pMNGt/AMSk5sH9wpisGcoahqTacC mgqNjKzKWNZH5fVWcjR0saG2ZPciQfZWF3R0JcsHrVqLQzeython6hKS+hlxFw9Qp4Uy +CvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765979547; x=1766584347; 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=1dmhSbGa11aoCwa2QR/4pZlPF5BdvQSf+YWgIGdjTtY=; b=rOCaSj7bGYS3y8cWfw8jcOc5DXzJLPx7/BJgHFiJGLUzHslzLChleJCw4EH3Ww7zDI 07dMgV7F28B4rV6hPcl+wZDwNQMvOwNZeOiBMHU5RmB32QTSQTzGlAkU0gbeXjyIc3HR D+rvFbn1paigsm9L1c9wK3RQsAQaVgT0Y3wBaUPGN00H5ZHABe/r0A4+m/PUG+TwRj5Z UPuHc9cs2tq2FnM1Ej0Erv4jhVWPhWdW6X/8ChPxAyzvKDiqS1TiewxUp5FJ4MOdrb76 /ZoxnXTLwy2gpCaRxOa3horiGi2iaR5JC1f7zkNtRk7ZXegggs6fF774Kj2kSIH3yjqH pO/Q== X-Forwarded-Encrypted: i=1; AJvYcCUnQ68S2stJkcmvl8VqG/Ye+EAuKOxU8IS1lYUzcRCph2QdH1dPx/Vddi3HtPddQvB10kT+hto7imL9kB0=@vger.kernel.org X-Gm-Message-State: AOJu0YxyToVP2PBI9OmJ7bG1uVJFEU7EbwV1vk0SdLoCBfBQf5hKpnyn x+yqap7E7Qk+bq7jME707+/+dkMOpnPl5stLXjaCGKrDNC4x976Z7Qd+5VIMTlnwWtE= X-Gm-Gg: AY/fxX7EG0UyIMPBpiAUieq2anQcT2VSPZEBlnhTF1gWa9deEsDP0IpbMXYB+dF+ue5 NrAzt+HxESdUZg9jkHZfRUaIWv8rTZtEI0lIDbfJAeiVwVwxVrIV9gURDO79D6EGKLGAajEpEQk 18Gaju+u2B2/bgV1cAYrMkfTviNh2f07I0JIopYY3Aiq90q92hsjR6kDOEkkEk3FgT/kiHyf3ab U22wpMuNxJb+0zV9qx5fPfqdPTSJgpQksPw517OSMMdHxoI3qAIQZ+UwlPoJfyoMnoXcVC1yBhI aZDr4hqcGhW3Y3wgBKeqlBZdhDTN390vNjzAolf0fIA+COL4NHkF6rv2UBa/SlZoGJclDIMRox3 MssJDbu+Inw7HyFhg/0peyJcMXJk1bMeLjAE1Q/QVzpdK6Ny59xY0d7j/nKtNVrBI7+QpcOxurB EiUn87N7lL/X/llymxdafx6S9PNqwlUEyQxVBHerbUWGFbhJq49jM= X-Google-Smtp-Source: AGHT+IFjWbNp9ucqit01hx4uiVylzLOMEnMuaieIZHHMFtzLDbezGqZEhZIONXkeIMCVRRvem4vK/A== X-Received: by 2002:a05:600c:444b:b0:477:9b4a:a82 with SMTP id 5b1f17b1804b1-47a8f91561cmr176856225e9.35.1765979546692; Wed, 17 Dec 2025 05:52:26 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.134]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4310adf701csm4508000f8f.42.2025.12.17.05.52.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Dec 2025 05:52:26 -0800 (PST) From: Claudiu X-Google-Original-From: Claudiu To: vkoul@kernel.org, fabrizio.castro.jz@renesas.com, biju.das.jz@bp.renesas.com, geert+renesas@glider.be, 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 Subject: [PATCH v5 1/6] dmaengine: sh: rz-dmac: Protect the driver specific lists Date: Wed, 17 Dec 2025 15:52:08 +0200 Message-ID: <20251217135213.400280-2-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251217135213.400280-1-claudiu.beznea.uj@bp.renesas.com> References: <20251217135213.400280-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 Signed-off-by: Claudiu Beznea --- 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 9e5f088355e2..c8e3d9f77b8a 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 @@ -448,6 +449,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++; } @@ -503,18 +505,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 @@ -530,27 +535,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