Bug 258217 - Kernel GICv3 ITS driver: potentially unsupported 32-bit read of 64-bit register GICR_TYPER
Summary: Kernel GICv3 ITS driver: potentially unsupported 32-bit read of 64-bit regist...
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: arm (show other bugs)
Version: CURRENT
Hardware: arm64 Any
: --- Affects Only Me
Assignee: Andrew Turner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-09-02 15:48 UTC by Olivier Delande
Modified: 2021-10-11 14:03 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Olivier Delande 2021-09-02 15:48:48 UTC
The kernel driver for the Interrupt Translation Service of ARM's Generic Interrupt Controller version 3 (sys/arm64/arm64/gicv3_its.c) reads the GICR_TYPER memory-mapped register of the redistributor in its its_init_cpu() function:

/* Check if the ITS is enabled on this CPU */
if ((gic_r_read_4(gicv3, GICR_TYPER) & GICR_TYPER_PLPIS) == 0)
       	...

This is a 32-bit read. However, GICR_TYPER is a 64-bit register and the GICv3 specification ([1], ยง11.1.3) only requires that such accesses be supported on systems with at least one core supporting Aarch32. By contrast, 64-bit reads are always supported.

I suggest extending the read to 64 bits. By the way, the main GICv3 driver (sys/arm64/arm64/gic_v3.c) also reads GICR_TYPER, and it does so with bus_read_8().

This issue showed up on a software implementation of the ITS (hypervisor) that expected a 64-bit read.

[1] https://developer.arm.com/documentation/ihi0069/latest
Comment 1 commit-hook freebsd_committer freebsd_triage 2021-09-15 09:22:47 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=1896a0094317c80d46beff5ad42b68215513c996

commit 1896a0094317c80d46beff5ad42b68215513c996
Author:     Andrew Turner <andrew@FreeBSD.org>
AuthorDate: 2021-09-15 09:13:41 +0000
Commit:     Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2021-09-15 09:13:41 +0000

    Use a 64 bit read to access GICR_TYPER

    The GICv3 ITS only needs to implement 32 bit access to the GICR_TYPER
    when the CPU implements AArch32. As this may not always be the case
    use a 64 bit read when checking if the ITS is enabled on the CPU.

    PR:             258217
    Reported by:    Olivier Delande <olivier.delande@provenrun.com>
    Sponsored by:   The FreeBSD Foundation

 sys/arm64/arm64/gicv3_its.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Comment 2 Antranig Vartanian 2021-09-27 12:07:35 UTC
Hey there!

I've been able to boot FreeBSD 13.0-RELEASE arm64.aarch64 in UTM on M1 MBP, however FreeBSD 14.0-CURRENT does not boot. I get a kernel panic.

Unfortunately I was not able to copy the console, so here's a screenshoot: https://antranigv.am/misc/freebsd-arm.jpg

I feel like this issue is connected to this bug, let me know if my hunch is correct :)

Thank you.
Comment 3 commit-hook freebsd_committer freebsd_triage 2021-10-11 12:16:41 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=00c276a2502488f4198dcec4bf1a6d22159e2b62

commit 00c276a2502488f4198dcec4bf1a6d22159e2b62
Author:     Andrew Turner <andrew@FreeBSD.org>
AuthorDate: 2021-09-15 09:13:41 +0000
Commit:     Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2021-10-11 10:50:42 +0000

    Use a 64 bit read to access GICR_TYPER

    The GICv3 ITS only needs to implement 32 bit access to the GICR_TYPER
    when the CPU implements AArch32. As this may not always be the case
    use a 64 bit read when checking if the ITS is enabled on the CPU.

    PR:             258217
    Reported by:    Olivier Delande <olivier.delande@provenrun.com>
    Sponsored by:   The FreeBSD Foundation

    (cherry picked from commit 1896a0094317c80d46beff5ad42b68215513c996)

 sys/arm64/arm64/gicv3_its.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)