Skip to contentSkip to conversation

Clear .bss for VP guests

PATCH Superseded Boris Ostrovsky 4 participants 25 messages Feb 25, 2016 – Feb 26, 2016

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Boris Ostrovsky

author reviewer
#0 lore raw

v3 cover Clear .bss for VP guests

PV guests need to have their .bss zeroed out since it is not guaranteed to be cleared by Xen's domain builder

v3:
* Use existing macros for selecting mode-appropriate instructions/registers
* Use 32-bit registers in XOR
* Split removal of mode-selecting ifdefs into a separate patch

Boris Ostrovsky (2):
xen/x86: Zero out .bss for PV guests xen/x86: Drop mode-selecting ifdefs in startup_xen()

 arch/x86/xen/xen-head.S | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
Signature · 1 line
2.1.0
author reviewer
#1 lore raw

PATCH v3 1/2 xen/x86: Zero out .bss for PV guests

Baremetal kernels clear .bss early in the boot but Xen PV guests don't execute that code. They have been able to run without problems because Xen domain builder happens to give out zeroed pages. However, since this is not really guaranteed, .bss should be explicitly cleared.

---
 arch/x86/xen/xen-head.S | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
arch/x86/xen/xen-head.S +14 -0
index b65f59a..11dbe49 100644
@@ -38,6 +38,20 @@
 	__INIT
 ENTRY(startup_xen)
 	cld
+
+#ifdef CONFIG_X86_32
+#define WSIZE_SHIFT	2
+#else
+#define WSIZE_SHIFT	3
+#endif
+	/* Clear .bss */
+	xor %eax,%eax
+	mov $__bss_start, %__ASM_REG(di)
+	mov $__bss_stop, %__ASM_REG(cx)
+	sub %__ASM_REG(di), %__ASM_REG(cx)
+	shr $WSIZE_SHIFT, %__ASM_REG(cx)
+	rep __ASM_SIZE(stos)
+
 #ifdef CONFIG_X86_32
 	mov %esi,xen_start_info
 	mov $init_thread_union+THREAD_SIZE,%esp
Signature · 1 line
2.1.0
#2 lore raw

Re: [PATCH v3 1/2] xen/x86: Zero out .bss for PV guests

Quoted 26 lines · Boris Ostrovsky

Baremetal kernels clear .bss early in the boot but Xen PV guests don't execute that code. They have been able to run without problems because Xen domain builder happens to give out zeroed pages. However, since this is not really guaranteed, .bss should be explicitly cleared.

---
 arch/x86/xen/xen-head.S | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
arch/x86/xen/xen-head.S +7 -0
index b65f59a..11dbe49 100644
@@ -38,6 +38,20 @@
        __INIT
 ENTRY(startup_xen)
        cld
+
+#ifdef CONFIG_X86_32
+#define WSIZE_SHIFT    2
+#else
+#define WSIZE_SHIFT    3
+#endif
+       /* Clear .bss */

arch/x86/xen/xen-head.S line 57

Quoted 10 lines
arch/x86/xen/xen-head.S +7 -0
+       xor %eax,%eax
+       mov $__bss_start, %__ASM_REG(di)
+       mov $__bss_stop, %__ASM_REG(cx)
+       sub %__ASM_REG(di), %__ASM_REG(cx)
+       shr $WSIZE_SHIFT, %__ASM_REG(cx)
+       rep __ASM_SIZE(stos)
+
 #ifdef CONFIG_X86_32
        mov %esi,xen_start_info
        mov $init_thread_union+THREAD_SIZE,%esp

Better, but can still be improved. Replace WSIZE_SHIFT with __ASM_SEL(2, 3), and use the macros for the registers (ie. __ASM_DI).

--
Brian Gerst

#3 lore raw

Re: [PATCH v3 1/2] xen/x86: Zero out .bss for PV guests

In reply to Boris Ostrovsky
Quoted 26 lines · Boris Ostrovsky

Baremetal kernels clear .bss early in the boot but Xen PV guests don't execute that code. They have been able to run without problems because Xen domain builder happens to give out zeroed pages. However, since this is not really guaranteed, .bss should be explicitly cleared.

