From nobody Fri Mar 24 13:13:57 2023 X-Original-To: dev-commits-src-all@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 4PjjMp6fLVz41Yl4; Fri, 24 Mar 2023 13:13:58 +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 4PjjMp0vdfz43Gs; Fri, 24 Mar 2023 13:13:58 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679663638; 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=Bv2ubscWFQd1aGQxlWoEyfwEIBG7KqPoal9CsIKYujY=; b=AmiDLY9mEqoWlKKZ2NKCeW9n+gbEw1pl1nVRvA2EXFSsCVEjZuJtG4mXkaDY9GVnl7iNh2 5wbV9D7IE4buh2OVflDV73VtbDoGJuWkiHVz89wkjiuYEW7mdpNsZgGiGTo0SOTwjeksvA 5vLKUHpWQWubqDxKuZMN1PO6b+eIfyJTq7MsJSkxTPfIjGIoM8+4ccdlTRcO8Er2bOzXdA 1lr4IMuuw7GRC8EUpBRMY10Tkq3k3cSpA+jExCxokJBLVKgZ6MBnQe9SjHViVxXrhwVXuq rETGwsta4l9LHtUB4BhkfZPiyudvQWCxA87PqKZRqcrR6AAxVhyc6rhOTlQXyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679663638; 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=Bv2ubscWFQd1aGQxlWoEyfwEIBG7KqPoal9CsIKYujY=; b=CZY0tUtZZg5yCyyhiS23b5Cvntmuxn9XnPv9dbD7mXFL2Y7w7IuARqFx06HBGlDVcxWheu ntr+G88HcTmtgMVdqDswvzsyRQBvWPI5E5Z/HBLd2e8CWITGvk0O9E1pIUfBnsCVo6n4Ra z/5P6K2G9bghYPDKugZofMq1oik4o4cAQEIcqfzLPD0wTIV3oMvZVreHneS0fqSUWS7wH2 BrcsAftCwa4RSE6aHOMuja8ZfzMziPoP7FSPn04Nldbk0oiwZcIJYKVODiHtCDUNWJbqX/ 2EiRO+a0Jxm6zyp/WsMO2mM8G+RIcrf6MG2T3Sb84vFvDUHeUuZpk+ZTT2tteA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1679663638; a=rsa-sha256; cv=none; b=eCnQpsKk9ByYYvWFoZ2F6E0+yjvVUb/JV6fl4/P6td3BxGVF4BEh1YGOJNygWTGc6lwQzT vQhHOHv4e/nUarIDxsaMXXFVZbs6B9XxPUB7V2Fylvhs3XFZrkIcNyBjZ3BzmS4xlIkHG0 CiM4IfsbfnR5KXn/5vLHR1nhf45MdZMFrvtlBbfQuNjIhFMKfRLf+0pddB+pt4jD9pNyvC xkgysAePZG1zBSxWb/c2t7wY2Lni4117yBf4TDZ3isQFS5wWIaCDux3TJZXzgKsWwecbv+ FJtAE5yfDS5DQgbMQ6v3Tiim8XEITEgDnL0sevPjAdhPZvcr5lmkefSDeQlIzQ== 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 4PjjMn6tW2zKNG; Fri, 24 Mar 2023 13:13:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 32ODDv4Q031194; Fri, 24 Mar 2023 13:13:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32ODDv7d031193; Fri, 24 Mar 2023 13:13:57 GMT (envelope-from git) Date: Fri, 24 Mar 2023 13:13:57 GMT Message-Id: <202303241313.32ODDv7d031193@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mitchell Horne Subject: git: 865b5640f8ef - stable/13 - arm64: limit EFI excluded regions to physical memory types List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 865b5640f8ef3c3a369f13b2c531737b7fb8fec4 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=865b5640f8ef3c3a369f13b2c531737b7fb8fec4 commit 865b5640f8ef3c3a369f13b2c531737b7fb8fec4 Author: Mitchell Horne AuthorDate: 2023-03-15 15:26:57 +0000 Commit: Mitchell Horne CommitDate: 2023-03-24 13:12:40 +0000 arm64: limit EFI excluded regions to physical memory types Consolidate add_efi_map_entry() and exclude_efi_map_entry() into a single function, handle_efi_map_entry(), so that the exact set of entry types handled is the same in the addition or exclusion cases. Before, exclude_efi_map_entry() had a 'default' case that would exclude all entry types that were not listed explicitly in the switch statement. Logically, we do not need to exclude a range that could not possibly be added to physmem, and we do not need to exclude bus ranges that are not physical memory, for example EFI_MD_TYPE_IOMEM. Since physmem's ram0 device will reserve bus memory resources for its owned ranges, this was preventing attachment of the watchdog device on the RPI4B. For some reason its region of memory-mapped I/O appeared in the EFI memory map (with the aforementioned EFI_MD_TYPE_IOMEM type). This change fixes the attachment issue, as we prevent the physmem API from messing with this range of bus space. PR: 270044 Reported by: karels, Mark Millard Reviewed by: andrew, karels, imp MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D39003 (cherry picked from commit 8937bd37d07c5c75995e01457aec00fb0a05c462) --- sys/arm64/arm64/machdep.c | 71 ++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/sys/arm64/arm64/machdep.c b/sys/arm64/arm64/machdep.c index 283ca221d7f3..68fcf0257232 100644 --- a/sys/arm64/arm64/machdep.c +++ b/sys/arm64/arm64/machdep.c @@ -446,36 +446,25 @@ foreach_efi_map_entry(struct efi_map_header *efihdr, efi_map_entry_cb cb, void * } } +/* + * Handle the EFI memory map list. + * + * We will make two passes at this, the first (exclude == false) to populate + * physmem with valid physical memory ranges from recognized map entry types. + * In the second pass we will exclude memory ranges from physmem which must not + * be used for general allocations, either because they are used by runtime + * firmware or otherwise reserved. + * + * Adding the runtime-reserved memory ranges to physmem and excluding them + * later ensures that they are included in the DMAP, but excluded from + * phys_avail[]. + * + * Entry types not explicitly listed here are ignored and not mapped. + */ static void -exclude_efi_map_entry(struct efi_md *p, void *argp __unused) -{ - - switch (p->md_type) { - case EFI_MD_TYPE_CODE: - case EFI_MD_TYPE_DATA: - case EFI_MD_TYPE_BS_CODE: - case EFI_MD_TYPE_BS_DATA: - case EFI_MD_TYPE_FREE: - /* - * We're allowed to use any entry with these types. - */ - break; - default: - physmem_exclude_region(p->md_phys, p->md_pages * EFI_PAGE_SIZE, - EXFLAG_NOALLOC); - } -} - -static void -exclude_efi_map_entries(struct efi_map_header *efihdr) -{ - - foreach_efi_map_entry(efihdr, exclude_efi_map_entry, NULL); -} - -static void -add_efi_map_entry(struct efi_md *p, void *argp __unused) +handle_efi_map_entry(struct efi_md *p, void *argp) { + bool exclude = *(bool *)argp; switch (p->md_type) { case EFI_MD_TYPE_RECLAIM: @@ -487,7 +476,7 @@ add_efi_map_entry(struct efi_md *p, void *argp __unused) /* * Some UEFI implementations put the system table in the * runtime code section. Include it in the DMAP, but will - * be excluded from phys_avail later. + * be excluded from phys_avail. */ case EFI_MD_TYPE_RT_DATA: /* @@ -495,6 +484,12 @@ add_efi_map_entry(struct efi_md *p, void *argp __unused) * region is created to stop it from being added * to phys_avail. */ + if (exclude) { + physmem_exclude_region(p->md_phys, + p->md_pages * EFI_PAGE_SIZE, EXFLAG_NOALLOC); + break; + } + /* FALLTHROUGH */ case EFI_MD_TYPE_CODE: case EFI_MD_TYPE_DATA: case EFI_MD_TYPE_BS_CODE: @@ -503,8 +498,12 @@ add_efi_map_entry(struct efi_md *p, void *argp __unused) /* * We're allowed to use any entry with these types. */ - physmem_hardware_region(p->md_phys, - p->md_pages * EFI_PAGE_SIZE); + if (!exclude) + physmem_hardware_region(p->md_phys, + p->md_pages * EFI_PAGE_SIZE); + break; + default: + /* Other types shall not be handled by physmem. */ break; } } @@ -512,7 +511,15 @@ add_efi_map_entry(struct efi_md *p, void *argp __unused) static void add_efi_map_entries(struct efi_map_header *efihdr) { - foreach_efi_map_entry(efihdr, add_efi_map_entry, NULL); + bool exclude = false; + foreach_efi_map_entry(efihdr, handle_efi_map_entry, &exclude); +} + +static void +exclude_efi_map_entries(struct efi_map_header *efihdr) +{ + bool exclude = true; + foreach_efi_map_entry(efihdr, handle_efi_map_entry, &exclude); } static void