[Differential] D35553: protect arm busdma bounce page counters with bounce page lock

From: rfyu28uyeg_snkmail.com (John Hein) <phabric-noreply_at_FreeBSD.org>
Date: Wed, 22 Jun 2022 23:23:11 UTC
rfyu28uyeg_snkmail.com created this revision.
rfyu28uyeg_snkmail.com added reviewers: mjg, hselasky, jhb.
rfyu28uyeg_snkmail.com added a project: ARM.
Herald added subscribers: andrew, imp.
rfyu28uyeg_snkmail.com requested review of this revision.

REVISION SUMMARY
  In bus_dmamap_unload(), the counters for free_bpages and reserved_bpages appear to be vulnerable to unprotected read-modify-write operations that result in accounting that looks like a page leak.
  
  See also https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=264836
  
  Please suggest appropriate reviewers.

REPOSITORY
  rG FreeBSD src repository

REVISION DETAIL
  https://reviews.freebsd.org/D35553

AFFECTED FILES
  sys/arm/arm/busdma_machdep.c

CHANGE DETAILS

diff --git a/sys/arm/arm/busdma_machdep.c b/sys/arm/arm/busdma_machdep.c
--- a/sys/arm/arm/busdma_machdep.c
+++ b/sys/arm/arm/busdma_machdep.c
@@ -1184,8 +1184,10 @@
 		free_bounce_pages(dmat, map);
 
 		bz = dmat->bounce_zone;
+		mtx_lock(&bounce_lock);
 		bz->free_bpages += map->pagesreserved;
 		bz->reserved_bpages -= map->pagesreserved;
+		mtx_unlock(&bounce_lock);
 		map->pagesreserved = 0;
 		map->pagesneeded = 0;
 	}



EMAIL PREFERENCES
  https://reviews.freebsd.org/settings/panel/emailpreferences/

To: rfyu28uyeg_snkmail.com, mjg, hselasky, jhb
Cc: imp, andrew, freebsd-arm-list, bz