public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3 v5.4.y] dmaengine: ti: edma: Add support for handling reserved channels
@ 2025-04-16  6:43 Hardik Gohil
  2025-04-16 14:17 ` Sasha Levin
  2025-04-22 13:32 ` Greg KH
  0 siblings, 2 replies; 21+ messages in thread
From: Hardik Gohil @ 2025-04-16  6:43 UTC (permalink / raw)
  To: stable; +Cc: Peter Ujfalusi, Vinod Koul, Hardik Gohil

From: Peter Ujfalusi <peter.ujfalusi@ti.com>

Like paRAM slots, channels could be used by other cores and in this case
we need to make sure that the driver do not alter these channels.

Handle the generic dma-channel-mask property to mark channels in a bitmap
which can not be used by Linux and convert the legacy rsv_chans if it is
provided by platform_data.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
Link: https://lore.kernel.org/r/20191025073056.25450-4-peter.ujfalusi@ti.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Hardik Gohil <hgohil@mvista.com>
---
The patch [dmaengine: ti: edma: Add some null pointer checks to the edma_probe] fix for CVE-2024-26771                                   needs to be backported to v5.4.y kernel.

patch 2/3 
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=v5.10.235&id=2a03c1314506557277829562dd2ec5c11a6ea914 
patch 3/3
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=linux-5.10.y&id=c432094aa7c9970f2fa10d2305d550d3810657ce

patch 2 and 3 are cleanly applicable to v5.4.y, build test was sucessful.

 drivers/dma/ti/edma.c | 59 ++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 53 insertions(+), 6 deletions(-)

