Skip to contentSkip to conversation

pds_core: disable bus mastering in pdsc_stop() to quiesce DMA

PATCH In review Nikhil P. Rao 2 participants 2 messages Jun 3

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pds_core: disable bus mastering in pdsc_stop() to quiesce DMA

pdsc_stop() masks interrupts but does not disable bus mastering, leaving the device able to perform DMA after the function returns. This can lead to use-after-free if DMA buffers are freed while the device is still accessing them.

Add pci_clear_master() to pdsc_stop() to disable bus mastering after masking interrupts, ensuring all DMA is quiesced before teardown proceeds.

Add the corresponding pci_set_master() to pdsc_start() to re-enable bus mastering when the device is brought back up, such as during recovery.

Fixes 01ba61b55b20 ("pds_core: Add adminq processing and commands")
---
 drivers/net/ethernet/amd/pds_core/core.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/net/ethernet/amd/pds_core/core.c +9 -7
index 705cab7b0727..27369b3297b2 100644
@@ -494,6 +494,7 @@ void pdsc_teardown(struct pdsc *pdsc, bool removing)
 
 int pdsc_start(struct pdsc *pdsc)
 {
+	pci_set_master(pdsc->pdev);
 	pds_core_intr_mask(&pdsc->intr_ctrl[pdsc->adminqcq.intx],
 			   PDS_CORE_INTR_MASK_CLEAR);
 
@@ -504,14 +505,15 @@ void pdsc_stop(struct pdsc *pdsc)
 {
 	int i;
 
-	if (!pdsc->intr_info)
-		return;
-
 	/* Mask interrupts that are in use */
-	for (i = 0; i < pdsc->nintrs; i++)
-		if (pdsc->intr_info[i].vector)
-			pds_core_intr_mask(&pdsc->intr_ctrl[i],
-					   PDS_CORE_INTR_MASK_SET);
+	if (pdsc->intr_info) {
+		for (i = 0; i < pdsc->nintrs; i++)
+			if (pdsc->intr_info[i].vector)
+				pds_core_intr_mask(&pdsc->intr_ctrl[i],
+						   PDS_CORE_INTR_MASK_SET);
+	}
+
+	pci_clear_master(pdsc->pdev);
 }
 
 static void pdsc_adminq_wait_and_dec_once_unused(struct pdsc *pdsc)
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw

From: Nikhil P. Rao <[email protected]>
Date: Wed, 3 Jun 2026 03:52:45 +0000

Quoted 9 lines

pdsc_stop() masks interrupts but does not disable bus mastering, leaving the device able to perform DMA after the function returns. This can lead to use-after-free if DMA buffers are freed while the device is still accessing them.

Add pci_clear_master() to pdsc_stop() to disable bus mastering after masking interrupts, ensuring all DMA is quiesced before teardown proceeds.

Quoted 6 lines

Add the corresponding pci_set_master() to pdsc_start() to re-enable bus mastering when the device is brought back up, such as during recovery.

Fixes 01ba61b55b20 ("pds_core: Add adminq processing and commands")

One nit below.

Quoted 24 lines
---
 drivers/net/ethernet/amd/pds_core/core.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/net/ethernet/amd/pds_core/core.c +1 -3
index 705cab7b0727..27369b3297b2 100644
@@ -494,6 +494,7 @@ void pdsc_teardown(struct pdsc *pdsc, bool removing)
 
 int pdsc_start(struct pdsc *pdsc)
 {
+	pci_set_master(pdsc->pdev);
 	pds_core_intr_mask(&pdsc->intr_ctrl[pdsc->adminqcq.intx],
 			   PDS_CORE_INTR_MASK_CLEAR);
 
@@ -504,14 +505,15 @@ void pdsc_stop(struct pdsc *pdsc)
 {
 	int i;
 
-	if (!pdsc->intr_info)
-		return;
-
 	/* Mask interrupts that are in use */

drivers/net/ethernet/amd/pds_core/core.c void pdsc_stop(struct pdsc *pdsc) · line 514

Quoted 10 lines
drivers/net/ethernet/amd/pds_core/core.c +6 -4
-	for (i = 0; i < pdsc->nintrs; i++)
-		if (pdsc->intr_info[i].vector)
-			pds_core_intr_mask(&pdsc->intr_ctrl[i],
-					   PDS_CORE_INTR_MASK_SET);
+	if (pdsc->intr_info) {
+		for (i = 0; i < pdsc->nintrs; i++)
+			if (pdsc->intr_info[i].vector)
+				pds_core_intr_mask(&pdsc->intr_ctrl[i],
+						   PDS_CORE_INTR_MASK_SET);
+	}

Could you add braces around if since you're touching this anyway?

		for (...) {
			if (pdsc->...)
		}

drivers/net/ethernet/amd/pds_core/core.c void pdsc_stop(struct pdsc *pdsc) · line 519

Quoted 5 lines
drivers/net/ethernet/amd/pds_core/core.c +2 -0
+
+	pci_clear_master(pdsc->pdev);
 }
 
 static void pdsc_adminq_wait_and_dec_once_unused(struct pdsc *pdsc)

Thanks,
Olek