Date: Fri, 17 Jul 2015 18:38:26 +0000 From: "zbb (Zbigniew Bodek)" <phabric-noreply@FreeBSD.org> To: freebsd-arm@freebsd.org Subject: [Differential] [Request, 32 lines] D3121: Don't allow malloc() to wait for resource while holding a lock in ITS Message-ID: <differential-rev-PHID-DREV-ztsg4nogc7wzfzawsctm-req@FreeBSD.org>
next in thread | raw e-mail | index | archive | help
--b1_9a72bb892bcba53faec79e1a568f0eb4 Content-Type: text/plain; charset = "utf-8" Content-Transfer-Encoding: 8bit zbb created this revision. zbb added reviewers: emaste, andrew, wma_semihalf.com, imp, ian. zbb added a subscriber: freebsd-arm-list. zbb set the repository for this revision to rS FreeBSD src repository. Herald added subscribers: emaste, andrew, imp. REVISION SUMMARY 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 since 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 REPOSITORY rS FreeBSD src repository REVISION DETAIL https://reviews.freebsd.org/D3121 AFFECTED FILES sys/arm64/arm64/gic_v3_its.c CHANGE DETAILS diff --git a/sys/arm64/arm64/gic_v3_its.c b/sys/arm64/arm64/gic_v3_its.c --- a/sys/arm64/arm64/gic_v3_its.c +++ b/sys/arm64/arm64/gic_v3_its.c @@ -795,6 +795,26 @@ } 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) { @@ -1303,7 +1323,10 @@ devid = PCI_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; @@ -1321,7 +1344,12 @@ */ 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 EMAIL PREFERENCES https://reviews.freebsd.org/settings/panel/emailpreferences/ To: zbb, emaste, andrew, wma_semihalf.com, imp, ian Cc: imp, andrew, freebsd-arm-list, emaste --b1_9a72bb892bcba53faec79e1a568f0eb4 Content-Type: text/x-patch; charset=utf-8; name="D3121.7056.patch" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="D3121.7056.patch" ZGlmZiAtLWdpdCBhL3N5cy9hcm02NC9hcm02NC9naWNfdjNfaXRzLmMgYi9zeXMvYXJtNjQvYXJt NjQvZ2ljX3YzX2l0cy5jCi0tLSBhL3N5cy9hcm02NC9hcm02NC9naWNfdjNfaXRzLmMKKysrIGIv c3lzL2FybTY0L2FybTY0L2dpY192M19pdHMuYwpAQCAtNzk1LDYgKzc5NSwyNiBAQAogfQogCiBz dGF0aWMgdm9pZAorbHBpX2ZyZWVfY2h1bmsoc3RydWN0IGdpY192M19pdHNfc29mdGMgKnNjLCBz dHJ1Y3QgbHBpX2NodW5rICpscGljKQoreworCWludCBzdGFydCwgZW5kOworCXVpbnQ4X3QgKmJp dG1hcDsK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GV2LT5wY2lfZGV2ID0gcGNpX2RldjsK IAluZXdkZXYtPmRldmlkID0gZGV2aWQ7CiAKQEAgLTEzMjEsNyArMTM0NCwxMiBAQAogCSAqLwog CW5ld2Rldi0+aXR0ID0gKHZtX29mZnNldF90KWNvbnRpZ21hbGxvYygKIAkgICAgcm91bmR1cDIo cm91bmR1cDIobnZlY3MsIDIpICogZXNpemUsIDB4MTAwKSwgTV9HSUNfVjNfSVRTLAotCSAgICAo TV9XQUlUT0sgfCBNX1pFUk8pLCAwLCB+MFVMLCAweDEwMCwgMCk7CisJICAgIChNX05PV0FJVCB8 IE1fWkVSTyksIDAsIH4wVUwsIDB4MTAwLCAwKTsKKwlpZiAobmV3ZGV2LT5pdHQgPT0gMCkgewor CQlscGlfZnJlZV9jaHVuayhzYywgJm5ld2Rldi0+bHBpcyk7CisJCWZyZWUobmV3ZGV2LCBNX0dJ Q19WM19JVFMpOworCQlyZXR1cm4gKE5VTEwpOworCX0KIAogCS8qCiAJICogWFhYIEFSTTY0VE9E TzogQ3VycmVudGx5IGFsbCBpbnRlcnJ1cHRzIGFyZSBnb2luZwoK --b1_9a72bb892bcba53faec79e1a568f0eb4--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?differential-rev-PHID-DREV-ztsg4nogc7wzfzawsctm-req>