Date: Mon, 21 Apr 2025 18:56:13 +0100 From: Jessica Clarke <jrtc27@freebsd.org> To: =?utf-8?Q?Bojan_Novkovi=C4=87?= <bnovkov@FreeBSD.org> Cc: "src-committers@freebsd.org" <src-committers@FreeBSD.org>, "dev-commits-src-all@freebsd.org" <dev-commits-src-all@FreeBSD.org>, "dev-commits-src-main@freebsd.org" <dev-commits-src-main@FreeBSD.org> Subject: Re: git: f1e18f331923 - main - riscv: Exclude OpenSBI memory regions when booting with EFI Message-ID: <F443E453-62F7-4599-A6B9-118FB8D63E69@freebsd.org> In-Reply-To: <6F9CE6EB-8A7E-48D1-BDE5-AB7D930EC1DE@freebsd.org> References: <202504161421.53GELphv059586@gitrepo.freebsd.org> <6F9CE6EB-8A7E-48D1-BDE5-AB7D930EC1DE@freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On 16 Apr 2025, at 15:30, Jessica Clarke <jrtc27@FreeBSD.org> wrote: >=20 > On 16 Apr 2025, at 15:21, Bojan Novkovi=C4=87 <bnovkov@FreeBSD.org> = wrote: >>=20 >> The branch main has been updated by bnovkov: >>=20 >> URL: = https://cgit.FreeBSD.org/src/commit/?id=3Df1e18f331923041980149fef46cdb273= 6e61debb >>=20 >> commit f1e18f331923041980149fef46cdb2736e61debb >> Author: Bojan Novkovi=C4=87 <bnovkov@FreeBSD.org> >> AuthorDate: 2025-04-15 16:28:05 +0000 >> Commit: Bojan Novkovi=C4=87 <bnovkov@FreeBSD.org> >> CommitDate: 2025-04-16 14:20:13 +0000 >>=20 >> riscv: Exclude OpenSBI memory regions when booting with EFI >>=20 >> OpenSBI uses the first PMP entry to prevent buggy supervisor >> software from overwriting the firmware [1]. However, this >> region may not be properly marked as reserved in the EFI map, = leading >> to an access violation exception whenever the kernel >> attempts to write to a page from that region. >>=20 >> Fix this by preemptively excluding first EFI memory map entry >> if it is marked as "BootServicesData". >>=20 >> [1] https://github.com/riscv-non-isa/riscv-sbi-doc/pull/37 >>=20 >> Reported by: tuexen >> Tested by: tuexen >> Fixes: a2e2178402af >> Reviewed by: imp, jrtc27 >=20 > No I didn=E2=80=99t, I left a comment saying I didn=E2=80=99t like the = concept. >=20 >> Differential Revision: https://reviews.freebsd.org/D49839 >> --- >> sys/riscv/riscv/machdep.c | 32 ++++++++++++++++++++++++++++++-- >> 1 file changed, 30 insertions(+), 2 deletions(-) >>=20 >> diff --git a/sys/riscv/riscv/machdep.c b/sys/riscv/riscv/machdep.c >> index 516dbde5ffaa..f253bc9a853b 100644 >> --- a/sys/riscv/riscv/machdep.c >> +++ b/sys/riscv/riscv/machdep.c >> @@ -541,6 +541,22 @@ fdt_physmem_exclude_region_cb(const struct = mem_region *mr, void *arg __unused) >> } >> #endif >>=20 >> +static void >> +efi_exclude_sbi_pmp_cb(struct efi_md *p, void *argp) >> +{ >> + bool *first =3D (bool *)argp; >> + >> + if (!*first) >> + return; >> + >> + *first =3D false; >> + if (p->md_type =3D=3D EFI_MD_TYPE_BS_DATA) { >> + physmem_exclude_region(p->md_phys, >> + min(p->md_pages * EFI_PAGE_SIZE, L2_SIZE), >> + EXFLAG_NOALLOC); >=20 > Doesn=E2=80=99t this need EXFLAG_NODUMP like the FDT case? Ping. Jess
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?F443E453-62F7-4599-A6B9-118FB8D63E69>