---
 arch/x86/xen/xen-head.S | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
arch/x86/xen/xen-head.S +7 -0
index b65f59a..11dbe49 100644
@@ -38,6 +38,20 @@
        __INIT
 ENTRY(startup_xen)
        cld
+
+#ifdef CONFIG_X86_32
+#define WSIZE_SHIFT    2
+#else
+#define WSIZE_SHIFT    3
+#endif
+       /* Clear .bss */

arch/x86/xen/xen-head.S line 57

Quoted 10 lines
arch/x86/xen/xen-head.S +7 -0
+       xor %eax,%eax
+       mov $__bss_start, %__ASM_REG(di)
+       mov $__bss_stop, %__ASM_REG(cx)
+       sub %__ASM_REG(di), %__ASM_REG(cx)
+       shr $WSIZE_SHIFT, %__ASM_REG(cx)
+       rep __ASM_SIZE(stos)
+
 #ifdef CONFIG_X86_32
        mov %esi,xen_start_info
        mov $init_thread_union+THREAD_SIZE,%esp

Better, but can still be improved. Replace WSIZE_SHIFT with __ASM_SEL(2, 3), and use the macros for the registers (ie. __ASM_DI).

--
Brian Gerst

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author reviewer
#4 lore raw

PATCH v3 1/2 xen/x86: Zero out .bss for PV guests

In reply to Boris Ostrovsky

Baremetal kernels clear .bss early in the boot but Xen PV guests don't execute that code. They have been able to run without problems because Xen domain builder happens to give out zeroed pages. However, since this is not really guaranteed, .bss should be explicitly cleared.

---
 arch/x86/xen/xen-head.S | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
arch/x86/xen/xen-head.S +14 -0
index b65f59a..11dbe49 100644
@@ -38,6 +38,20 @@
 	__INIT
 ENTRY(startup_xen)
 	cld
+
+#ifdef CONFIG_X86_32
+#define WSIZE_SHIFT	2
+#else
+#define WSIZE_SHIFT	3
+#endif
+	/* Clear .bss */
+	xor %eax,%eax
+	mov $__bss_start, %__ASM_REG(di)
+	mov $__bss_stop, %__ASM_REG(cx)
+	sub %__ASM_REG(di), %__ASM_REG(cx)
+	shr $WSIZE_SHIFT, %__ASM_REG(cx)
+	rep __ASM_SIZE(stos)
+
 #ifdef CONFIG_X86_32
 	mov %esi,xen_start_info
 	mov $init_thread_union+THREAD_SIZE,%esp
Signature · 7 lines
2.1.0


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
author reviewer
#5 lore raw

PATCH v3 2/2 xen/x86: Drop mode-selecting ifdefs in startup_xen()

In reply to Boris Ostrovsky

Use asm/asm.h macros instead.

---
 arch/x86/xen/xen-head.S | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
arch/x86/xen/xen-head.S +3 -7
index 11dbe49..2366895 100644
@@ -52,13 +52,9 @@ ENTRY(startup_xen)
 	shr $WSIZE_SHIFT, %__ASM_REG(cx)
 	rep __ASM_SIZE(stos)
 
-#ifdef CONFIG_X86_32
-	mov %esi,xen_start_info
-	mov $init_thread_union+THREAD_SIZE,%esp
-#else
-	mov %rsi,xen_start_info
-	mov $init_thread_union+THREAD_SIZE,%rsp
-#endif
+	mov %__ASM_REG(si), xen_start_info
+	mov $init_thread_union+THREAD_SIZE, %__ASM_REG(sp)
+
 	jmp xen_start_kernel
 
 	__FINIT
Signature · 7 lines
2.1.0


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
author reviewer
#6 lore raw

PATCH v3 2/2 xen/x86: Drop mode-selecting ifdefs in startup_xen()

In reply to Boris Ostrovsky

Use asm/asm.h macros instead.

---
 arch/x86/xen/xen-head.S | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
