lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <tip-6fc77525f509e16b1e909e5ffd6f9ad9dccc0f82@git.kernel.org>
Date:	Mon, 29 Feb 2016 02:57:49 -0800
From:	tip-bot for Alexander Kuleshov <tipbot@...or.com>
To:	linux-tip-commits@...r.kernel.org
Cc:	linux-kernel@...r.kernel.org, torvalds@...ux-foundation.org,
	tglx@...utronix.de, mingo@...nel.org, dyoung@...hat.com,
	hpa@...or.com, kuleshovmail@...il.com, akpm@...ux-foundation.org,
	bhe@...hat.com, bp@...e.de, peterz@...radead.org,
	msalter@...hat.com, jroedel@...e.de
Subject: [tip:x86/boot] x86/setup: Calculate ramdisk parameters only once

Commit-ID:  6fc77525f509e16b1e909e5ffd6f9ad9dccc0f82
Gitweb:     http://git.kernel.org/tip/6fc77525f509e16b1e909e5ffd6f9ad9dccc0f82
Author:     Alexander Kuleshov <kuleshovmail@...il.com>
AuthorDate: Fri, 26 Feb 2016 15:04:36 +0600
Committer:  Ingo Molnar <mingo@...nel.org>
CommitDate: Sat, 27 Feb 2016 12:52:27 +0100

x86/setup: Calculate ramdisk parameters only once

The check and definitions related to ramdisk are similar in the
early_reserve_initrd() and reserve_initrd() functions.

This patch introduces 'struct ramdisk' which contains information
about initrd. This structure will be filled in the setup_arch()
and passed to the reserve_initrd() and relocate_initrd() functions.

This allows us to not get/check ramdisk parameters from the bootparams
every time in the early_reserve_initrd(), reserve_initrd() and
relocate_initrd() function.

Signed-off-by: Alexander Kuleshov <kuleshovmail@...il.com>
Reviewed-by: Borislav Petkov <bp@...e.de>
Cc: Andrew Morton <akpm@...ux-foundation.org>
Cc: Baoquan He <bhe@...hat.com>
Cc: Dave Young <dyoung@...hat.com>
Cc: Joerg Roedel <jroedel@...e.de>
Cc: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Mark Salter <msalter@...hat.com>
Cc: Peter Zijlstra <peterz@...radead.org>
Cc: Thomas Gleixner <tglx@...utronix.de>
Link: http://lkml.kernel.org/r/1456477476-16415-1-git-send-email-kuleshovmail@gmail.com
[ Small readability changes. ]
Signed-off-by: Ingo Molnar <mingo@...nel.org>
---
 arch/x86/kernel/setup.c | 111 ++++++++++++++++++++++++++----------------------
 1 file changed, 61 insertions(+), 50 deletions(-)

diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index d3d80e6..5cf832c 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -169,6 +169,12 @@ static struct resource bss_resource = {
 	.flags	= IORESOURCE_BUSY | IORESOURCE_MEM
 };
 
+struct ramdisk {
+	u64 start_addr;		/* ramdisk load address */
+	u64 end_addr;		/* ramdisk end address */
+	u64 size;		/* ramdisk size */
+	bool reserve_ramdisk;	/* do initrd provided by bootloader */
+};
 
 #ifdef CONFIG_X86_32
 /* cpu data as detected by the assembly code in head.S */
@@ -309,6 +315,7 @@ static u64 __init get_ramdisk_image(void)
 
 	return ramdisk_image;
 }
+
 static u64 __init get_ramdisk_size(void)
 {
 	u64 ramdisk_size = boot_params.hdr.ramdisk_size;
@@ -318,90 +325,87 @@ static u64 __init get_ramdisk_size(void)
 	return ramdisk_size;
 }
 
-static void __init relocate_initrd(void)
+static void __init relocate_initrd(struct ramdisk *ramdisk)
 {
-	/* Assume only end is not page aligned */
-	u64 ramdisk_image = get_ramdisk_image();
-	u64 ramdisk_size  = get_ramdisk_size();
-	u64 area_size     = PAGE_ALIGN(ramdisk_size);
-
 	/* We need to move the initrd down into directly mapped mem */
 	relocated_ramdisk = memblock_find_in_range(0, PFN_PHYS(max_pfn_mapped),
-						   area_size, PAGE_SIZE);
+						   ramdisk->size, PAGE_SIZE);
 
 	if (!relocated_ramdisk)
 		panic("Cannot find place for new RAMDISK of size %lld\n",
-		      ramdisk_size);
+		      ramdisk->size);
 
 	/* Note: this includes all the mem currently occupied by
 	   the initrd, we rely on that fact to keep the data intact. */
-	memblock_reserve(relocated_ramdisk, area_size);
+	memblock_reserve(relocated_ramdisk, ramdisk->size);
 	initrd_start = relocated_ramdisk + PAGE_OFFSET;
-	initrd_end   = initrd_start + ramdisk_size;
+	initrd_end   = initrd_start + ramdisk->size;
 	printk(KERN_INFO "Allocated new RAMDISK: [mem %#010llx-%#010llx]\n",
-	       relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1);
+	       relocated_ramdisk, relocated_ramdisk + ramdisk->size - 1);
 
