Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 20 Mar 2018 22:01:18 +0000 (UTC)
From:      Warner Losh <imp@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r331271 - in head/sys/dev: cardbus pccard pccbb
Message-ID:  <201803202201.w2KM1Isd085328@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: imp
Date: Tue Mar 20 22:01:18 2018
New Revision: 331271
URL: https://svnweb.freebsd.org/changeset/base/331271

Log:
  Push down Giant one layer. In the days of yore, back when Penitums
  were the new kids on the block and F00F hacks were all the rage, one
  needed to take out Giant to do anything moderately complicated with
  the VM, mappings and such. So the pccard / cardbus code held Giant for
  the entire insertion or removal process.
  
  Today, the VM is MP safe. The lock is only needed for dealing with
  newbus things. Move locking and unlocking Giant to be only around
  adding and probing devices in pccard and cardbus.

Modified:
  head/sys/dev/cardbus/cardbus.c
  head/sys/dev/pccard/pccard.c
  head/sys/dev/pccbb/pccbb.c

Modified: head/sys/dev/cardbus/cardbus.c
==============================================================================
--- head/sys/dev/cardbus/cardbus.c	Tue Mar 20 22:00:58 2018	(r331270)
+++ head/sys/dev/cardbus/cardbus.c	Tue Mar 20 22:01:18 2018	(r331271)
@@ -197,6 +197,7 @@ cardbus_attach_card(device_t cbdev)
 	domain = pcib_get_domain(cbdev);
 	bus = pcib_get_bus(cbdev);
 	slot = 0;
+	mtx_lock(&Giant);
 	/* For each function, set it up and try to attach a driver to it */
 	for (func = 0; func <= cardbusfunchigh; func++) {
 		struct cardbus_devinfo *dinfo;
@@ -230,6 +231,7 @@ cardbus_attach_card(device_t cbdev)
 		else
 			pci_cfg_save(dinfo->pci.cfg.dev, &dinfo->pci, 1);
 	}
+	mtx_unlock(&Giant);
 	if (cardattached > 0)
 		return (0);
 /*	POWER_DISABLE_SOCKET(brdev, cbdev); */

Modified: head/sys/dev/pccard/pccard.c
==============================================================================
--- head/sys/dev/pccard/pccard.c	Tue Mar 20 22:00:58 2018	(r331270)
+++ head/sys/dev/pccard/pccard.c	Tue Mar 20 22:01:18 2018	(r331271)
@@ -236,6 +236,7 @@ pccard_attach_card(device_t dev)
 	DEVPRINTF((dev, "Card has %d functions. pccard_mfc is %d\n", i + 1,
 	    pccard_mfc(sc)));
 
+	mtx_lock(&Giant);
 	STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) {
 		if (STAILQ_EMPTY(&pf->cfe_head))
 			continue;
@@ -248,6 +249,7 @@ pccard_attach_card(device_t dev)
 		pf->dev = child;
 		pccard_probe_and_attach_child(dev, child, pf);
 	}
+	mtx_unlock(&Giant);
 	return (0);
 }
 

Modified: head/sys/dev/pccbb/pccbb.c
==============================================================================
--- head/sys/dev/pccbb/pccbb.c	Tue Mar 20 22:00:58 2018	(r331270)
+++ head/sys/dev/pccbb/pccbb.c	Tue Mar 20 22:01:18 2018	(r331271)
@@ -470,14 +470,6 @@ cbb_event_thread(void *arg)
 	sc->flags |= CBB_KTHREAD_RUNNING;
 	while ((sc->flags & CBB_KTHREAD_DONE) == 0) {
 		mtx_unlock(&sc->mtx);
-		/*
-		 * We take out Giant here because we need it deep,
-		 * down in the bowels of the vm system for mapping the
-		 * memory we need to read the CIS.  In addition, since
-		 * we are adding/deleting devices from the dev tree,
-		 * and that code isn't MP safe, we have to hold Giant.
-		 */
-		mtx_lock(&Giant);
 		status = cbb_get(sc, CBB_SOCKET_STATE);
 		DPRINTF(("Status is 0x%x\n", status));
 		if (!CBB_CARD_PRESENT(status)) {
@@ -503,7 +495,6 @@ cbb_event_thread(void *arg)
 			not_a_card = 0;		/* We know card type */
 			cbb_insert(sc);
 		}
-		mtx_unlock(&Giant);
 
 		/*
 		 * First time through we need to tell mountroot that we're



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201803202201.w2KM1Isd085328>