Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1208272 > unrolled thread
| Started by | Mark Salter <msalter@redhat.com> |
|---|---|
| First post | 2015-08-16 23:00 +0200 |
| Last post | 2015-08-17 15:40 +0200 |
| Articles | 3 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH V3 2/3] arm64: support initrd outside kernel linear map Mark Salter <msalter@redhat.com> - 2015-08-16 23:00 +0200
Re: [PATCH V3 2/3] arm64: support initrd outside kernel linear map Will Deacon <will.deacon@arm.com> - 2015-08-17 13:30 +0200
Re: [PATCH V3 2/3] arm64: support initrd outside kernel linear map Mark Salter <msalter@redhat.com> - 2015-08-17 15:40 +0200
| From | Mark Salter <msalter@redhat.com> |
|---|---|
| Date | 2015-08-16 23:00 +0200 |
| Subject | [PATCH V3 2/3] arm64: support initrd outside kernel linear map |
| Message-ID | <pYdc6-2Wi-19@gated-at.bofh.it> |
The use of mem= could leave part or all of the initrd outside of
the kernel linear map. This will lead to an error when unpacking
the initrd and a probable failure to boot. This patch catches that
situation and relocates the initrd to be fully within the linear
map.
Signed-off-by: Mark Salter <msalter@redhat.com>
---
arch/arm64/kernel/setup.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 59 insertions(+)
diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
index f3067d4..5f45fd9 100644
--- a/arch/arm64/kernel/setup.c
+++ b/arch/arm64/kernel/setup.c
@@ -359,6 +359,64 @@ static void __init request_standard_resources(void)
}
}
+#ifdef CONFIG_BLK_DEV_INITRD
+/*
+ * Relocate initrd if it is not completely within the linear mapping.
+ * This would be the case if mem= cuts out all or part of it.
+ */
+static void __init relocate_initrd(void)
+{
+ phys_addr_t orig_start = __virt_to_phys(initrd_start);
+ phys_addr_t orig_end = __virt_to_phys(initrd_end);
+ phys_addr_t ram_end = memblock_end_of_DRAM();
+ phys_addr_t new_start;
+ unsigned long size, to_free = 0;
+ void *dest;
+
+ if (orig_end <= ram_end)
+ return;
+
+ /* Note if any of original initrd will freeing below */
+ if (orig_start < ram_end)
+ to_free = ram_end - orig_start;
+
+ size = orig_end - orig_start;
+
+ /* initrd needs to be relocated completely inside linear mapping */
+ new_start = memblock_find_in_range(0, PFN_PHYS(max_pfn),
+ size, PAGE_SIZE);
+ if (!new_start)
+ panic("Cannot relocate initrd of size %ld\n", size);
+ memblock_reserve(new_start, size);
+
+ initrd_start = __phys_to_virt(new_start);
+ initrd_end = initrd_start + size;
+
+ pr_info("Moving initrd from [%llx-%llx] to [%llx-%llx]\n",
+ orig_start, orig_start + size - 1,
+ new_start, new_start + size - 1);
+
+ dest = (void *)initrd_start;
+
+ if (to_free) {
+ memcpy(dest, (void *)__phys_to_virt(orig_start), to_free);
+ dest += to_free;
+ }
+
+ copy_from_early_mem(dest, orig_start + to_free, size - to_free);
+
+ if (to_free) {
+ pr_info("Freeing original RAMDISK from [%llx-%llx]\n",
+ orig_start, orig_start + to_free - 1);
+ memblock_free(orig_start, to_free);
+ }
+}
+#else
+static inline void __init reserve_initrd(void)
+{
+}
+#endif
+
u64 __cpu_logical_map[NR_CPUS] = { [0 ... NR_CPUS-1] = INVALID_HWID };
void __init setup_arch(char **cmdline_p)
@@ -392,6 +450,7 @@ void __init setup_arch(char **cmdline_p)
acpi_boot_table_init();
paging_init();
+ relocate_initrd();
request_standard_resources();
early_ioremap_reset();
--
2.4.3
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [next] | [standalone]
| From | Will Deacon <will.deacon@arm.com> |
|---|---|
| Date | 2015-08-17 13:30 +0200 |
| Message-ID | <pYqM1-5T7-7@gated-at.bofh.it> |
| In reply to | #1208272 |
Hi Mark,
On Sun, Aug 16, 2015 at 09:49:27PM +0100, Mark Salter wrote:
> The use of mem= could leave part or all of the initrd outside of
> the kernel linear map. This will lead to an error when unpacking
> the initrd and a probable failure to boot. This patch catches that
> situation and relocates the initrd to be fully within the linear
> map.
>
> Signed-off-by: Mark Salter <msalter@redhat.com>
> ---
> arch/arm64/kernel/setup.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 59 insertions(+)
>
> diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
> index f3067d4..5f45fd9 100644
> --- a/arch/arm64/kernel/setup.c
> +++ b/arch/arm64/kernel/setup.c
> @@ -359,6 +359,64 @@ static void __init request_standard_resources(void)
> }
> }
>
> +#ifdef CONFIG_BLK_DEV_INITRD
> +/*
> + * Relocate initrd if it is not completely within the linear mapping.
> + * This would be the case if mem= cuts out all or part of it.
> + */
> +static void __init relocate_initrd(void)
> +{
> + phys_addr_t orig_start = __virt_to_phys(initrd_start);
> + phys_addr_t orig_end = __virt_to_phys(initrd_end);
Any particular reason to use the __* variants here?
> + phys_addr_t ram_end = memblock_end_of_DRAM();
> + phys_addr_t new_start;
> + unsigned long size, to_free = 0;
> + void *dest;
> +
> + if (orig_end <= ram_end)
> + return;
> +
> + /* Note if any of original initrd will freeing below */
The comment doesn't make sense.
> + if (orig_start < ram_end)
> + to_free = ram_end - orig_start;
> +
> + size = orig_end - orig_start;
> +
> + /* initrd needs to be relocated completely inside linear mapping */
> + new_start = memblock_find_in_range(0, PFN_PHYS(max_pfn),
> + size, PAGE_SIZE);
> + if (!new_start)
> + panic("Cannot relocate initrd of size %ld\n", size);
> + memblock_reserve(new_start, size);
> +
> + initrd_start = __phys_to_virt(new_start);
> + initrd_end = initrd_start + size;
> +
> + pr_info("Moving initrd from [%llx-%llx] to [%llx-%llx]\n",
> + orig_start, orig_start + size - 1,
> + new_start, new_start + size - 1);
> +
> + dest = (void *)initrd_start;
> +
> + if (to_free) {
> + memcpy(dest, (void *)__phys_to_virt(orig_start), to_free);
> + dest += to_free;
> + }
> +
> + copy_from_early_mem(dest, orig_start + to_free, size - to_free);
> +
> + if (to_free) {
> + pr_info("Freeing original RAMDISK from [%llx-%llx]\n",
> + orig_start, orig_start + to_free - 1);
> + memblock_free(orig_start, to_free);
> + }
> +}
> +#else
> +static inline void __init reserve_initrd(void)
relocate_initrd ?
Will
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Mark Salter <msalter@redhat.com> |
|---|---|
| Date | 2015-08-17 15:40 +0200 |
| Message-ID | <pYsNP-jx-1@gated-at.bofh.it> |
| In reply to | #1208537 |
On Mon, 2015-08-17 at 12:22 +0100, Will Deacon wrote:
> Hi Mark,
>
> On Sun, Aug 16, 2015 at 09:49:27PM +0100, Mark Salter wrote:
> > The use of mem= could leave part or all of the initrd outside of
> > the kernel linear map. This will lead to an error when unpacking
> > the initrd and a probable failure to boot. This patch catches that
> > situation and relocates the initrd to be fully within the linear
> > map.
> >
> > Signed-off-by: Mark Salter <msalter@redhat.com>
> > ---
> > arch/arm64/kernel/setup.c | 59
> > +++++++++++++++++++++++++++++++++++++++++++++++
> > 1 file changed, 59 insertions(+)
> >
> > diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
> > index f3067d4..5f45fd9 100644
> > --- a/arch/arm64/kernel/setup.c
> > +++ b/arch/arm64/kernel/setup.c
> > @@ -359,6 +359,64 @@ static void __init
> > request_standard_resources(void)
> > }
> > }
> >
> > +#ifdef CONFIG_BLK_DEV_INITRD
> > +/*
> > + * Relocate initrd if it is not completely within the linear mapping.
> > + * This would be the case if mem= cuts out all or part of it.
> > + */
> > +static void __init relocate_initrd(void)
> > +{
> > + phys_addr_t orig_start = __virt_to_phys(initrd_start);
> > + phys_addr_t orig_end = __virt_to_phys(initrd_end);
>
> Any particular reason to use the __* variants here?
To avoid need to cast initrd_{start,end} to pointer.
>
> > + phys_addr_t ram_end = memblock_end_of_DRAM();
> > + phys_addr_t new_start;
> > + unsigned long size, to_free = 0;
> > + void *dest;
> > +
> > + if (orig_end <= ram_end)
> > + return;
> > +
> > + /* Note if any of original initrd will freeing below */
>
> The comment doesn't make sense.
No it doesn't.
>
> > + if (orig_start < ram_end)
> > + to_free = ram_end - orig_start;
> > +
> > + size = orig_end - orig_start;
> > +
> > + /* initrd needs to be relocated completely inside linear
> > mapping */
> > + new_start = memblock_find_in_range(0, PFN_PHYS(max_pfn),
> > + size, PAGE_SIZE);
> > + if (!new_start)
> > + panic("Cannot relocate initrd of size %ld\n", size);
> > + memblock_reserve(new_start, size);
> > +
> > + initrd_start = __phys_to_virt(new_start);
> > + initrd_end = initrd_start + size;
> > +
> > + pr_info("Moving initrd from [%llx-%llx] to [%llx-%llx]\n",
> > + orig_start, orig_start + size - 1,
> > + new_start, new_start + size - 1);
> > +
> > + dest = (void *)initrd_start;
> > +
> > + if (to_free) {
> > + memcpy(dest, (void *)__phys_to_virt(orig_start),
> > to_free);
> > + dest += to_free;
> > + }
> > +
> > + copy_from_early_mem(dest, orig_start + to_free, size -
> > to_free);
> > +
> > + if (to_free) {
> > + pr_info("Freeing original RAMDISK from [%llx-%llx]\n",
> > + orig_start, orig_start + to_free - 1);
> > + memblock_free(orig_start, to_free);
> > + }
> > +}
> > +#else
> > +static inline void __init reserve_initrd(void)
>
> relocate_initrd ?
Yes
Thanks, will fix that and the comment.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web