-	copy_from_early_mem((void *)initrd_start, ramdisk_image, ramdisk_size);
+	copy_from_early_mem((void *)initrd_start, ramdisk->start_addr, ramdisk->size);
 
 	printk(KERN_INFO "Move RAMDISK from [mem %#010llx-%#010llx] to"
 		" [mem %#010llx-%#010llx]\n",
-		ramdisk_image, ramdisk_image + ramdisk_size - 1,
-		relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1);
+		ramdisk->start_addr, ramdisk->start_addr + ramdisk->size - 1,
+		relocated_ramdisk, relocated_ramdisk + ramdisk->size - 1);
 }
 
-static void __init early_reserve_initrd(void)
+static void __init early_reserve_initrd(struct ramdisk *ramdisk)
 {
-	/* Assume only end is not page aligned */
-	u64 ramdisk_image = get_ramdisk_image();
-	u64 ramdisk_size  = get_ramdisk_size();
-	u64 ramdisk_end   = PAGE_ALIGN(ramdisk_image + ramdisk_size);
-
+	/* No initrd provided by bootloader */
 	if (!boot_params.hdr.type_of_loader ||
-	    !ramdisk_image || !ramdisk_size)
-		return;		/* No initrd provided by bootloader */
-
-	memblock_reserve(ramdisk_image, ramdisk_end - ramdisk_image);
+	    !ramdisk->start_addr ||
+	    !ramdisk->size)
+		ramdisk->reserve_ramdisk = false;
+	else
+		memblock_reserve(ramdisk->start_addr, ramdisk->size);
 }
-static void __init reserve_initrd(void)
+
+static void __init reserve_initrd(struct ramdisk *ramdisk)
 {
-	/* Assume only end is not page aligned */
-	u64 ramdisk_image = get_ramdisk_image();
-	u64 ramdisk_size  = get_ramdisk_size();
-	u64 ramdisk_end   = PAGE_ALIGN(ramdisk_image + ramdisk_size);
 	u64 mapped_size;
 
-	if (!boot_params.hdr.type_of_loader ||
-	    !ramdisk_image || !ramdisk_size)
-		return;		/* No initrd provided by bootloader */
+	if (!ramdisk->reserve_ramdisk)
+		return;
 
 	initrd_start = 0;
 
 	mapped_size = memblock_mem_size(max_pfn_mapped);
-	if (ramdisk_size >= (mapped_size>>1))
+	if (ramdisk->size >= (mapped_size >> 1))
 		panic("initrd too large to handle, "
-		       "disabling initrd (%lld needed, %lld available)\n",
-		       ramdisk_size, mapped_size>>1);
+		      "disabling initrd (%lld needed, %lld available)\n",
+		       ramdisk->size, mapped_size >> 1);
 
-	printk(KERN_INFO "RAMDISK: [mem %#010llx-%#010llx]\n", ramdisk_image,
-			ramdisk_end - 1);
+	printk(KERN_INFO "RAMDISK: [mem %#010llx-%#010llx]\n",
+		ramdisk->start_addr, ramdisk->end_addr - 1);
 
-	if (pfn_range_is_mapped(PFN_DOWN(ramdisk_image),
-				PFN_DOWN(ramdisk_end))) {
+	if (pfn_range_is_mapped(PFN_DOWN(ramdisk->start_addr),
+				PFN_DOWN(ramdisk->end_addr))) {
 		/* All are mapped, easy case */
-		initrd_start = ramdisk_image + PAGE_OFFSET;
-		initrd_end = initrd_start + ramdisk_size;
+		initrd_start = ramdisk->start_addr + PAGE_OFFSET;
+		initrd_end = initrd_start + ramdisk->size;
 		return;
 	}
 
-	relocate_initrd();
+	relocate_initrd(ramdisk);
 
-	memblock_free(ramdisk_image, ramdisk_end - ramdisk_image);
+	memblock_free(ramdisk->start_addr, ramdisk->size);
 }
 #else
-static void __init early_reserve_initrd(void)
+static u64 __init get_ramdisk_image(void)
+{
+	return 0;
+}
+static u64 __init get_ramdisk_size(void)
 {
+	return 0;
 }
-static void __init reserve_initrd(void)
+static void __init early_reserve_initrd(struct ramdisk *ramdisk)
+{
+
+}
+static void __init reserve_initrd(struct ramdisk *ramdisk)
 {
 }
 #endif /* CONFIG_BLK_DEV_INITRD */
@@ -844,13 +848,20 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
  *
  * Note: On x86_64, fixmaps are ready for use even before this is called.
  */
-
 void __init setup_arch(char **cmdline_p)
 {
-	memblock_reserve(__pa_symbol(_text),
-			 (unsigned long)__bss_stop - (unsigned long)_text);
+	struct ramdisk ramdisk = {
+	       .start_addr	= get_ramdisk_image(),
+	       .size		= PAGE_ALIGN(get_ramdisk_size()),
+	       .reserve_ramdisk	= true
+	};
+
+	/* Assume end is not page aligned */
+	ramdisk.end_addr = PAGE_ALIGN(ramdisk.start_addr + ramdisk.size);
+
+	memblock_reserve(__pa_symbol(_text), (unsigned long)(__bss_stop - _text));
 
-	early_reserve_initrd();
+	early_reserve_initrd(&ramdisk);
 
 	/*
 	 * At this point everything still needed from the boot loader
@@ -1135,7 +1146,7 @@ void __init setup_arch(char **cmdline_p)
 	/* Allocate bigger log buffer */
 	setup_log_buf(1);
 
-	reserve_initrd();
+	reserve_initrd(&ramdisk);
 
 #if defined(CONFIG_ACPI) && defined(CONFIG_BLK_DEV_INITRD)
 	acpi_initrd_override((void *)initrd_start, initrd_end - initrd_start);

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