From: Ard Biesheuvel <ardb@kernel.org>
To: linux-acpi@vger.kernel.org
Cc: lorenzo.pieralisi@arm.com, catalin.marinas@arm.com,
rjw@rjwysocki.net, will@kernel.org,
Ard Biesheuvel <ardb@kernel.org>,
linux-arm-kernel@lists.infradead.org, lenb@kernel.org
Subject: [PATCH] ACPI: ioremap: avoid redundant rounding to OS page size
Date: Mon, 17 Aug 2020 14:04:31 +0200 [thread overview]
Message-ID: <20200817120431.32233-1-ardb@kernel.org> (raw)
The arm64 implementation of acpi_os_ioremap() was recently updated to
tighten the checks around which parts of memory are permitted to be
mapped by ACPI code, which generally only needs access to memory regions
that are statically described by firmware, and any attempts to access
memory that is in active use by the OS is generally a bug or a hacking
attempt. This tightening is based on the EFI memory map, which describes
all memory in the system.
The AArch64 architecture permits page sizes of 16k and 64k in addition
to the EFI default, which is 4k, which means that the EFI memory map may
describe regions that cannot be mapped seamlessly if the OS page size is
greater than 4k. This is usually not a problem, given that the EFI spec
does not permit memory regions requiring different memory attributes to
share a 64k page frame, and so the usual rounding to page size performed
by ioremap() is sufficient to deal with this. However, this rounding does
complicate our EFI memory map permission check, due to the loss of
information that occurs when several small regions share a single 64k
page frame (where rounding each of them will result in the same 64k
single page region).
However, due to the fact that the region check occurs *before* the call
to ioremap() where the necessary rounding is performed, we can deal
with this issue simply by removing the redundant rounding performed by
acpi_os_map_iomem(), as it appears to be the only place where the
arguments to a call to acpi_os_ioremap() are rounded up. So omit the
rounding in the call, and instead, apply the necessary offset to the
result of kmap().
Fixes: 1583052d111f ("arm64/acpi: disallow AML memory opregions to access kernel memory")
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
drivers/acpi/osl.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
index 6ad8cb05f672..55dbdbbae3be 100644
--- a/drivers/acpi/osl.c
+++ b/drivers/acpi/osl.c
@@ -289,7 +289,8 @@ static void __iomem *acpi_map(acpi_physical_address pg_off, unsigned long pg_sz)
if (should_use_kmap(pfn)) {
if (pg_sz > PAGE_SIZE)
return NULL;
- return (void __iomem __force *)kmap(pfn_to_page(pfn));
+ pg_off &= ~PAGE_MASK;
+ return (void __iomem __force *)(kmap(pfn_to_page(pfn)) + pg_off);
} else
return acpi_os_ioremap(pg_off, pg_sz);
}
@@ -350,7 +351,7 @@ void __iomem __ref
pg_off = round_down(phys, PAGE_SIZE);
pg_sz = round_up(phys + size, PAGE_SIZE) - pg_off;
- virt = acpi_map(pg_off, pg_sz);
+ virt = acpi_map(phys, size);
if (!virt) {
mutex_unlock(&acpi_ioremap_lock);
kfree(map);
@@ -358,7 +359,7 @@ void __iomem __ref
}
INIT_LIST_HEAD(&map->list);
- map->virt = virt;
+ map->virt = (void *)((unsigned long)virt & PAGE_MASK);
map->phys = pg_off;
map->size = pg_sz;
map->track.refcount = 1;
@@ -367,7 +368,7 @@ void __iomem __ref
out:
mutex_unlock(&acpi_ioremap_lock);
- return map->virt + (phys - map->phys);
+ return virt;
}
EXPORT_SYMBOL_GPL(acpi_os_map_iomem);
--
2.17.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next reply other threads:[~2020-08-17 12:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-17 12:04 Ard Biesheuvel [this message]
2020-08-17 12:40 ` [PATCH] ACPI: ioremap: avoid redundant rounding to OS page size Christoph Hellwig
2020-08-17 12:59 ` Ard Biesheuvel
2020-08-17 16:30 ` kernel test robot
2020-08-17 17:06 ` kernel test robot
2020-08-17 23:41 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200817120431.32233-1-ardb@kernel.org \
--to=ardb@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=lorenzo.pieralisi@arm.com \
--cc=rjw@rjwysocki.net \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).