Module Name:    src
Committed By:   rin
Date:           Sat May  7 05:08:16 UTC 2022

Modified Files:
        src/sys/arch/powerpc/booke/pci: pq3pci.c

Log Message:
Downgrade pq3pci_intrsources_lock and pq3pci_msigroups_lock from
spin to adaptive mutexes.

These locks are typically used during autoconf(9), not from
interrupt context.

Found by LOCKDEBUG.

XXX
I'm not sure whether these locks are really necessary...
Similar codes, e.g. in powerpc/pic/intr.c, do not use any locks.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/powerpc/booke/pci/pq3pci.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/powerpc/booke/pci/pq3pci.c
diff -u src/sys/arch/powerpc/booke/pci/pq3pci.c:1.30 src/sys/arch/powerpc/booke/pci/pq3pci.c:1.31
--- src/sys/arch/powerpc/booke/pci/pq3pci.c:1.30	Tue Jan 11 22:45:56 2022
+++ src/sys/arch/powerpc/booke/pci/pq3pci.c	Sat May  7 05:08:16 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: pq3pci.c,v 1.30 2022/01/11 22:45:56 andvar Exp $	*/
+/*	$NetBSD: pq3pci.c,v 1.31 2022/05/07 05:08:16 rin Exp $	*/
 /*-
  * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -39,7 +39,7 @@
 #define	__INTR_PRIVATE
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pq3pci.c,v 1.30 2022/01/11 22:45:56 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pq3pci.c,v 1.31 2022/05/07 05:08:16 rin Exp $");
 
 #include "locators.h"
 
@@ -727,8 +727,11 @@ static int
 pq3pci_once_init(void)
 {
 
-	mutex_init(&pq3pci_intrsources_lock, MUTEX_DEFAULT, IPL_VM);
-	mutex_init(&pq3pci_msigroups_lock, MUTEX_DEFAULT, IPL_VM);
+	/*
+	 * XXX necessary??
+	 */
+	mutex_init(&pq3pci_intrsources_lock, MUTEX_DEFAULT, IPL_NONE);
+	mutex_init(&pq3pci_msigroups_lock, MUTEX_DEFAULT, IPL_NONE);
 
 	return 0;
 }
@@ -1209,7 +1212,7 @@ pq3pci_msi_alloc_one(int ipl)
 	uint32_t bitmap[maplen];
 	pci_intr_handle_t handle;
 
-	mutex_spin_enter(&pq3pci_msigroups_lock);
+	mutex_enter(&pq3pci_msigroups_lock);
 	for (u_int i = 0; i < maplen; i++) {
 		struct pq3pci_msigroup * const msig = pq3pci_msigroups[i];
 		if (msig == NULL) {
@@ -1237,20 +1240,20 @@ pq3pci_msi_alloc_one(int ipl)
 			struct pq3pci_msihand * const msih __diagused =
 			    pq3pci_msi_claim(handle);
 			KASSERT(msih != NULL);
-			mutex_spin_exit(&pq3pci_msigroups_lock);
+			mutex_exit(&pq3pci_msigroups_lock);
 			return handle;
 		}
 	}
 
 	if (freegroup-- == 0) {
-		mutex_spin_exit(&pq3pci_msigroups_lock);
+		mutex_exit(&pq3pci_msigroups_lock);
 		return 0;
 	}
 
 	struct pq3pci_msigroup * const msig =
 	    kmem_zalloc(sizeof(*msig), KM_NOSLEEP);
 	if (msig == NULL) {
-		mutex_spin_exit(&pq3pci_msigroups_lock);
+		mutex_exit(&pq3pci_msigroups_lock);
 		return 0;
 	}
 	pq3pci_msi_group_setup(msig, freegroup, ipl);
@@ -1259,7 +1262,7 @@ pq3pci_msi_alloc_one(int ipl)
 	struct pq3pci_msihand * const msih __diagused =
 	    pq3pci_msi_claim(handle);
 	KASSERT(msih != NULL);
-	mutex_spin_exit(&pq3pci_msigroups_lock);
+	mutex_exit(&pq3pci_msigroups_lock);
 	return handle;
 }
 
@@ -1327,17 +1330,17 @@ static struct pq3pci_intrsource *
 pq3pci_intr_source_lookup(struct pq3pci_softc *sc, pci_intr_handle_t handle)
 {
 	struct pq3pci_intrsource *pis;
-	mutex_spin_enter(&pq3pci_intrsources_lock);
+	mutex_enter(&pq3pci_intrsources_lock);
 	SIMPLEQ_FOREACH(pis, &pq3pci_intrsources, pis_link) {
 		if (pis->pis_handle == handle) {
-			mutex_spin_exit(&pq3pci_intrsources_lock);
+			mutex_exit(&pq3pci_intrsources_lock);
 			return pis;
 		}
 	}
 	pis = kmem_zalloc(sizeof(*pis), KM_NOSLEEP);
 	if (pis != NULL)
 		pq3pci_intr_source_setup(sc, pis, handle);
-	mutex_spin_exit(&pq3pci_intrsources_lock);
+	mutex_exit(&pq3pci_intrsources_lock);
 	return pis;
 }
 

Reply via email to