arch/x86/xen/xen-head.S +3 -7
index 11dbe49..2366895 100644
@@ -52,13 +52,9 @@ ENTRY(startup_xen)
 	shr $WSIZE_SHIFT, %__ASM_REG(cx)
 	rep __ASM_SIZE(stos)
 
-#ifdef CONFIG_X86_32
-	mov %esi,xen_start_info
-	mov $init_thread_union+THREAD_SIZE,%esp
-#else
-	mov %rsi,xen_start_info
-	mov $init_thread_union+THREAD_SIZE,%rsp
-#endif
+	mov %__ASM_REG(si), xen_start_info
+	mov $init_thread_union+THREAD_SIZE, %__ASM_REG(sp)
+
 	jmp xen_start_kernel
 
 	__FINIT
Signature · 1 line
2.1.0
#7 lore raw
In reply to Boris Ostrovsky

El 25/2/16 a les 16:16, Boris Ostrovsky ha escrit:

Quoted 2 lines

PV guests need to have their .bss zeroed out since it is not guaranteed to be cleared by Xen's domain builder

I guess I'm missing something, but elf_load_image (in libelf-loader.c) seems to be able to clear segments (it will zero the memory between p_paddr + p_filesz and p_paddr + p_memsz) while loading the ELF into memory, so if the program headers are correctly setup the .bss should be zeroed out AFAICT.

Roger.

author reviewer
#8 lore raw
Quoted 8 lines · Roger Pau Monné

El 25/2/16 a les 16:16, Boris Ostrovsky ha escrit:

Quoted 2 lines

PV guests need to have their .bss zeroed out since it is not guaranteed to be cleared by Xen's domain builder

I guess I'm missing something, but elf_load_image (in libelf-loader.c) seems to be able to clear segments (it will zero the memory between p_paddr + p_filesz and p_paddr + p_memsz) while loading the ELF into memory, so if the program headers are correctly setup the .bss should be zeroed out AFAICT.

Right, but I don't think this is guaranteed. It's uninitialized data so in principle it can be anything.

The ELF spec says "the system initializes the data with zero when the program begins to run" which I read as it's up to runtime and not the loader to do so.

And since kernel does it explicitly on baremetal path I think it's a good idea for PV to do the same.

-boris

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author reviewer
#9 lore raw
In reply to Roger Pau Monné
Quoted 8 lines · Roger Pau Monné

El 25/2/16 a les 16:16, Boris Ostrovsky ha escrit:

Quoted 2 lines

PV guests need to have their .bss zeroed out since it is not guaranteed to be cleared by Xen's domain builder

I guess I'm missing something, but elf_load_image (in libelf-loader.c) seems to be able to clear segments (it will zero the memory between p_paddr + p_filesz and p_paddr + p_memsz) while loading the ELF into memory, so if the program headers are correctly setup the .bss should be zeroed out AFAICT.

Right, but I don't think this is guaranteed. It's uninitialized data so in principle it can be anything.

The ELF spec says "the system initializes the data with zero when the program begins to run" which I read as it's up to runtime and not the loader to do so.

And since kernel does it explicitly on baremetal path I think it's a good idea for PV to do the same.

-boris

#10 lore raw
Quoted 17 lines · Boris Ostrovsky
Quoted 11 lines · Roger Pau Monné

El 25/2/16 a les 16:16, Boris Ostrovsky ha escrit:

Quoted 3 lines

PV guests need to have their .bss zeroed out since it is not guaranteed to be cleared by Xen's domain builder

I guess I'm missing something, but elf_load_image (in libelf-loader.c) seems to be able to clear segments (it will zero the memory between p_paddr + p_filesz and p_paddr + p_memsz) while loading the ELF into memory, so if the program headers are correctly setup the .bss should be zeroed out AFAICT.

Right, but I don't think this is guaranteed. It's uninitialized data so in principle it can be anything.

Quoted 6 lines

The ELF spec says "the system initializes the data with zero when the program begins to run" which I read as it's up to runtime and not the loader to do so.

And since kernel does it explicitly on baremetal path I think it's a good idea for PV to do the same.

It does it on bare metal because bzImage is a raw binary image, not ELF.

--
Brian Gerst

author reviewer
#11 lore raw
Quoted 15 lines · Brian Gerst
Quoted 13 lines · Boris Ostrovsky
Quoted 8 lines · Roger Pau Monné

El 25/2/16 a les 16:16, Boris Ostrovsky ha escrit:

Quoted 2 lines

PV guests need to have their .bss zeroed out since it is not guaranteed to be cleared by Xen's domain builder

I guess I'm missing something, but elf_load_image (in libelf-loader.c) seems to be able to clear segments (it will zero the memory between p_paddr + p_filesz and p_paddr + p_memsz) while loading the ELF into memory, so if the program headers are correctly setup the .bss should be zeroed out AFAICT.

Right, but I don't think this is guaranteed. It's uninitialized data so in principle it can be anything.

Quoted 7 lines
Quoted 6 lines

The ELF spec says "the system initializes the data with zero when the program begins to run" which I read as it's up to runtime and not the loader to do so.

And since kernel does it explicitly on baremetal path I think it's a good idea for PV to do the same.

It does it on bare metal because bzImage is a raw binary image, not ELF.

OK, I didn't think about this.

But nevertheless, is it guaranteed that .bss is cleared by the loader? My reading of the spec is that it's not.

-boris

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author reviewer
#12 lore raw
In reply to Brian Gerst
Quoted 15 lines · Brian Gerst
Quoted 13 lines · Boris Ostrovsky
Quoted 8 lines · Roger Pau Monné

El 25/2/16 a les 16:16, Boris Ostrovsky ha escrit:

Quoted 2 lines

PV guests need to have their .bss zeroed out since it is not guaranteed to be cleared by Xen's domain builder

I guess I'm missing something, but elf_load_image (in libelf-loader.c) seems to be able to clear segments (it will zero the memory between p_paddr + p_filesz and p_paddr + p_memsz) while loading the ELF into memory, so if the program headers are correctly setup the .bss should be zeroed out AFAICT.

Right, but I don't think this is guaranteed. It's uninitialized data so in principle it can be anything.

Quoted 7 lines
Quoted 6 lines

The ELF spec says "the system initializes the data with zero when the program begins to run" which I read as it's up to runtime and not the loader to do so.

And since kernel does it explicitly on baremetal path I think it's a good idea for PV to do the same.

It does it on bare metal because bzImage is a raw binary image, not ELF.

OK, I didn't think about this.

But nevertheless, is it guaranteed that .bss is cleared by the loader? My reading of the spec is that it's not.

-boris

#13 lore raw
Quoted 27 lines · Boris Ostrovsky
Quoted 26 lines · Brian Gerst
Quoted 24 lines · Boris Ostrovsky
Quoted 10 lines · Roger Pau Monné

El 25/2/16 a les 16:16, Boris Ostrovsky ha escrit:

Quoted 3 lines

PV guests need to have their .bss zeroed out since it is not guaranteed
to be cleared by Xen's domain builder

I guess I'm missing something, but elf_load_image (in libelf-loader.c) seems to be able to clear segments (it will zero the memory between p_paddr + p_filesz and p_paddr + p_memsz) while loading the ELF into memory, so if the program headers are correctly setup the .bss should be
zeroed out AFAICT.

Right, but I don't think this is guaranteed. It's uninitialized data so in
principle it can be anything.

The ELF spec says "the system initializes the data with zero when the program begins to run" which I read as it's up to runtime and not the loader
to do so.

And since kernel does it explicitly on baremetal path I think it's a good
idea for PV to do the same.

Quoted 6 lines
Quoted 1 line

It does it on bare metal because bzImage is a raw binary image, not ELF.

OK, I didn't think about this.

But nevertheless, is it guaranteed that .bss is cleared by the loader? My reading of the spec is that it's not.

I'm going to apply it once you post a final version with the last suggestion from Brian.

I'll drop the tag for stable though.

David

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#14 lore raw
In reply to Boris Ostrovsky
Quoted 27 lines · Boris Ostrovsky
Quoted 26 lines · Brian Gerst
Quoted 24 lines · Boris Ostrovsky
Quoted 10 lines · Roger Pau Monné

El 25/2/16 a les 16:16, Boris Ostrovsky ha escrit:

Quoted 3 lines

PV guests need to have their .bss zeroed out since it is not guaranteed
to be cleared by Xen's domain builder

I guess I'm missing something, but elf_load_image (in libelf-loader.c) seems to be able to clear segments (it will zero the memory between p_paddr + p_filesz and p_paddr + p_memsz) while loading the ELF into memory, so if the program headers are correctly setup the .bss should be
zeroed out AFAICT.

Right, but I don't think this is guaranteed. It's uninitialized data so in
principle it can be anything.

The ELF spec says "the system initializes the data with zero when the program begins to run" which I read as it's up to runtime and not the loader
to do so.

And since kernel does it explicitly on baremetal path I think it's a good
idea for PV to do the same.

Quoted 6 lines
Quoted 1 line

It does it on bare metal because bzImage is a raw binary image, not ELF.

OK, I didn't think about this.

But nevertheless, is it guaranteed that .bss is cleared by the loader? My reading of the spec is that it's not.

I'm going to apply it once you post a final version with the last suggestion from Brian.

I'll drop the tag for stable though.

David

#15 lore raw
In reply to Boris Ostrovsky

El 26/2/16 a les 16:10, Boris Ostrovsky ha escrit:

Quoted 27 lines · Brian Gerst
Quoted 26 lines
Quoted 24 lines · Boris Ostrovsky
Quoted 10 lines · Roger Pau Monné

El 25/2/16 a les 16:16, Boris Ostrovsky ha escrit:

Quoted 3 lines

PV guests need to have their .bss zeroed out since it is not guaranteed
to be cleared by Xen's domain builder

I guess I'm missing something, but elf_load_image (in libelf-loader.c) seems to be able to clear segments (it will zero the memory between p_paddr + p_filesz and p_paddr + p_memsz) while loading the ELF into memory, so if the program headers are correctly setup the .bss should be
zeroed out AFAICT.

Right, but I don't think this is guaranteed. It's uninitialized data so in
principle it can be anything.

The ELF spec says "the system initializes the data with zero when the program begins to run" which I read as it's up to runtime and not the loader
to do so.

And since kernel does it explicitly on baremetal path I think it's a good
idea for PV to do the same.

Quoted 6 lines
Quoted 1 line

It does it on bare metal because bzImage is a raw binary image, not ELF.

OK, I didn't think about this.

But nevertheless, is it guaranteed that .bss is cleared by the loader? My reading of the spec is that it's not.

I think this is very blur in general. The copy of the spec I have says:

"the system initializes the data with zeros when the program begins to run"

What is "the system" here, Xen or the guest kernel?

Just to be clear, I'm not opposing to this change in any way, but the message in patch 1/2 needs to be fixed:

"They have been able to run without problems because Xen domain builder happens to give out zeroed pages."

This is wrong IMHO, .bss is not cleared because we are using zeroed pages, but because elf_load_image explicitly zeroes the space between p_filesz and p_memsz in ELF program headers (which is were .bss resides on properly arranged ELF binaries) when loading them.

I'm quite sure NetBSD also relies on this, so I would say it's intrinsically part of the Xen boot ABI now, and this change just adds seatbelts to Linux.

Roger.

#16 lore raw
Quoted 47 lines · Roger Pau Monné

El 26/2/16 a les 16:10, Boris Ostrovsky ha escrit:

Quoted 27 lines · Brian Gerst
Quoted 26 lines
Quoted 24 lines · Boris Ostrovsky
Quoted 10 lines · Roger Pau Monné

El 25/2/16 a les 16:16, Boris Ostrovsky ha escrit:

Quoted 3 lines

PV guests need to have their .bss zeroed out since it is not guaranteed
to be cleared by Xen's domain builder

I guess I'm missing something, but elf_load_image (in libelf-loader.c) seems to be able to clear segments (it will zero the memory between p_paddr + p_filesz and p_paddr + p_memsz) while loading the ELF into memory, so if the program headers are correctly setup the .bss should be
zeroed out AFAICT.

Right, but I don't think this is guaranteed. It's uninitialized data so in
principle it can be anything.

The ELF spec says "the system initializes the data with zero when the program begins to run" which I read as it's up to runtime and not the loader
to do so.

And since kernel does it explicitly on baremetal path I think it's a good
idea for PV to do the same.

Quoted 6 lines
Quoted 1 line

It does it on bare metal because bzImage is a raw binary image, not ELF.

OK, I didn't think about this.

But nevertheless, is it guaranteed that .bss is cleared by the loader? My reading of the spec is that it's not.

I think this is very blur in general. The copy of the spec I have says:

"the system initializes the data with zeros when the program begins to run"

What is "the system" here, Xen or the guest kernel?

Just to be clear, I'm not opposing to this change in any way, but the message in patch 1/2 needs to be fixed:

"They have been able to run without problems because Xen domain builder happens to give out zeroed pages."

Quoted 8 lines

This is wrong IMHO, .bss is not cleared because we are using zeroed pages, but because elf_load_image explicitly zeroes the space between p_filesz and p_memsz in ELF program headers (which is were .bss resides on properly arranged ELF binaries) when loading them.

I'm quite sure NetBSD also relies on this, so I would say it's intrinsically part of the Xen boot ABI now, and this change just adds seatbelts to Linux.

The tools support loading bzImages, not just ELF images.

David

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#17 lore raw
In reply to Roger Pau Monné
Quoted 47 lines · Roger Pau Monné

El 26/2/16 a les 16:10, Boris Ostrovsky ha escrit:

Quoted 27 lines · Brian Gerst
Quoted 26 lines
Quoted 24 lines · Boris Ostrovsky
Quoted 10 lines · Roger Pau Monné

El 25/2/16 a les 16:16, Boris Ostrovsky ha escrit:

Quoted 3 lines

PV guests need to have their .bss zeroed out since it is not guaranteed
to be cleared by Xen's domain builder

I guess I'm missing something, but elf_load_image (in libelf-loader.c) seems to be able to clear segments (it will zero the memory between p_paddr + p_filesz and p_paddr + p_memsz) while loading the ELF into memory, so if the program headers are correctly setup the .bss should be
zeroed out AFAICT.

Right, but I don't think this is guaranteed. It's uninitialized data so in
principle it can be anything.

The ELF spec says "the system initializes the data with zero when the program begins to run" which I read as it's up to runtime and not the loader
to do so.

And since kernel does it explicitly on baremetal path I think it's a good
idea for PV to do the same.

Quoted 6 lines
Quoted 1 line

It does it on bare metal because bzImage is a raw binary image, not ELF.

OK, I didn't think about this.

But nevertheless, is it guaranteed that .bss is cleared by the loader? My reading of the spec is that it's not.

I think this is very blur in general. The copy of the spec I have says:

"the system initializes the data with zeros when the program begins to run"

What is "the system" here, Xen or the guest kernel?

Just to be clear, I'm not opposing to this change in any way, but the message in patch 1/2 needs to be fixed:

"They have been able to run without problems because Xen domain builder happens to give out zeroed pages."

Quoted 8 lines

This is wrong IMHO, .bss is not cleared because we are using zeroed pages, but because elf_load_image explicitly zeroes the space between p_filesz and p_memsz in ELF program headers (which is were .bss resides on properly arranged ELF binaries) when loading them.

I'm quite sure NetBSD also relies on this, so I would say it's intrinsically part of the Xen boot ABI now, and this change just adds seatbelts to Linux.

The tools support loading bzImages, not just ELF images.

David

author reviewer
#18 lore raw
Quoted 2 lines · David Vrabel

The tools support loading bzImages, not just ELF images.

We load them as ELF images though, I believe, after uncompressing. E.g.:

static int xc_dom_load_bzimage_kernel(struct xc_dom_image *dom)

{
    return elf_loader.loader(dom);
}

-boris

author reviewer
#20 lore raw
In reply to Roger Pau Monné
Quoted 41 lines · Roger Pau Monné

El 26/2/16 a les 16:10, Boris Ostrovsky ha escrit:

Quoted 23 lines · Brian Gerst
Quoted 22 lines
Quoted 20 lines · Boris Ostrovsky
Quoted 10 lines · Roger Pau Monné

El 25/2/16 a les 16:16, Boris Ostrovsky ha escrit:

Quoted 3 lines

PV guests need to have their .bss zeroed out since it is not guaranteed
to be cleared by Xen's domain builder

I guess I'm missing something, but elf_load_image (in libelf-loader.c) seems to be able to clear segments (it will zero the memory between p_paddr + p_filesz and p_paddr + p_memsz) while loading the ELF into memory, so if the program headers are correctly setup the .bss should be
zeroed out AFAICT.

Right, but I don't think this is guaranteed. It's uninitialized data so in
principle it can be anything.

The ELF spec says "the system initializes the data with zero when the program begins to run" which I read as it's up to runtime and not the loader
to do so.

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines

And since kernel does it explicitly on baremetal path I think it's a good
idea for PV to do the same.

It does it on bare metal because bzImage is a raw binary image, not ELF.

OK, I didn't think about this.

But nevertheless, is it guaranteed that .bss is cleared by the loader? My reading of the spec is that it's not.

I think this is very blur in general. The copy of the spec I have says:

"the system initializes the data with zeros when the program begins to run"

What is "the system" here, Xen or the guest kernel?

Just to be clear, I'm not opposing to this change in any way, but the message in patch 1/2 needs to be fixed:

Quoted 7 lines

"They have been able to run without problems because Xen domain builder happens to give out zeroed pages."

This is wrong IMHO, .bss is not cleared because we are using zeroed pages, but because elf_load_image explicitly zeroes the space between p_filesz and p_memsz in ELF program headers (which is were .bss resides on properly arranged ELF binaries) when loading them.

That's what I meant --- that the builder/loader gives out zeroed pages, not that Xen's allocator clears them in general. I'll update the commit message.

Quoted 4 lines

I'm quite sure NetBSD also relies on this, so I would say it's intrinsically part of the Xen boot ABI now, and this change just adds seatbelts to Linux.

Maybe NetBSD should drive carefully then ;-)

-boris

author reviewer
#21 lore raw
In reply to Roger Pau Monné
Quoted 41 lines · Roger Pau Monné

El 26/2/16 a les 16:10, Boris Ostrovsky ha escrit:

Quoted 23 lines · Brian Gerst
Quoted 22 lines
Quoted 20 lines · Boris Ostrovsky
Quoted 10 lines · Roger Pau Monné

El 25/2/16 a les 16:16, Boris Ostrovsky ha escrit:

Quoted 3 lines

PV guests need to have their .bss zeroed out since it is not guaranteed
to be cleared by Xen's domain builder

I guess I'm missing something, but elf_load_image (in libelf-loader.c) seems to be able to clear segments (it will zero the memory between p_paddr + p_filesz and p_paddr + p_memsz) while loading the ELF into memory, so if the program headers are correctly setup the .bss should be
zeroed out AFAICT.

Right, but I don't think this is guaranteed. It's uninitialized data so in
principle it can be anything.

The ELF spec says "the system initializes the data with zero when the program begins to run" which I read as it's up to runtime and not the loader
to do so.

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines

And since kernel does it explicitly on baremetal path I think it's a good
idea for PV to do the same.

It does it on bare metal because bzImage is a raw binary image, not ELF.

OK, I didn't think about this.

But nevertheless, is it guaranteed that .bss is cleared by the loader? My reading of the spec is that it's not.

I think this is very blur in general. The copy of the spec I have says:

"the system initializes the data with zeros when the program begins to run"

What is "the system" here, Xen or the guest kernel?

Just to be clear, I'm not opposing to this change in any way, but the message in patch 1/2 needs to be fixed:

Quoted 7 lines

"They have been able to run without problems because Xen domain builder happens to give out zeroed pages."

This is wrong IMHO, .bss is not cleared because we are using zeroed pages, but because elf_load_image explicitly zeroes the space between p_filesz and p_memsz in ELF program headers (which is were .bss resides on properly arranged ELF binaries) when loading them.

That's what I meant --- that the builder/loader gives out zeroed pages, not that Xen's allocator clears them in general. I'll update the commit message.

Quoted 4 lines

I'm quite sure NetBSD also relies on this, so I would say it's intrinsically part of the Xen boot ABI now, and this change just adds seatbelts to Linux.

Maybe NetBSD should drive carefully then ;-)

-boris

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#22 lore raw
In reply to Boris Ostrovsky

El 26/2/16 a les 16:10, Boris Ostrovsky ha escrit:

Quoted 27 lines · Brian Gerst
Quoted 26 lines
Quoted 24 lines · Boris Ostrovsky
Quoted 10 lines · Roger Pau Monné

El 25/2/16 a les 16:16, Boris Ostrovsky ha escrit:

Quoted 3 lines

PV guests need to have their .bss zeroed out since it is not guaranteed
to be cleared by Xen's domain builder

I guess I'm missing something, but elf_load_image (in libelf-loader.c) seems to be able to clear segments (it will zero the memory between p_paddr + p_filesz and p_paddr + p_memsz) while loading the ELF into memory, so if the program headers are correctly setup the .bss should be
zeroed out AFAICT.

Right, but I don't think this is guaranteed. It's uninitialized data so in
principle it can be anything.

The ELF spec says "the system initializes the data with zero when the program begins to run" which I read as it's up to runtime and not the loader
to do so.

And since kernel does it explicitly on baremetal path I think it's a good
idea for PV to do the same.

Quoted 6 lines
Quoted 1 line

It does it on bare metal because bzImage is a raw binary image, not ELF.

OK, I didn't think about this.

But nevertheless, is it guaranteed that .bss is cleared by the loader? My reading of the spec is that it's not.

I think this is very blur in general. The copy of the spec I have says:

"the system initializes the data with zeros when the program begins to run"

What is "the system" here, Xen or the guest kernel?

Just to be clear, I'm not opposing to this change in any way, but the message in patch 1/2 needs to be fixed:

"They have been able to run without problems because Xen domain builder happens to give out zeroed pages."

This is wrong IMHO, .bss is not cleared because we are using zeroed pages, but because elf_load_image explicitly zeroes the space between p_filesz and p_memsz in ELF program headers (which is were .bss resides on properly arranged ELF binaries) when loading them.

I'm quite sure NetBSD also relies on this, so I would say it's intrinsically part of the Xen boot ABI now, and this change just adds seatbelts to Linux.

Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#23 lore raw
In reply to Boris Ostrovsky
Quoted 17 lines · Boris Ostrovsky
Quoted 11 lines · Roger Pau Monné

El 25/2/16 a les 16:16, Boris Ostrovsky ha escrit:

Quoted 3 lines

PV guests need to have their .bss zeroed out since it is not guaranteed to be cleared by Xen's domain builder

I guess I'm missing something, but elf_load_image (in libelf-loader.c) seems to be able to clear segments (it will zero the memory between p_paddr + p_filesz and p_paddr + p_memsz) while loading the ELF into memory, so if the program headers are correctly setup the .bss should be zeroed out AFAICT.

Right, but I don't think this is guaranteed. It's uninitialized data so in principle it can be anything.

Quoted 6 lines

The ELF spec says "the system initializes the data with zero when the program begins to run" which I read as it's up to runtime and not the loader to do so.

And since kernel does it explicitly on baremetal path I think it's a good idea for PV to do the same.

It does it on bare metal because bzImage is a raw binary image, not ELF.

--
Brian Gerst

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#24 lore raw
In reply to Boris Ostrovsky

El 25/2/16 a les 16:16, Boris Ostrovsky ha escrit:

Quoted 2 lines

PV guests need to have their .bss zeroed out since it is not guaranteed to be cleared by Xen's domain builder

I guess I'm missing something, but elf_load_image (in libelf-loader.c) seems to be able to clear segments (it will zero the memory between p_paddr + p_filesz and p_paddr + p_memsz) while loading the ELF into memory, so if the program headers are correctly setup the .bss should be zeroed out AFAICT.

Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel