From nobody Wed Aug 23 16:39:02 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4RWBkH0t7Qz4r5hg; Wed, 23 Aug 2023 16:39:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RWBkH0CK9z4K4D; Wed, 23 Aug 2023 16:39:03 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692808743; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Lw7KukhqqjJEpyvAtsosllJ8ws6auMtHeNfwaDBU6FY=; b=BM4EKdhTkwmOmiCJrtwgLhv0KOwvNi9aQc6Zrze7AB+pcZ1ol+pHVJhazYz6sI7W8VVv9m xPRYnPtoaLKcXWKQxNiuIPRolBoczvGlJ2+p9SWo3WOqvJbZwAtiPILRtshsckYbzcm7d4 S+Yu0x1KrIpre0zJ/sfaw5QKlgRhUtiAs07w9jT8WncjvZrHgS0MMuTv6eGgL8RRY1GDWk NjUKUO9JtjNRWPpNFZENsEWn9QSfGKudaqEas6WIMU0bhP7L73QyKs3Hpk1w16cuN5LYcF 9CvBUjzxcRHLFwfleSLtrHUZC4vceh6dz+GcrTB0UmIJe3eq5EvCqjJyTwVa8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692808743; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Lw7KukhqqjJEpyvAtsosllJ8ws6auMtHeNfwaDBU6FY=; b=dNYrE7ZRI53Yaonx9LsCfDnAGhvPt/9qiyNaBIhdqTNei8yArD6yLK2zIUK30sODymJJyD seNUjO6WkE9aDmn0mDgcNZ8fZ2IM1Vtu/IgCsmQ++jDsxogQhcnpRA/jjV53FiqOE3AO6O TiOBr7A9AocmO5sKTQcxOB3/Z2Eb4BvgnouadHXSyuuUD0llNsRDPZCG1h1jXgDkgjSlA+ H33RrqiqbHZv2BHLzyHEuA5cc2t/ZKcfMU15BzPUkQLZ/m4hmCp1VMMLKrL7RxH61bpyQ7 QxSfMrehaISPXiyiJgLE8wE0hRRDLr2sHPMoiufHc+H6veMpjHK5euHRjOxSbg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1692808743; a=rsa-sha256; cv=none; b=oZPgq+n7tEAB1rSv9USTjp7ce6cXHYtQmyjSKEupDEtkBeJUb0rvXRxAh75QrKZwBwflJM S+SwBdpcjM0B16S+vuPmSJMRy55JPK6eACy/aPBlkxIXyEyn3Ou1CCpbdUz0rUzCK8STxE LiazvgA9x3fcEWTAzdxP9QrTwZ//m3hjA6ji7M/gUDHgAdy9qhvVyb+1psZv9cpo0NdCHX SKsYaOGJSS3AT/8rr+li/Gn8aZtB81wzllOKxO+rFu+FtYbHCtzUPaGWe9iByAng4SHaE4 QbFIZoLZyqiqvud1o6nVGGKc6a+7WuRqKoM9sKL3ziz+aOqgPivF/VODpBTcVg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4RWBkG6Cq8zscM; Wed, 23 Aug 2023 16:39:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 37NGd2Pd023637; Wed, 23 Aug 2023 16:39:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 37NGd2VF023634; Wed, 23 Aug 2023 16:39:02 GMT (envelope-from git) Date: Wed, 23 Aug 2023 16:39:02 GMT Message-Id: <202308231639.37NGd2VF023634@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andrew Turner Subject: git: 7d2dd08d013d - main - gicv3: Add checks for the device ID List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: andrew X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 7d2dd08d013d79dc3f2a22747b079628a571cea2 Auto-Submitted: auto-generated The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=7d2dd08d013d79dc3f2a22747b079628a571cea2 commit 7d2dd08d013d79dc3f2a22747b079628a571cea2 Author: Andrew Turner AuthorDate: 2023-08-22 14:37:19 +0000 Commit: Andrew Turner CommitDate: 2023-08-23 16:38:20 +0000 gicv3: Add checks for the device ID Add checks that the device ID is supported by the hardware and is within the range allocated when the driver attaches. Reviewed by: gallatin, imp Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D41554 --- sys/arm64/arm64/gicv3_its.c | 48 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/sys/arm64/arm64/gicv3_its.c b/sys/arm64/arm64/gicv3_its.c index cc743e72b032..cb655eaca412 100644 --- a/sys/arm64/arm64/gicv3_its.c +++ b/sys/arm64/arm64/gicv3_its.c @@ -221,7 +221,10 @@ struct its_cmd { /* An ITS private table */ struct its_ptable { vm_offset_t ptab_vaddr; - unsigned long ptab_size; + /* Size of the L1 table */ + size_t ptab_l1_size; + /* Number of L1 entries */ + int ptab_l1_nidents; }; /* ITS collection description. */ @@ -246,6 +249,8 @@ struct gicv3_its_softc { cpuset_t sc_cpus; struct domainset *sc_ds; u_int gic_irq_cpu; + int sc_devbits; + int sc_dev_table_idx; struct its_ptable sc_its_ptab[GITS_BASER_NUM]; struct its_col *sc_its_cols[MAXCPU]; /* Per-CPU collections */ @@ -476,7 +481,8 @@ gicv3_its_table_init(device_t dev, struct gicv3_its_softc *sc) vm_offset_t table; vm_paddr_t paddr; uint64_t cache, reg, share, tmp, type; - size_t esize, its_tbl_size, nidents, nitspages, npages; + size_t its_tbl_size, nitspages, npages; + size_t l1_esize, l1_nidents; int i, page_size; int devbits; @@ -505,6 +511,7 @@ gicv3_its_table_init(device_t dev, struct gicv3_its_softc *sc) devbits = GITS_TYPER_DEVB(gic_its_read_8(sc, GITS_TYPER)); cache = GITS_BASER_CACHE_WAWB; } + sc->sc_devbits = devbits; share = GITS_BASER_SHARE_IS; for (i = 0; i < GITS_BASER_NUM; i++) { @@ -515,7 +522,7 @@ gicv3_its_table_init(device_t dev, struct gicv3_its_softc *sc) continue; /* The table entry size */ - esize = GITS_BASER_ESIZE(reg); + l1_esize = GITS_BASER_ESIZE(reg); /* Find the tables page size */ page_size = gicv3_its_table_page_size(sc, i); @@ -527,8 +534,13 @@ gicv3_its_table_init(device_t dev, struct gicv3_its_softc *sc) switch(type) { case GITS_BASER_TYPE_DEV: - nidents = (1 << devbits); - its_tbl_size = esize * nidents; + if (sc->sc_dev_table_idx != -1) + device_printf(dev, + "Warning: Multiple device tables found\n"); + + sc->sc_dev_table_idx = i; + l1_nidents = (1 << devbits); + its_tbl_size = l1_esize * l1_nidents; its_tbl_size = roundup2(its_tbl_size, page_size); break; case GITS_BASER_TYPE_VP: @@ -550,7 +562,8 @@ gicv3_its_table_init(device_t dev, struct gicv3_its_softc *sc) (1ul << 48) - 1, PAGE_SIZE_64K, 0); sc->sc_its_ptab[i].ptab_vaddr = table; - sc->sc_its_ptab[i].ptab_size = npages * PAGE_SIZE; + sc->sc_its_ptab[i].ptab_l1_size = its_tbl_size; + sc->sc_its_ptab[i].ptab_l1_nidents = l1_nidents; paddr = vtophys(table); @@ -874,6 +887,7 @@ gicv3_its_attach(device_t dev) sc = device_get_softc(dev); + sc->sc_dev_table_idx = -1; sc->sc_irq_length = gicv3_get_nirqs(dev); sc->sc_irq_base = GIC_FIRST_LPI; sc->sc_irq_base += device_get_unit(dev) * sc->sc_irq_length; @@ -1200,6 +1214,23 @@ its_device_find(device_t dev, device_t child) return (its_dev); } +static bool +its_device_alloc(struct gicv3_its_softc *sc, int devid) +{ + struct its_ptable *ptable; + + /* No device table */ + if (sc->sc_dev_table_idx < 0) { + if (devid < (1 << sc->sc_devbits)) + return (true); + return (false); + } + + ptable = &sc->sc_its_ptab[sc->sc_dev_table_idx]; + /* Check the devid is within the table limit */ + return (devid < ptable->ptab_l1_nidents); +} + static struct its_dev * its_device_get(device_t dev, device_t child, u_int nvecs) { @@ -1225,6 +1256,11 @@ its_device_get(device_t dev, device_t child, u_int nvecs) its_dev->lpis.lpi_num = nvecs; its_dev->lpis.lpi_free = nvecs; + if (!its_device_alloc(sc, its_dev->devid)) { + free(its_dev, M_GICV3_ITS); + return (NULL); + } + if (vmem_alloc(sc->sc_irq_alloc, nvecs, M_FIRSTFIT | M_NOWAIT, &irq_base) != 0) { free(its_dev, M_GICV3_ITS);