diff --git a/drivers/dma/ti/edma.c b/drivers/dma/ti/edma.c
index 01089e5c565f..47423bbd7bc7 100644
--- a/drivers/dma/ti/edma.c
+++ b/drivers/dma/ti/edma.c
@@ -259,6 +259,13 @@ struct edma_cc {
 	 */
 	unsigned long *slot_inuse;
 
+	/*
+	 * For tracking reserved channels used by DSP.
+	 * If the bit is cleared, the channel is allocated to be used by DSP
+	 * and Linux must not touch it.
+	 */
+	unsigned long *channels_mask;
+
 	struct dma_device		dma_slave;
 	struct dma_device		*dma_memcpy;
 	struct edma_chan		*slave_chans;
@@ -715,6 +722,12 @@ static int edma_alloc_channel(struct edma_chan *echan,
 	struct edma_cc *ecc = echan->ecc;
 	int channel = EDMA_CHAN_SLOT(echan->ch_num);
 
+	if (!test_bit(echan->ch_num, ecc->channels_mask)) {
+		dev_err(ecc->dev, "Channel%d is reserved, can not be used!\n",
+			echan->ch_num);
+		return -EINVAL;
+	}
+
 	/* ensure access through shadow region 0 */
 	edma_or_array2(ecc, EDMA_DRAE, 0, EDMA_REG_ARRAY_INDEX(channel),
 		       EDMA_CHANNEL_BIT(channel));
@@ -2249,7 +2262,7 @@ static int edma_probe(struct platform_device *pdev)
 	struct edma_soc_info	*info = pdev->dev.platform_data;
 	s8			(*queue_priority_mapping)[2];
 	int			i, off;
-	const s16		(*rsv_slots)[2];
+	const s16               (*reserved)[2];
 	const s16		(*xbar_chans)[2];
 	int			irq;
 	char			*irq_name;
@@ -2330,15 +2343,32 @@ static int edma_probe(struct platform_device *pdev)
 	if (!ecc->slot_inuse)
 		return -ENOMEM;
 
+	ecc->channels_mask = devm_kcalloc(dev,
+					   BITS_TO_LONGS(ecc->num_channels),
+					   sizeof(unsigned long), GFP_KERNEL);
+	if (!ecc->channels_mask)
+		return -ENOMEM;
+
+	/* Mark all channels available initially */
+	bitmap_fill(ecc->channels_mask, ecc->num_channels);
+
 	ecc->default_queue = info->default_queue;
 
 	if (info->rsv) {
 		/* Set the reserved slots in inuse list */
-		rsv_slots = info->rsv->rsv_slots;
-		if (rsv_slots) {
-			for (i = 0; rsv_slots[i][0] != -1; i++)
-				bitmap_set(ecc->slot_inuse, rsv_slots[i][0],
-					   rsv_slots[i][1]);
+		reserved = info->rsv->rsv_slots;
+		if (reserved) {
+			for (i = 0; reserved[i][0] != -1; i++)
+				bitmap_set(ecc->slot_inuse, reserved[i][0],
+					   reserved[i][1]);
+		}
+
+		/* Clear channels not usable for Linux */
+		reserved = info->rsv->rsv_chans;
+		if (reserved) {
+			for (i = 0; reserved[i][0] != -1; i++)
+				bitmap_clear(ecc->channels_mask, reserved[i][0],
+					     reserved[i][1]);
 		}
 	}
 
@@ -2398,6 +2428,7 @@ static int edma_probe(struct platform_device *pdev)
 
 	if (!ecc->legacy_mode) {
 		int lowest_priority = 0;
+		unsigned int array_max;
 		struct of_phandle_args tc_args;
 
 		ecc->tc_list = devm_kcalloc(dev, ecc->num_tc,
@@ -2421,6 +2452,18 @@ static int edma_probe(struct platform_device *pdev)
 			}
 			of_node_put(tc_args.np);
 		}
+
+		/* See if we have optional dma-channel-mask array */
+		array_max = DIV_ROUND_UP(ecc->num_channels, BITS_PER_TYPE(u32));
+		ret = of_property_read_variable_u32_array(node,
+						"dma-channel-mask",
+						(u32 *)ecc->channels_mask,
+						1, array_max);
+		if (ret > 0 && ret != array_max)
+			dev_warn(dev, "dma-channel-mask is not complete.\n");
+		else if (ret == -EOVERFLOW || ret == -ENODATA)
+			dev_warn(dev,
+				 "dma-channel-mask is out of range or empty\n");
 	}
 
 	/* Event queue priority mapping */
@@ -2438,6 +2481,10 @@ static int edma_probe(struct platform_device *pdev)
 	edma_dma_init(ecc, legacy_mode);
 
 	for (i = 0; i < ecc->num_channels; i++) {
+		/* Do not touch reserved channels */
+		if (!test_bit(i, ecc->channels_mask))
+			continue;
+
 		/* Assign all channels to the default queue */
 		edma_assign_channel_eventq(&ecc->slave_chans[i],
 					   info->default_queue);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2025-04-25  8:24 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-16  6:43 [PATCH 1/3 v5.4.y] dmaengine: ti: edma: Add support for handling reserved channels Hardik Gohil
2025-04-16 14:17 ` Sasha Levin
2025-04-22 13:32 ` Greg KH
     [not found]   ` <CAH+zgeHyLBNMz=kWw0xbfKfw2Fy6BtbWZAub6w_cTsAhNEsxSw@mail.gmail.com>
2025-04-22 14:10     ` Hardik Gohil
2025-04-22 14:11     ` Greg KH
2025-04-22 15:17       ` [PATCH 2/3 v5.4.y] dmaengine: ti: edma: add missed operations Hardik Gohil
2025-04-22 15:17         ` [PATCH 3/3 v5.4.y] dmaengine: ti: edma: Add some null pointer checks to the edma_probe Hardik Gohil
2025-04-22 16:15           ` Greg KH
2025-04-23 10:00             ` Hardik Gohil
2025-04-23 11:07               ` Greg KH
2025-04-24  6:06                 ` [PATCH 2/3 v5.4.y] dmaengine: ti: edma: add missed operations Hardik Gohil
2025-04-24  6:06                   ` [PATCH 3/3 v5.4.y] dmaengine: ti: edma: Add some null pointer checks to the edma_probe Hardik Gohil
2025-04-24 23:22                     ` Sasha Levin
2025-04-24 23:22                   ` [PATCH 2/3 v5.4.y] dmaengine: ti: edma: add missed operations Sasha Levin
2025-04-25  8:11                   ` Greg KH
2025-04-24  6:08                 ` [PATCH 1/3 v5.4.y] dmaengine: ti: edma: Add support for handling reserved channels Hardik Gohil
2025-04-25  1:14                   ` Sasha Levin
2025-04-25  8:10                   ` Greg KH
2025-04-25  8:24                     ` Greg KH
2025-04-22 16:14         ` [PATCH 2/3 v5.4.y] dmaengine: ti: edma: add missed operations Greg KH
2025-04-22 19:46         ` Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox