linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [x86/KASLR] ed9f007ee6: -- System halted
       [not found] <57712812.r6MdDSquaCRYkMnh%xiaolong.ye@intel.com>
@ 2016-06-27 18:59 ` Yinghai Lu
       [not found]   ` <20160628054354.GA9620@yexl-desktop>
  2016-07-01  7:50 ` Baoquan He
  1 sibling, 1 reply; 12+ messages in thread
From: Yinghai Lu @ 2016-06-27 18:59 UTC (permalink / raw)
  To: kernel test robot
  Cc: Kees Cook, LKP ML, tipbuild, LKML, Thomas Gleixner,
	Peter Zijlstra, Linus Torvalds, Josh Poimboeuf, H.J. Lu,
	H. Peter Anvin, Dmitry Vyukov, Denys Vlasenko, Brian Gerst,
	Borislav Petkov, Baoquan He, Andy Lutomirski, Andrey Ryabinin,
	Andrew Morton, Ingo Molnar

[-- Attachment #1: Type: text/plain, Size: 442 bytes --]

output is:

early console in setup code
early console in extract_kernel
input_data: 0x0000000008fbb276
input_len: 0x00000000018c6e00
output: 0x0000000001000000
output_len: 0x0000000009867c98
kernel_total_size: 0x0000000008769000
booted via startup_32()
Physical KASLR using RDTSC...
Virtual KASLR using RDTSC...

Decompressing Linux...

XZ-compressed data is corrupt

 -- System halted

Can you apply attached debug patch and send out dmesg?

[-- Attachment #2: revert_79063a7.patch --]
[-- Type: text/x-patch, Size: 2909 bytes --]

---
 arch/x86/boot/compressed/misc.c      |   24 ------------------------
 arch/x86/boot/compressed/misc.h      |   10 ----------
 arch/x86/boot/compressed/pagetable.c |    2 --
 3 files changed, 36 deletions(-)

Index: linux-2.6/arch/x86/boot/compressed/misc.c
===================================================================
--- linux-2.6.orig/arch/x86/boot/compressed/misc.c
+++ linux-2.6/arch/x86/boot/compressed/misc.c
@@ -152,23 +152,6 @@ void __putstr(const char *s)
 	outb(0xff & (pos >> 1), vidport+1);
 }
 
-void __puthex(unsigned long value)
-{
-	char alpha[2] = "0";
-	int bits;
-
-	for (bits = sizeof(value) * 8 - 4; bits >= 0; bits -= 4) {
-		unsigned long digit = (value >> bits) & 0xf;
-
-		if (digit < 0xA)
-			alpha[0] = '0' + digit;
-		else
-			alpha[0] = 'a' + (digit - 0xA);
-
-		__putstr(alpha);
-	}
-}
-
 #if CONFIG_X86_NEED_RELOCS
 static void handle_relocations(void *output, unsigned long output_len,
 			       unsigned long virt_addr)
@@ -365,13 +348,6 @@ asmlinkage __visible void *extract_kerne
 	free_mem_ptr     = heap;	/* Heap */
 	free_mem_end_ptr = heap + BOOT_HEAP_SIZE;
 
-	/* Report initial kernel position details. */
-	debug_putaddr(input_data);
-	debug_putaddr(input_len);
-	debug_putaddr(output);
-	debug_putaddr(output_len);
-	debug_putaddr(kernel_total_size);
-
 	/*
 	 * The memory hole needed for the kernel is the larger of either
 	 * the entire decompressed kernel plus relocation table, or the
Index: linux-2.6/arch/x86/boot/compressed/misc.h
===================================================================
--- linux-2.6.orig/arch/x86/boot/compressed/misc.h
+++ linux-2.6/arch/x86/boot/compressed/misc.h
@@ -34,27 +34,17 @@ extern memptr free_mem_ptr;
 extern memptr free_mem_end_ptr;
 extern struct boot_params *boot_params;
 void __putstr(const char *s);
-void __puthex(unsigned long value);
 #define error_putstr(__x)  __putstr(__x)
 #define error_puthex(__x)  __puthex(__x)
 
 #ifdef CONFIG_X86_VERBOSE_BOOTUP
 
 #define debug_putstr(__x)  __putstr(__x)
-#define debug_puthex(__x)  __puthex(__x)
-#define debug_putaddr(__x) { \
-		debug_putstr(#__x ": 0x"); \
-		debug_puthex((unsigned long)(__x)); \
-		debug_putstr("\n"); \
-	}
 
 #else
 
 static inline void debug_putstr(const char *s)
 { }
-static inline void debug_puthex(const char *s)
-{ }
-#define debug_putaddr(x) /* */
 
 #endif
 
Index: linux-2.6/arch/x86/boot/compressed/pagetable.c
===================================================================
--- linux-2.6.orig/arch/x86/boot/compressed/pagetable.c
+++ linux-2.6/arch/x86/boot/compressed/pagetable.c
@@ -45,8 +45,6 @@ static void *alloc_pgt_page(void *contex
 	/* Validate there is space available for a new page. */
 	if (pages->pgt_buf_offset >= pages->pgt_buf_size) {
 		debug_putstr("out of pgt_buf in " __FILE__ "!?\n");
-		debug_putaddr(pages->pgt_buf_offset);
-		debug_putaddr(pages->pgt_buf_size);
 		return NULL;
 	}
 

[-- Attachment #3: early_console_more_2_2x.patch --]
[-- Type: text/x-patch, Size: 2026 bytes --]

Subject: [PATCH] x86, boot: Add printf support for early console in compressed/misc.c

Reuse printf.c in x86 setup code.

Later decompresser code could print out more info for debug info.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>

---
 arch/x86/boot/compressed/Makefile    |    1 +
 arch/x86/boot/compressed/misc.h      |    7 +++++++
 arch/x86/boot/compressed/pagetable.c |    4 ++++
 arch/x86/boot/compressed/printf.c    |    5 +++++
 4 files changed, 17 insertions(+)

Index: linux-2.6/arch/x86/boot/compressed/Makefile
===================================================================
--- linux-2.6.orig/arch/x86/boot/compressed/Makefile
+++ linux-2.6/arch/x86/boot/compressed/Makefile
@@ -73,6 +73,7 @@ vmlinux-objs-y := $(obj)/vmlinux.lds $(o
 	$(obj)/string.o $(obj)/cmdline.o $(obj)/error.o \
 	$(obj)/piggy.o $(obj)/cpuflags.o
 
+vmlinux-objs-$(CONFIG_X86_VERBOSE_BOOTUP) += $(obj)/printf.o
 vmlinux-objs-$(CONFIG_EARLY_PRINTK) += $(obj)/early_serial_console.o
 vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/kaslr.o
 ifdef CONFIG_X86_64
Index: linux-2.6/arch/x86/boot/compressed/printf.c
===================================================================
--- /dev/null
+++ linux-2.6/arch/x86/boot/compressed/printf.c
@@ -0,0 +1,5 @@
+#include "misc.h"
+
+#define puts(__x)  __putstr(__x)
+
+#include "../printf.c"
Index: linux-2.6/arch/x86/boot/compressed/misc.h
===================================================================
--- linux-2.6.orig/arch/x86/boot/compressed/misc.h
+++ linux-2.6/arch/x86/boot/compressed/misc.h
@@ -37,14 +37,21 @@ void __putstr(const char *s);
 #define error_putstr(__x)  __putstr(__x)
 #define error_puthex(__x)  __puthex(__x)
 
+/* printf.c */
+int sprintf(char *buf, const char *fmt, ...);
+int printf(const char *fmt, ...);
+
 #ifdef CONFIG_X86_VERBOSE_BOOTUP
 
 #define debug_putstr(__x)  __putstr(__x)
+#define debug_printf printf
 
 #else
 
 static inline void debug_putstr(const char *s)
 { }
+static inline int debug_printf(const char *fmt, ...)
+{ }
 
 #endif
 

[-- Attachment #4: early_console_more_2_2x_add_0.patch --]
[-- Type: text/x-patch, Size: 3151 bytes --]

Subject: [PATCH] x86, boot: Add print out for input/output info early console in compressed/misc.c

Use printf to print out decompress_kernel input and output info.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>

---
 arch/x86/boot/compressed/misc.c |   42 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 40 insertions(+), 2 deletions(-)

Index: linux-2.6/arch/x86/boot/compressed/misc.c
===================================================================
--- linux-2.6.orig/arch/x86/boot/compressed/misc.c
+++ linux-2.6/arch/x86/boot/compressed/misc.c
@@ -322,6 +322,8 @@ asmlinkage __visible void *extract_kerne
 {
 	const unsigned long kernel_total_size = VO__end - VO__text;
 	unsigned long virt_addr = (unsigned long)output;
+	unsigned long output_run_size = max(output_len, kernel_total_size);
+	unsigned long init_size;
 
 	/* Retain x86 boot parameters pointer passed from startup_32/64. */
 	boot_params = rmode;
@@ -348,6 +350,37 @@ asmlinkage __visible void *extract_kerne
 	free_mem_ptr     = heap;	/* Heap */
 	free_mem_end_ptr = heap + BOOT_HEAP_SIZE;
 
+	init_size = boot_params->hdr.init_size;
+	debug_putstr("decompress_kernel:\n");
+	debug_printf("       input: [0x%010lx-0x%010lx]\n",
+		 (unsigned long)input_data,
+		 (unsigned long)input_data + input_len - 1);
+	debug_printf("      output: [0x%010lx-0x%010lx] 0x%08lx: output_len\n",
+		 (unsigned long)output,
+		 (unsigned long)output + output_len - 1,
+		 (unsigned long)output_len);
+	debug_printf("              [0x%010lx-0x%010lx] 0x%08lx: run_size\n",
+		 (unsigned long)output,
+		 (unsigned long)output + kernel_total_size - 1,
+		 (unsigned long)kernel_total_size);
+	debug_printf("              [0x%010lx-0x%010lx] 0x%08lx: output_run_size\n",
+		 (unsigned long)output,
+		 (unsigned long)output + output_run_size - 1,
+		 (unsigned long)output_run_size);
+	debug_printf("              [0x%010lx-0x%010lx] 0x%08lx: init_size\n",
+		 (unsigned long)output,
+		 (unsigned long)output + init_size - 1,
+		 (unsigned long)init_size);
+	debug_printf("ZO text/data: [0x%010lx-0x%010lx]\n",
+		 (unsigned long)input_data + input_len,
+		 (unsigned long)output + init_size - 1);
+	debug_printf("     ZO heap: [0x%010lx-0x%010lx]\n",
+		 (unsigned long)heap,
+		 (unsigned long)heap + BOOT_HEAP_SIZE - 1);
+	debug_printf("  VO bss/brk: [0x%010lx-0x%010lx]\n",
+		 (unsigned long)output + (VO___bss_start - VO__text),
+		 (unsigned long)output + kernel_total_size - 1);
+
 	/*
 	 * The memory hole needed for the kernel is the larger of either
 	 * the entire decompressed kernel plus relocation table, or the
@@ -355,8 +388,13 @@ asmlinkage __visible void *extract_kerne
 	 */
 	choose_random_location((unsigned long)input_data, input_len,
 				(unsigned long *)&output,
-				max(output_len, kernel_total_size),
-				&virt_addr);
+				output_run_size, &virt_addr);
+
+	if ((unsigned long)output != virt_addr)
+		debug_printf("  new output: [0x%010lx-0x%010lx] 0x%08lx: output_run_size\n",
+			 virt_addr,
+			 virt_addr + output_run_size - 1,
+			 output_run_size);
 
 	/* Validate memory location choices. */
 	if ((unsigned long)output & (MIN_KERNEL_ALIGN - 1))

[-- Attachment #5: early_console_more_2_2x_add_1.patch --]
[-- Type: text/x-patch, Size: 1695 bytes --]

Subject: [PATCH] x86, boot: Add more debug printout in compressed/misc.c

with support that use printf.c in x86 setup code.
print out more info for debug info.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>


---
 arch/x86/boot/compressed/misc.c |   12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

Index: linux-2.6/arch/x86/boot/compressed/misc.c
===================================================================
--- linux-2.6.orig/arch/x86/boot/compressed/misc.c
+++ linux-2.6/arch/x86/boot/compressed/misc.c
@@ -287,7 +287,7 @@ static void parse_elf(void *output)
 		return;
 	}
 
-	debug_putstr("Parsing ELF... ");
+	debug_putstr("Parsing ELF...\n");
 
 	phdrs = malloc(sizeof(*phdrs) * ehdr.e_phnum);
 	if (!phdrs)
@@ -307,6 +307,11 @@ static void parse_elf(void *output)
 			dest = (void *)(phdr->p_paddr);
 #endif
 			memmove(dest, output + phdr->p_offset, phdr->p_filesz);
+			debug_printf("   parse_elf: [0x%010lx-0x%010lx] <=== [0x%010lx-0x%010lx]\n",
+				(unsigned long)dest,
+				(unsigned long)dest + phdr->p_filesz - 1,
+				(unsigned long)output + phdr->p_offset,
+				(unsigned long)output + phdr->p_offset + phdr->p_filesz - 1);
 			break;
 		default: /* Ignore other PT_* */ break;
 		}
@@ -431,6 +436,11 @@ asmlinkage __visible void *extract_kerne
 		error("Wrong destination address");
 #endif
 
+	debug_printf("  decompress: [0x%010lx-0x%010lx] <=== [0x%010lx-0x%010lx]\n",
+		(unsigned long)output,
+		(unsigned long)output + output_len - 1,
+		(unsigned long)input_data,
+		(unsigned long)input_data + input_len - 1);
 	debug_putstr("\nDecompressing Linux... ");
 	__decompress(input_data, input_len, NULL, NULL, output, output_len,
 			NULL, error);

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [x86/KASLR] ed9f007ee6: -- System halted
       [not found]     ` <CAE9FiQV50UhjJDH89C_T7f2vxFDm7Hpjn78ZKtnfeygQcsf23w@mail.gmail.com>
@ 2016-06-29 20:08       ` Yinghai Lu
  2016-06-29 20:29         ` [LKP] " Huang, Ying
  0 siblings, 1 reply; 12+ messages in thread
From: Yinghai Lu @ 2016-06-29 20:08 UTC (permalink / raw)
  To: Ye Xiaolong; +Cc: LKP ML, Linux Kernel Mailing List

[-- Attachment #1: Type: text/plain, Size: 1120 bytes --]

On Tue, Jun 28, 2016 at 12:49 PM, Yinghai Lu <yinghai@kernel.org> wrote:
> On Mon, Jun 27, 2016 at 10:43 PM, Ye Xiaolong <xiaolong.ye@intel.com> wrote:
>> On Mon, Jun 27, 2016 at 11:59:37AM -0700, Yinghai Lu wrote:
>>>output is:
>>>
>>>early console in setup code
>>>early console in extract_kernel
>>>input_data: 0x0000000008fbb276
>>>input_len: 0x00000000018c6e00
>>>output: 0x0000000001000000
>>>output_len: 0x0000000009867c98
>>>kernel_total_size: 0x0000000008769000
>>>booted via startup_32()
>>>Physical KASLR using RDTSC...
>>>Virtual KASLR using RDTSC...
>>>
>>>Decompressing Linux...
>>>
>>>XZ-compressed data is corrupt
>>>
>>> -- System halted
>>>
>>>Can you apply attached debug patch and send out dmesg?
>>
>> There are 4 patches you attached, do you mean to apply them all based on
>> commit ed9f007ee6? I tried and seemed they can't apply clearly on it.
>

Please check attached updated debug patches.

You should apply them after ed9f007ee6 in following sequence

revert_79063a7.patch
early_console_more_2_2x.patch
early_console_more_2_2x_add_0.patch
early_console_more_2_2x_add_1.patch

Thanks

Yinghai

[-- Attachment #2: revert_79063a7.patch --]
[-- Type: text/x-patch, Size: 2909 bytes --]

---
 arch/x86/boot/compressed/misc.c      |   24 ------------------------
 arch/x86/boot/compressed/misc.h      |   10 ----------
 arch/x86/boot/compressed/pagetable.c |    2 --
 3 files changed, 36 deletions(-)

Index: linux-2.6/arch/x86/boot/compressed/misc.c
===================================================================
--- linux-2.6.orig/arch/x86/boot/compressed/misc.c
+++ linux-2.6/arch/x86/boot/compressed/misc.c
@@ -152,23 +152,6 @@ void __putstr(const char *s)
 	outb(0xff & (pos >> 1), vidport+1);
 }
 
-void __puthex(unsigned long value)
-{
-	char alpha[2] = "0";
-	int bits;
-
-	for (bits = sizeof(value) * 8 - 4; bits >= 0; bits -= 4) {
-		unsigned long digit = (value >> bits) & 0xf;
-
-		if (digit < 0xA)
-			alpha[0] = '0' + digit;
-		else
-			alpha[0] = 'a' + (digit - 0xA);
-
-		__putstr(alpha);
-	}
-}
-
 #if CONFIG_X86_NEED_RELOCS
 static void handle_relocations(void *output, unsigned long output_len,
 			       unsigned long virt_addr)
@@ -365,13 +348,6 @@ asmlinkage __visible void *extract_kerne
 	free_mem_ptr     = heap;	/* Heap */
 	free_mem_end_ptr = heap + BOOT_HEAP_SIZE;
 
-	/* Report initial kernel position details. */
-	debug_putaddr(input_data);
-	debug_putaddr(input_len);
-	debug_putaddr(output);
-	debug_putaddr(output_len);
-	debug_putaddr(kernel_total_size);
-
 	/*
 	 * The memory hole needed for the kernel is the larger of either
 	 * the entire decompressed kernel plus relocation table, or the
Index: linux-2.6/arch/x86/boot/compressed/misc.h
===================================================================
--- linux-2.6.orig/arch/x86/boot/compressed/misc.h
+++ linux-2.6/arch/x86/boot/compressed/misc.h
@@ -34,27 +34,17 @@ extern memptr free_mem_ptr;
 extern memptr free_mem_end_ptr;
 extern struct boot_params *boot_params;
 void __putstr(const char *s);
-void __puthex(unsigned long value);
 #define error_putstr(__x)  __putstr(__x)
 #define error_puthex(__x)  __puthex(__x)
 
 #ifdef CONFIG_X86_VERBOSE_BOOTUP
 
 #define debug_putstr(__x)  __putstr(__x)
-#define debug_puthex(__x)  __puthex(__x)
-#define debug_putaddr(__x) { \
-		debug_putstr(#__x ": 0x"); \
-		debug_puthex((unsigned long)(__x)); \
-		debug_putstr("\n"); \
-	}
 
 #else
 
 static inline void debug_putstr(const char *s)
 { }
-static inline void debug_puthex(const char *s)
-{ }
-#define debug_putaddr(x) /* */
 
 #endif
 
Index: linux-2.6/arch/x86/boot/compressed/pagetable.c
===================================================================
--- linux-2.6.orig/arch/x86/boot/compressed/pagetable.c
+++ linux-2.6/arch/x86/boot/compressed/pagetable.c
@@ -45,8 +45,6 @@ static void *alloc_pgt_page(void *contex
 	/* Validate there is space available for a new page. */
 	if (pages->pgt_buf_offset >= pages->pgt_buf_size) {
 		debug_putstr("out of pgt_buf in " __FILE__ "!?\n");
-		debug_putaddr(pages->pgt_buf_offset);
-		debug_putaddr(pages->pgt_buf_size);
 		return NULL;
 	}
 

[-- Attachment #3: early_console_more_2_2x.patch --]
[-- Type: text/x-patch, Size: 2026 bytes --]

Subject: [PATCH] x86, boot: Add printf support for early console in compressed/misc.c

Reuse printf.c in x86 setup code.

Later decompresser code could print out more info for debug info.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>

---
 arch/x86/boot/compressed/Makefile    |    1 +
 arch/x86/boot/compressed/misc.h      |    7 +++++++
 arch/x86/boot/compressed/pagetable.c |    4 ++++
 arch/x86/boot/compressed/printf.c    |    5 +++++
 4 files changed, 17 insertions(+)

Index: linux-2.6/arch/x86/boot/compressed/Makefile
===================================================================
--- linux-2.6.orig/arch/x86/boot/compressed/Makefile
+++ linux-2.6/arch/x86/boot/compressed/Makefile
@@ -73,6 +73,7 @@ vmlinux-objs-y := $(obj)/vmlinux.lds $(o
 	$(obj)/string.o $(obj)/cmdline.o $(obj)/error.o \
 	$(obj)/piggy.o $(obj)/cpuflags.o
 
+vmlinux-objs-$(CONFIG_X86_VERBOSE_BOOTUP) += $(obj)/printf.o
 vmlinux-objs-$(CONFIG_EARLY_PRINTK) += $(obj)/early_serial_console.o
 vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/kaslr.o
 ifdef CONFIG_X86_64
Index: linux-2.6/arch/x86/boot/compressed/printf.c
===================================================================
--- /dev/null
+++ linux-2.6/arch/x86/boot/compressed/printf.c
@@ -0,0 +1,5 @@
+#include "misc.h"
+
+#define puts(__x)  __putstr(__x)
+
+#include "../printf.c"
Index: linux-2.6/arch/x86/boot/compressed/misc.h
===================================================================
--- linux-2.6.orig/arch/x86/boot/compressed/misc.h
+++ linux-2.6/arch/x86/boot/compressed/misc.h
@@ -37,14 +37,21 @@ void __putstr(const char *s);
 #define error_putstr(__x)  __putstr(__x)
 #define error_puthex(__x)  __puthex(__x)
 
+/* printf.c */
+int sprintf(char *buf, const char *fmt, ...);
+int printf(const char *fmt, ...);
+
 #ifdef CONFIG_X86_VERBOSE_BOOTUP
 
 #define debug_putstr(__x)  __putstr(__x)
+#define debug_printf printf
 
 #else
 
 static inline void debug_putstr(const char *s)
 { }
+static inline int debug_printf(const char *fmt, ...)
+{ }
 
 #endif
 

[-- Attachment #4: early_console_more_2_2x_add_0.patch --]
[-- Type: text/x-patch, Size: 3299 bytes --]

Subject: [PATCH] x86, boot: Add print out for input/output info early console in compressed/misc.c

Use printf to print out decompress_kernel input and output info.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>

---
 arch/x86/boot/compressed/misc.c |   45 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 43 insertions(+), 2 deletions(-)

Index: linux-2.6/arch/x86/boot/compressed/misc.c
===================================================================
--- linux-2.6.orig/arch/x86/boot/compressed/misc.c
+++ linux-2.6/arch/x86/boot/compressed/misc.c
@@ -322,6 +322,9 @@ asmlinkage __visible void *extract_kerne
 {
 	const unsigned long kernel_total_size = VO__end - VO__text;
 	unsigned long virt_addr = (unsigned long)output;
+	unsigned char *output_orig = output;
+	unsigned long output_run_size = max(output_len, kernel_total_size);
+	unsigned long init_size;
 
 	/* Retain x86 boot parameters pointer passed from startup_32/64. */
 	boot_params = rmode;
@@ -348,6 +351,37 @@ asmlinkage __visible void *extract_kerne
 	free_mem_ptr     = heap;	/* Heap */
 	free_mem_end_ptr = heap + BOOT_HEAP_SIZE;
 
+	init_size = boot_params->hdr.init_size;
+	debug_putstr("decompress_kernel:\n");
+	debug_printf("       input: [0x%010lx-0x%010lx]\n",
+		 (unsigned long)input_data,
+		 (unsigned long)input_data + input_len - 1);
+	debug_printf("      output: [0x%010lx-0x%010lx] 0x%08lx: output_len\n",
+		 (unsigned long)output,
+		 (unsigned long)output + output_len - 1,
+		 (unsigned long)output_len);
+	debug_printf("              [0x%010lx-0x%010lx] 0x%08lx: run_size\n",
+		 (unsigned long)output,
+		 (unsigned long)output + kernel_total_size - 1,
+		 (unsigned long)kernel_total_size);
+	debug_printf("              [0x%010lx-0x%010lx] 0x%08lx: output_run_size\n",
+		 (unsigned long)output,
+		 (unsigned long)output + output_run_size - 1,
+		 (unsigned long)output_run_size);
+	debug_printf("              [0x%010lx-0x%010lx] 0x%08lx: init_size\n",
+		 (unsigned long)output,
+		 (unsigned long)output + init_size - 1,
+		 (unsigned long)init_size);
+	debug_printf("ZO text/data: [0x%010lx-0x%010lx]\n",
+		 (unsigned long)input_data + input_len,
+		 (unsigned long)output + init_size - 1);
+	debug_printf("     ZO heap: [0x%010lx-0x%010lx]\n",
+		 (unsigned long)heap,
+		 (unsigned long)heap + BOOT_HEAP_SIZE - 1);
+	debug_printf("  VO bss/brk: [0x%010lx-0x%010lx]\n",
+		 (unsigned long)output + (VO___bss_start - VO__text),
+		 (unsigned long)output + kernel_total_size - 1);
+
 	/*
 	 * The memory hole needed for the kernel is the larger of either
 	 * the entire decompressed kernel plus relocation table, or the
@@ -355,8 +389,15 @@ asmlinkage __visible void *extract_kerne
 	 */
 	choose_random_location((unsigned long)input_data, input_len,
 				(unsigned long *)&output,
-				max(output_len, kernel_total_size),
-				&virt_addr);
+				output_run_size, &virt_addr);
+
+	if (output != output_orig)
+		debug_printf("  new output: [0x%010lx-0x%010lx] 0x%08lx: output_run_size\n",
+			 (unsigned long)output,
+			 (unsigned long)output + output_run_size - 1,
+			 output_run_size);
+	if ((unsigned long)output != virt_addr)
+		debug_printf("   virt_addr: 0x%010lx\n", virt_addr);
 
 	/* Validate memory location choices. */
 	if ((unsigned long)output & (MIN_KERNEL_ALIGN - 1))

[-- Attachment #5: early_console_more_2_2x_add_1.patch --]
[-- Type: text/x-patch, Size: 1726 bytes --]

Subject: [PATCH] x86, boot: Add more debug printout in compressed/misc.c

with support that use printf.c in x86 setup code.
print out more info for debug info.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>


---
 arch/x86/boot/compressed/misc.c |   12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

Index: linux-2.6/arch/x86/boot/compressed/misc.c
===================================================================
--- linux-2.6.orig/arch/x86/boot/compressed/misc.c
+++ linux-2.6/arch/x86/boot/compressed/misc.c
@@ -269,7 +269,7 @@ static void parse_elf(void *output)
 		return;
 	}
 
-	debug_putstr("Parsing ELF... ");
+	debug_putstr("Parsing ELF...\n");
 
 	phdrs = malloc(sizeof(*phdrs) * ehdr.e_phnum);
 	if (!phdrs)
@@ -289,6 +289,11 @@ static void parse_elf(void *output)
 			dest = (void *)(phdr->p_paddr);
 #endif
 			memmove(dest, output + phdr->p_offset, phdr->p_filesz);
+			debug_printf("   parse_elf: [0x%010lx-0x%010lx] <=== [0x%010lx-0x%010lx]\n",
+				(unsigned long)dest,
+				(unsigned long)dest + phdr->p_filesz - 1,
+				(unsigned long)output + phdr->p_offset,
+				(unsigned long)output + phdr->p_offset + phdr->p_filesz - 1);
 			break;
 		default: /* Ignore other PT_* */ break;
 		}
@@ -418,6 +423,11 @@ asmlinkage __visible void *extract_kerne
 		error("Destination virtual address changed when not relocatable");
 #endif
 
+	debug_printf("  decompress: [0x%010lx-0x%010lx] <=== [0x%010lx-0x%010lx]\n",
+		(unsigned long)output,
+		(unsigned long)output + output_len - 1,
+		(unsigned long)input_data,
+		(unsigned long)input_data + input_len - 1);
 	debug_putstr("\nDecompressing Linux... ");
 	__decompress(input_data, input_len, NULL, NULL, output, output_len,
 			NULL, error);

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [LKP] [x86/KASLR] ed9f007ee6: -- System halted
  2016-06-29 20:08       ` Yinghai Lu
@ 2016-06-29 20:29         ` Huang, Ying
  2016-06-30  4:49           ` Yinghai Lu
  0 siblings, 1 reply; 12+ messages in thread
From: Huang, Ying @ 2016-06-29 20:29 UTC (permalink / raw)
  To: Yinghai Lu; +Cc: Ye Xiaolong, LKP ML, Linux Kernel Mailing List

Hi, Yinghai,

Yinghai Lu <yinghai@kernel.org> writes:

> On Tue, Jun 28, 2016 at 12:49 PM, Yinghai Lu <yinghai@kernel.org> wrote:
>> On Mon, Jun 27, 2016 at 10:43 PM, Ye Xiaolong <xiaolong.ye@intel.com> wrote:
>>> On Mon, Jun 27, 2016 at 11:59:37AM -0700, Yinghai Lu wrote:
>>>>output is:
>>>>
>>>>early console in setup code
>>>>early console in extract_kernel
>>>>input_data: 0x0000000008fbb276
>>>>input_len: 0x00000000018c6e00
>>>>output: 0x0000000001000000
>>>>output_len: 0x0000000009867c98
>>>>kernel_total_size: 0x0000000008769000
>>>>booted via startup_32()
>>>>Physical KASLR using RDTSC...
>>>>Virtual KASLR using RDTSC...
>>>>
>>>>Decompressing Linux...
>>>>
>>>>XZ-compressed data is corrupt
>>>>
>>>> -- System halted
>>>>
>>>>Can you apply attached debug patch and send out dmesg?
>>>
>>> There are 4 patches you attached, do you mean to apply them all based on
>>> commit ed9f007ee6? I tried and seemed they can't apply clearly on it.
>>
>
> Please check attached updated debug patches.
>
> You should apply them after ed9f007ee6 in following sequence
>
> revert_79063a7.patch
> early_console_more_2_2x.patch
> early_console_more_2_2x_add_0.patch
> early_console_more_2_2x_add_1.patch

If you could provide a git branch for that, that will be easier for us
to test and more accurate for you to get the right patch to be tested.

Best Regards,
Huang, Ying

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [LKP] [x86/KASLR] ed9f007ee6: -- System halted
  2016-06-29 20:29         ` [LKP] " Huang, Ying
@ 2016-06-30  4:49           ` Yinghai Lu
  2016-06-30  6:58             ` Ye Xiaolong
  0 siblings, 1 reply; 12+ messages in thread
From: Yinghai Lu @ 2016-06-30  4:49 UTC (permalink / raw)
  To: Huang, Ying; +Cc: Ye Xiaolong, LKP ML, Linux Kernel Mailing List

On Wed, Jun 29, 2016 at 1:29 PM, Huang, Ying <ying.huang@intel.com> wrote:
> If you could provide a git branch for that, that will be easier for us
> to test and more accurate for you to get the right patch to be tested.
>

Please check

git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git
for-x86-v4.8-kaslr-debug

Thanks

Yinghai

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [LKP] [x86/KASLR] ed9f007ee6: -- System halted
  2016-06-30  4:49           ` Yinghai Lu
@ 2016-06-30  6:58             ` Ye Xiaolong
  2016-07-01  0:24               ` Yinghai Lu
  0 siblings, 1 reply; 12+ messages in thread
From: Ye Xiaolong @ 2016-06-30  6:58 UTC (permalink / raw)
  To: Yinghai Lu; +Cc: Huang, Ying, LKP ML, Linux Kernel Mailing List

[-- Attachment #1: Type: text/plain, Size: 559 bytes --]

On Wed, Jun 29, 2016 at 09:49:12PM -0700, Yinghai Lu wrote:
>On Wed, Jun 29, 2016 at 1:29 PM, Huang, Ying <ying.huang@intel.com> wrote:
>> If you could provide a git branch for that, that will be easier for us
>> to test and more accurate for you to get the right patch to be tested.
>>
>
>Please check
>
>git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git
>for-x86-v4.8-kaslr-debugy

Hi, yinghai

Attached is the dmesg for the kernel which is built based on your
for-x86-v4.8-kaslr-debug branch. 
 
Thanks,
Xiaolong
>
>Thanks
>
>Yinghai

[-- Attachment #2: dmesg-debug.xz --]
[-- Type: application/octet-stream, Size: 1192 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [LKP] [x86/KASLR] ed9f007ee6: -- System halted
  2016-06-30  6:58             ` Ye Xiaolong
@ 2016-07-01  0:24               ` Yinghai Lu
  2016-07-01  4:06                 ` Baoquan He
  0 siblings, 1 reply; 12+ messages in thread
From: Yinghai Lu @ 2016-07-01  0:24 UTC (permalink / raw)
  To: Ye Xiaolong, Baoquan He, Kees Cook
  Cc: Huang, Ying, LKP ML, Linux Kernel Mailing List

On Wed, Jun 29, 2016 at 11:58 PM, Ye Xiaolong <xiaolong.ye@intel.com> wrote:
> On Wed, Jun 29, 2016 at 09:49:12PM -0700, Yinghai Lu wrote:
>>On Wed, Jun 29, 2016 at 1:29 PM, Huang, Ying <ying.huang@intel.com> wrote:
>>> If you could provide a git branch for that, that will be easier for us
>>> to test and more accurate for you to get the right patch to be tested.
>>>
>>
>>Please check
>>
>>git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git
>>for-x86-v4.8-kaslr-debug
>
> Hi, yinghai
>
> Attached is the dmesg for the kernel which is built based on your
> for-x86-v4.8-kaslr-debug branch.

Thanks for capturing the boot log.

early console in setup code
early console in extract_kernel
decompress_kernel:
       input: [0x0008fba276-0x000a8818ed]
      output: [0x0001000000-0x000a867c97] 0x09867c98: output_len
              [0x0001000000-0x0009768fff] 0x08769000: run_size
              [0x0001000000-0x000a867c97] 0x09867c98: output_run_size
              [0x0001000000-0x000a8affff] 0x098b0000: init_size
ZO text/data: [0x000a8818ee-0x000a8affff]
     ZO heap: [0x000a888400-0x000a8983ff]
  VO bss/brk: [0x0009674000-0x0009768fff]
booted via startup_32()
Physical KASLR using RDTSC...
Virtual KASLR using RDTSC...
  new output: [0x0006600000-0x000fe67c97] 0x09867c98: output_run_size
   virt_addr:  0x0024000000
  decompress: [0x0006600000-0x000fe67c97] <=== [0x0008fba276-0x000a8818ed]

Decompressing Linux...

XZ-compressed data is corrupt

 -- System halted

Hi Kees/Baoquan,

Looks like

commit ed9f007ee68478f6a50ec9971ade25a0129a5c0e
Author: Kees Cook <keescook@chromium.org>
Date:   Wed May 25 15:45:33 2016 -0700

    x86/KASLR: Extend kernel image physical address randomization to addresses l
arger than 4G


cause choose_random_location() return new output buffer
new output: [0x0006600000-0x000fe67c97] 0x09867c98: output_run_size

that is overlapped with input data.
       input: [0x0008fba276-0x000a8818ed]
              ....-0x000a8affff] 0x098b0000: init_size

and input already is in mem_avoid.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [LKP] [x86/KASLR] ed9f007ee6: -- System halted
  2016-07-01  0:24               ` Yinghai Lu
@ 2016-07-01  4:06                 ` Baoquan He
  2016-07-01  4:46                   ` Baoquan He
  0 siblings, 1 reply; 12+ messages in thread
From: Baoquan He @ 2016-07-01  4:06 UTC (permalink / raw)
  To: Yinghai Lu
  Cc: Ye Xiaolong, Kees Cook, Huang, Ying, LKP ML, Linux Kernel Mailing List

On 06/30/16 at 05:24pm, Yinghai Lu wrote:
> On Wed, Jun 29, 2016 at 11:58 PM, Ye Xiaolong <xiaolong.ye@intel.com> wrote:
> > On Wed, Jun 29, 2016 at 09:49:12PM -0700, Yinghai Lu wrote:
> >>On Wed, Jun 29, 2016 at 1:29 PM, Huang, Ying <ying.huang@intel.com> wrote:
> >>> If you could provide a git branch for that, that will be easier for us
> >>> to test and more accurate for you to get the right patch to be tested.
> >>>
> >>
> >>Please check
> >>
> >>git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git
> >>for-x86-v4.8-kaslr-debug
> >
> > Hi, yinghai
> >
> > Attached is the dmesg for the kernel which is built based on your
> > for-x86-v4.8-kaslr-debug branch.
> 
> Thanks for capturing the boot log.
> 
> early console in setup code
> early console in extract_kernel
> decompress_kernel:
>        input: [0x0008fba276-0x000a8818ed]
>       output: [0x0001000000-0x000a867c97] 0x09867c98: output_len
>               [0x0001000000-0x0009768fff] 0x08769000: run_size
>               [0x0001000000-0x000a867c97] 0x09867c98: output_run_size
>               [0x0001000000-0x000a8affff] 0x098b0000: init_size
> ZO text/data: [0x000a8818ee-0x000a8affff]
>      ZO heap: [0x000a888400-0x000a8983ff]
>   VO bss/brk: [0x0009674000-0x0009768fff]
> booted via startup_32()
> Physical KASLR using RDTSC...
> Virtual KASLR using RDTSC...
>   new output: [0x0006600000-0x000fe67c97] 0x09867c98: output_run_size
>    virt_addr:  0x0024000000
>   decompress: [0x0006600000-0x000fe67c97] <=== [0x0008fba276-0x000a8818ed]
> 
> Decompressing Linux...
> 
> XZ-compressed data is corrupt
> 
>  -- System halted
> 
> Hi Kees/Baoquan,
> 
> Looks like
> 
> commit ed9f007ee68478f6a50ec9971ade25a0129a5c0e
> Author: Kees Cook <keescook@chromium.org>
> Date:   Wed May 25 15:45:33 2016 -0700
> 
>     x86/KASLR: Extend kernel image physical address randomization to addresses l
> arger than 4G

I know why it happened, making patch. will reply soon.

> 
> 
> cause choose_random_location() return new output buffer
> new output: [0x0006600000-0x000fe67c97] 0x09867c98: output_run_size
> 
> that is overlapped with input data.
>        input: [0x0008fba276-0x000a8818ed]
>               ....-0x000a8affff] 0x098b0000: init_size
> 
> and input already is in mem_avoid.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [LKP] [x86/KASLR] ed9f007ee6: -- System halted
  2016-07-01  4:06                 ` Baoquan He
@ 2016-07-01  4:46                   ` Baoquan He
  0 siblings, 0 replies; 12+ messages in thread
From: Baoquan He @ 2016-07-01  4:46 UTC (permalink / raw)
  To: Yinghai Lu
  Cc: Ye Xiaolong, Kees Cook, Huang, Ying, LKP ML, Linux Kernel Mailing List

On 07/01/16 at 12:06pm, Baoquan He wrote:
> On 06/30/16 at 05:24pm, Yinghai Lu wrote:
> > On Wed, Jun 29, 2016 at 11:58 PM, Ye Xiaolong <xiaolong.ye@intel.com> wrote:
> > > On Wed, Jun 29, 2016 at 09:49:12PM -0700, Yinghai Lu wrote:
> > >>On Wed, Jun 29, 2016 at 1:29 PM, Huang, Ying <ying.huang@intel.com> wrote:
> > >>> If you could provide a git branch for that, that will be easier for us
> > >>> to test and more accurate for you to get the right patch to be tested.
> > >>>
> > >>
> > >>Please check
> > >>
> > >>git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git
> > >>for-x86-v4.8-kaslr-debug
> > >
> > > Hi, yinghai
> > >
> > > Attached is the dmesg for the kernel which is built based on your
> > > for-x86-v4.8-kaslr-debug branch.
> > 
> > Thanks for capturing the boot log.
> > 
> > early console in setup code
> > early console in extract_kernel
> > decompress_kernel:
> >        input: [0x0008fba276-0x000a8818ed]
> >       output: [0x0001000000-0x000a867c97] 0x09867c98: output_len
> >               [0x0001000000-0x0009768fff] 0x08769000: run_size
> >               [0x0001000000-0x000a867c97] 0x09867c98: output_run_size
> >               [0x0001000000-0x000a8affff] 0x098b0000: init_size
> > ZO text/data: [0x000a8818ee-0x000a8affff]
> >      ZO heap: [0x000a888400-0x000a8983ff]
> >   VO bss/brk: [0x0009674000-0x0009768fff]
> > booted via startup_32()
> > Physical KASLR using RDTSC...
> > Virtual KASLR using RDTSC...
> >   new output: [0x0006600000-0x000fe67c97] 0x09867c98: output_run_size
> >    virt_addr:  0x0024000000
> >   decompress: [0x0006600000-0x000fe67c97] <=== [0x0008fba276-0x000a8818ed]
> > 
> > Decompressing Linux...
> > 
> > XZ-compressed data is corrupt
> > 
> >  -- System halted
> > 
> > Hi Kees/Baoquan,
> > 
> > Looks like
> > 
> > commit ed9f007ee68478f6a50ec9971ade25a0129a5c0e
> > Author: Kees Cook <keescook@chromium.org>
> > Date:   Wed May 25 15:45:33 2016 -0700
> > 
> >     x86/KASLR: Extend kernel image physical address randomization to addresses l
> > arger than 4G
> 
> I know why it happened, making patch. will reply soon.

Sorry, I didn't get it, continue checking.

> 
> > 
> > 
> > cause choose_random_location() return new output buffer
> > new output: [0x0006600000-0x000fe67c97] 0x09867c98: output_run_size
> > 
> > that is overlapped with input data.
> >        input: [0x0008fba276-0x000a8818ed]
> >               ....-0x000a8affff] 0x098b0000: init_size
> > 
> > and input already is in mem_avoid.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [x86/KASLR]  ed9f007ee6: -- System halted
       [not found] <57712812.r6MdDSquaCRYkMnh%xiaolong.ye@intel.com>
  2016-06-27 18:59 ` [x86/KASLR] ed9f007ee6: -- System halted Yinghai Lu
@ 2016-07-01  7:50 ` Baoquan He
  2016-07-01 12:16   ` Ye Xiaolong
  1 sibling, 1 reply; 12+ messages in thread
From: Baoquan He @ 2016-07-01  7:50 UTC (permalink / raw)
  To: kernel test robot
  Cc: Kees Cook, lkp, tipbuild, linux-kernel, Yinghai Lu,
	Thomas Gleixner, Peter Zijlstra, Linus Torvalds, Josh Poimboeuf,
	H.J. Lu, H. Peter Anvin, Dmitry Vyukov, Denys Vlasenko,
	Brian Gerst, Borislav Petkov, Andy Lutomirski, Andrey Ryabinin,
	Andrew Morton, Ingo Molnar

Hi Xiaolong,

Could you please apply below patch and see if it works for you?

>From 46c2a9ecd11f61d952253e005bbd7dcbffa652fb Mon Sep 17 00:00:00 2001
From: Baoquan He <bhe@redhat.com>
Date: Fri, 1 Jul 2016 15:34:40 +0800
Subject: [PATCH] x86/KASLR: Fix code bug of finding earliest overlap

Signed-off-by: Baoquan He <bhe@redhat.com>
---
 arch/x86/boot/compressed/kaslr.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
index 304c5c3..8e1fdf7 100644
--- a/arch/x86/boot/compressed/kaslr.c
+++ b/arch/x86/boot/compressed/kaslr.c
@@ -285,6 +285,7 @@ static bool mem_avoid_overlap(struct mem_vector *img,
 		if (mem_overlaps(img, &mem_avoid[i]) &&
 		    mem_avoid[i].start < earliest) {
 			*overlap = mem_avoid[i];
+			earliest = overlap->start;
 			is_overlapping = true;
 		}
 	}
@@ -299,6 +300,7 @@ static bool mem_avoid_overlap(struct mem_vector *img,
 
 		if (mem_overlaps(img, &avoid) && (avoid.start < earliest)) {
 			*overlap = avoid;
+			earliest = overlap->start;
 			is_overlapping = true;
 		}
 
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [x86/KASLR]  ed9f007ee6: -- System halted
  2016-07-01  7:50 ` Baoquan He
@ 2016-07-01 12:16   ` Ye Xiaolong
  2016-07-01 13:14     ` Baoquan He
  0 siblings, 1 reply; 12+ messages in thread
From: Ye Xiaolong @ 2016-07-01 12:16 UTC (permalink / raw)
  To: Baoquan He
  Cc: Kees Cook, lkp, tipbuild, linux-kernel, Yinghai Lu,
	Thomas Gleixner, Peter Zijlstra, Linus Torvalds, Josh Poimboeuf,
	H.J. Lu, H. Peter Anvin, Dmitry Vyukov, Denys Vlasenko,
	Brian Gerst, Borislav Petkov, Andy Lutomirski, Andrey Ryabinin,
	Andrew Morton, Ingo Molnar

[-- Attachment #1: Type: text/plain, Size: 1311 bytes --]

On Fri, Jul 01, 2016 at 03:50:32PM +0800, Baoquan He wrote:
>Hi Xiaolong,
>
>Could you please apply below patch and see if it works for you?

Hi, Baoquan,

Please check enclosed dmesg after apply your fix patch, does it meet
your expectation?

Thanks,
Xiaolong

>
>From 46c2a9ecd11f61d952253e005bbd7dcbffa652fb Mon Sep 17 00:00:00 2001
>From: Baoquan He <bhe@redhat.com>
>Date: Fri, 1 Jul 2016 15:34:40 +0800
>Subject: [PATCH] x86/KASLR: Fix code bug of finding earliest overlap
>
>Signed-off-by: Baoquan He <bhe@redhat.com>
>---
> arch/x86/boot/compressed/kaslr.c | 2 ++
> 1 file changed, 2 insertions(+)
>
>diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
>index 304c5c3..8e1fdf7 100644
>--- a/arch/x86/boot/compressed/kaslr.c
>+++ b/arch/x86/boot/compressed/kaslr.c
>@@ -285,6 +285,7 @@ static bool mem_avoid_overlap(struct mem_vector *img,
> 		if (mem_overlaps(img, &mem_avoid[i]) &&
> 		    mem_avoid[i].start < earliest) {
> 			*overlap = mem_avoid[i];
>+			earliest = overlap->start;
> 			is_overlapping = true;
> 		}
> 	}
>@@ -299,6 +300,7 @@ static bool mem_avoid_overlap(struct mem_vector *img,
> 
> 		if (mem_overlaps(img, &avoid) && (avoid.start < earliest)) {
> 			*overlap = avoid;
>+			earliest = overlap->start;
> 			is_overlapping = true;
> 		}
> 
>-- 
>2.5.5
>

[-- Attachment #2: dmesg.xz --]
[-- Type: application/octet-stream, Size: 21712 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [x86/KASLR]  ed9f007ee6: -- System halted
  2016-07-01 12:16   ` Ye Xiaolong
@ 2016-07-01 13:14     ` Baoquan He
  2016-07-01 13:25       ` Baoquan He
  0 siblings, 1 reply; 12+ messages in thread
From: Baoquan He @ 2016-07-01 13:14 UTC (permalink / raw)
  To: Ye Xiaolong
  Cc: Kees Cook, lkp, tipbuild, linux-kernel, Yinghai Lu,
	Thomas Gleixner, Peter Zijlstra, Linus Torvalds, Josh Poimboeuf,
	H.J. Lu, H. Peter Anvin, Dmitry Vyukov, Denys Vlasenko,
	Brian Gerst, Borislav Petkov, Andy Lutomirski, Andrey Ryabinin,
	Andrew Morton, Ingo Molnar

[-- Attachment #1: Type: text/plain, Size: 1849 bytes --]

On 07/01/16 at 08:16pm, Ye Xiaolong wrote:
> On Fri, Jul 01, 2016 at 03:50:32PM +0800, Baoquan He wrote:
> >Hi Xiaolong,
> >
> >Could you please apply below patch and see if it works for you?
> 
> Hi, Baoquan,
> 
> Please check enclosed dmesg after apply your fix patch, does it meet
> your expectation?

It works, but didn't get a random phy addr. I am a little worried. I
guess your system has a very small physical memory space. Could you
apply attached patch on top of fix patch and Yinghai's debug patch and
paste the result? I want to check the physical memory and mem_avoid
region to make sure it.

Or if you can paste /proc/iomem I can have a quick check, then you don't
need to run the patch.

> 
> Thanks,
> Xiaolong
> 
> >
> >From 46c2a9ecd11f61d952253e005bbd7dcbffa652fb Mon Sep 17 00:00:00 2001
> >From: Baoquan He <bhe@redhat.com>
> >Date: Fri, 1 Jul 2016 15:34:40 +0800
> >Subject: [PATCH] x86/KASLR: Fix code bug of finding earliest overlap
> >
> >Signed-off-by: Baoquan He <bhe@redhat.com>
> >---
> > arch/x86/boot/compressed/kaslr.c | 2 ++
> > 1 file changed, 2 insertions(+)
> >
> >diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
> >index 304c5c3..8e1fdf7 100644
> >--- a/arch/x86/boot/compressed/kaslr.c
> >+++ b/arch/x86/boot/compressed/kaslr.c
> >@@ -285,6 +285,7 @@ static bool mem_avoid_overlap(struct mem_vector *img,
> > 		if (mem_overlaps(img, &mem_avoid[i]) &&
> > 		    mem_avoid[i].start < earliest) {
> > 			*overlap = mem_avoid[i];
> >+			earliest = overlap->start;
> > 			is_overlapping = true;
> > 		}
> > 	}
> >@@ -299,6 +300,7 @@ static bool mem_avoid_overlap(struct mem_vector *img,
> > 
> > 		if (mem_overlaps(img, &avoid) && (avoid.start < earliest)) {
> > 			*overlap = avoid;
> >+			earliest = overlap->start;
> > 			is_overlapping = true;
> > 		}
> > 
> >-- 
> >2.5.5
> >



[-- Attachment #2: e820_avoid_printing.patch --]
[-- Type: text/plain, Size: 1305 bytes --]

diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
index 8e1fdf7..f2bd558 100644
--- a/arch/x86/boot/compressed/kaslr.c
+++ b/arch/x86/boot/compressed/kaslr.c
@@ -260,6 +260,12 @@ static void mem_avoid_init(unsigned long input, unsigned long input_size,
 	mem_avoid[MEM_AVOID_BOOTPARAMS].size = sizeof(*boot_params);
 	add_identity_map(mem_avoid[MEM_AVOID_BOOTPARAMS].start,
 			 mem_avoid[MEM_AVOID_BOOTPARAMS].size);
+	for(int i=0; i<MEM_AVOID_MAX; i++)
+	debug_printf("      mem_avoid[%d]: [0x%010lx-0x%010lx] 0x%08lx: size\n",
+		 i,
+                 (unsigned long)mem_avoid[i].start,
+                 (unsigned long) mem_avoid[i].start + mem_avoid[i].size - 1,
+                 (unsigned long)mem_avoid[i].size);
 
 	/* We don't need to set a mapping for setup_data. */
 
@@ -376,6 +382,11 @@ static void process_e820_entry(struct e820entry *entry,
 	if (entry->type != E820_RAM)
 		return;
 
+	debug_printf("      e820 entry: [0x%010lx-0x%010lx] 0x%08lx: size\n",
+                 (unsigned long)entry->addr,
+                 (unsigned long)entry->addr + entry->size - 1,
+                 (unsigned long)entry->size);
+
 	/* On 32-bit, ignore entries entirely above our maximum. */
 	if (IS_ENABLED(CONFIG_X86_32) && entry->addr >= KERNEL_IMAGE_SIZE)
 		return;

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [x86/KASLR]  ed9f007ee6: -- System halted
  2016-07-01 13:14     ` Baoquan He
@ 2016-07-01 13:25       ` Baoquan He
  0 siblings, 0 replies; 12+ messages in thread
From: Baoquan He @ 2016-07-01 13:25 UTC (permalink / raw)
  To: Ye Xiaolong
  Cc: Kees Cook, lkp, tipbuild, linux-kernel, Yinghai Lu,
	Thomas Gleixner, Peter Zijlstra, Linus Torvalds, Josh Poimboeuf,
	H.J. Lu, H. Peter Anvin, Dmitry Vyukov, Denys Vlasenko,
	Brian Gerst, Borislav Petkov, Andy Lutomirski, Andrey Ryabinin,
	Andrew Morton, Ingo Molnar

On 07/01/16 at 09:14pm, Baoquan He wrote:
> On 07/01/16 at 08:16pm, Ye Xiaolong wrote:
> > On Fri, Jul 01, 2016 at 03:50:32PM +0800, Baoquan He wrote:
> > >Hi Xiaolong,
> > >
> > >Could you please apply below patch and see if it works for you?
> > 
> > Hi, Baoquan,
> > 
> > Please check enclosed dmesg after apply your fix patch, does it meet
> > your expectation?
> 
> It works, but didn't get a random phy addr. I am a little worried. I
> guess your system has a very small physical memory space. Could you
> apply attached patch on top of fix patch and Yinghai's debug patch and
> paste the result? I want to check the physical memory and mem_avoid
> region to make sure it.
> 
> Or if you can paste /proc/iomem I can have a quick check, then you don't
> need to run the patch.

Sorry, Xiaolong, I didn't notice you have pasted the boot log. It's OK
on your system. The fix is good. Since you only make physical memory
320M on that kvm, and the kernel run size need about 152M. It can't
search another suitable position.

I think the fix is good. By the way, are there other test systems, like
with different size of physical memory?

Thanks
Baoquan

> 
> > 
> > Thanks,
> > Xiaolong
> > 
> > >
> > >From 46c2a9ecd11f61d952253e005bbd7dcbffa652fb Mon Sep 17 00:00:00 2001
> > >From: Baoquan He <bhe@redhat.com>
> > >Date: Fri, 1 Jul 2016 15:34:40 +0800
> > >Subject: [PATCH] x86/KASLR: Fix code bug of finding earliest overlap
> > >
> > >Signed-off-by: Baoquan He <bhe@redhat.com>
> > >---
> > > arch/x86/boot/compressed/kaslr.c | 2 ++
> > > 1 file changed, 2 insertions(+)
> > >
> > >diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
> > >index 304c5c3..8e1fdf7 100644
> > >--- a/arch/x86/boot/compressed/kaslr.c
> > >+++ b/arch/x86/boot/compressed/kaslr.c
> > >@@ -285,6 +285,7 @@ static bool mem_avoid_overlap(struct mem_vector *img,
> > > 		if (mem_overlaps(img, &mem_avoid[i]) &&
> > > 		    mem_avoid[i].start < earliest) {
> > > 			*overlap = mem_avoid[i];
> > >+			earliest = overlap->start;
> > > 			is_overlapping = true;
> > > 		}
> > > 	}
> > >@@ -299,6 +300,7 @@ static bool mem_avoid_overlap(struct mem_vector *img,
> > > 
> > > 		if (mem_overlaps(img, &avoid) && (avoid.start < earliest)) {
> > > 			*overlap = avoid;
> > >+			earliest = overlap->start;
> > > 			is_overlapping = true;
> > > 		}
> > > 
> > >-- 
> > >2.5.5
> > >
> 
> 

> diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
> index 8e1fdf7..f2bd558 100644
> --- a/arch/x86/boot/compressed/kaslr.c
> +++ b/arch/x86/boot/compressed/kaslr.c
> @@ -260,6 +260,12 @@ static void mem_avoid_init(unsigned long input, unsigned long input_size,
>  	mem_avoid[MEM_AVOID_BOOTPARAMS].size = sizeof(*boot_params);
>  	add_identity_map(mem_avoid[MEM_AVOID_BOOTPARAMS].start,
>  			 mem_avoid[MEM_AVOID_BOOTPARAMS].size);
> +	for(int i=0; i<MEM_AVOID_MAX; i++)
> +	debug_printf("      mem_avoid[%d]: [0x%010lx-0x%010lx] 0x%08lx: size\n",
> +		 i,
> +                 (unsigned long)mem_avoid[i].start,
> +                 (unsigned long) mem_avoid[i].start + mem_avoid[i].size - 1,
> +                 (unsigned long)mem_avoid[i].size);
>  
>  	/* We don't need to set a mapping for setup_data. */
>  
> @@ -376,6 +382,11 @@ static void process_e820_entry(struct e820entry *entry,
>  	if (entry->type != E820_RAM)
>  		return;
>  
> +	debug_printf("      e820 entry: [0x%010lx-0x%010lx] 0x%08lx: size\n",
> +                 (unsigned long)entry->addr,
> +                 (unsigned long)entry->addr + entry->size - 1,
> +                 (unsigned long)entry->size);
> +
>  	/* On 32-bit, ignore entries entirely above our maximum. */
>  	if (IS_ENABLED(CONFIG_X86_32) && entry->addr >= KERNEL_IMAGE_SIZE)
>  		return;

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2016-07-01 13:25 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <57712812.r6MdDSquaCRYkMnh%xiaolong.ye@intel.com>
2016-06-27 18:59 ` [x86/KASLR] ed9f007ee6: -- System halted Yinghai Lu
     [not found]   ` <20160628054354.GA9620@yexl-desktop>
     [not found]     ` <CAE9FiQV50UhjJDH89C_T7f2vxFDm7Hpjn78ZKtnfeygQcsf23w@mail.gmail.com>
2016-06-29 20:08       ` Yinghai Lu
2016-06-29 20:29         ` [LKP] " Huang, Ying
2016-06-30  4:49           ` Yinghai Lu
2016-06-30  6:58             ` Ye Xiaolong
2016-07-01  0:24               ` Yinghai Lu
2016-07-01  4:06                 ` Baoquan He
2016-07-01  4:46                   ` Baoquan He
2016-07-01  7:50 ` Baoquan He
2016-07-01 12:16   ` Ye Xiaolong
2016-07-01 13:14     ` Baoquan He
2016-07-01 13:25       ` Baoquan He

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).