diff options
author | zbb <zbb@FreeBSD.org> | 2015-07-21 15:28:07 +0000 |
---|---|---|
committer | zbb <zbb@FreeBSD.org> | 2015-07-21 15:28:07 +0000 |
commit | 34b957f11d926d9a5619892f23c8db72b22f58d3 (patch) | |
tree | def8b1fb7ded8b2d1243a10c93ddfb48bd3b51d0 | |
parent | 5f08ac18d237b01234affc94c71a78cb1389bf71 (diff) | |
download | FreeBSD-src-34b957f11d926d9a5619892f23c8db72b22f58d3.zip FreeBSD-src-34b957f11d926d9a5619892f23c8db72b22f58d3.tar.gz |
Don't allow malloc() to wait for resource while holding a lock in ITS
malloc() should not go to sleep in case of lack of resource while
the kernel thread is holding a non-sleepable lock.
- change malloc() flags to M_NOWAIT in such cases implement
lpi_free_chunk() routine as it will be needed when ITT
allocation fails in its_device_alloc_locked()
- do not increase verbosity of this code since upper layers will
communicate an error if the interrupt setup fails
Obtained from: Semihalf
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D3121
-rw-r--r-- | sys/arm64/arm64/gic_v3_its.c | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/sys/arm64/arm64/gic_v3_its.c b/sys/arm64/arm64/gic_v3_its.c index f8488bb..2697c7d 100644 --- a/sys/arm64/arm64/gic_v3_its.c +++ b/sys/arm64/arm64/gic_v3_its.c @@ -814,6 +814,26 @@ retry: } static void +lpi_free_chunk(struct gic_v3_its_softc *sc, struct lpi_chunk *lpic) +{ + int start, end; + uint8_t *bitmap; + + bitmap = (uint8_t *)sc->its_lpi_bitmap; + + KASSERT((lpic->lpi_free == lpic->lpi_num), + ("Trying to free LPI chunk that is still in use.\n")); + + /* First bit of this chunk in a global bitmap */ + start = lpic->lpi_base - GIC_FIRST_LPI; + /* and last bit of this chunk... */ + end = start + lpic->lpi_num - 1; + + /* Finally free this chunk */ + bit_nclear(bitmap, start, end); +} + +static void lpi_configure(struct gic_v3_its_softc *sc, struct its_dev *its_dev, uint32_t lpinum, boolean_t unmask) { @@ -1322,7 +1342,10 @@ its_device_alloc_locked(struct gic_v3_its_softc *sc, device_t pci_dev, devid = its_get_devid(pci_dev); /* There was no previously created device. Create one now */ - newdev = malloc(sizeof(*newdev), M_GIC_V3_ITS, (M_WAITOK | M_ZERO)); + newdev = malloc(sizeof(*newdev), M_GIC_V3_ITS, (M_NOWAIT | M_ZERO)); + if (newdev == NULL) + return (NULL); + newdev->pci_dev = pci_dev; newdev->devid = devid; @@ -1340,7 +1363,12 @@ its_device_alloc_locked(struct gic_v3_its_softc *sc, device_t pci_dev, */ newdev->itt = (vm_offset_t)contigmalloc( roundup2(roundup2(nvecs, 2) * esize, 0x100), M_GIC_V3_ITS, - (M_WAITOK | M_ZERO), 0, ~0UL, 0x100, 0); + (M_NOWAIT | M_ZERO), 0, ~0UL, 0x100, 0); + if (newdev->itt == 0) { + lpi_free_chunk(sc, &newdev->lpis); + free(newdev, M_GIC_V3_ITS); + return (NULL); + } /* * XXX ARM64TODO: Currently all interrupts are going |