Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1342137 > unrolled thread

[PATCH v2] xen/x86: Zero out .bss for PV guests

Started byBoris Ostrovsky <boris.ostrovsky@oracle.com>
First post2016-02-24 16:30 +0100
Last post2016-02-24 18:50 +0100
Articles 5 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH v2] xen/x86: Zero out .bss for PV guests Boris Ostrovsky <boris.ostrovsky@oracle.com> - 2016-02-24 16:30 +0100
    Re: [PATCH v2] xen/x86: Zero out .bss for PV guests Brian Gerst <brgerst@gmail.com> - 2016-02-24 17:10 +0100
      Re: [PATCH v2] xen/x86: Zero out .bss for PV guests Boris Ostrovsky <boris.ostrovsky@oracle.com> - 2016-02-24 17:40 +0100
    Re: [Xen-devel] [PATCH v2] xen/x86: Zero out .bss for PV guests Andrew Cooper <andrew.cooper3@citrix.com> - 2016-02-24 18:30 +0100
      Re: [Xen-devel] [PATCH v2] xen/x86: Zero out .bss for PV guests Boris Ostrovsky <boris.ostrovsky@oracle.com> - 2016-02-24 18:50 +0100

#1342137 — [PATCH v2] xen/x86: Zero out .bss for PV guests

FromBoris Ostrovsky <boris.ostrovsky@oracle.com>
Date2016-02-24 16:30 +0100
Subject[PATCH v2] xen/x86: Zero out .bss for PV guests
Message-ID<r5Jy2-6wc-35@gated-at.bofh.it>
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.

(Since we introduce macros for specifying 32- and 64-bit registers we
can get rid of ifdefs in startup_xen())

Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: stable@vger.kernel.org
---
 arch/x86/xen/xen-head.S | 29 ++++++++++++++++++++++-------
 1 file changed, 22 insertions(+), 7 deletions(-)

diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
index b65f59a..2af87d1 100644
--- a/arch/x86/xen/xen-head.S
+++ b/arch/x86/xen/xen-head.S
@@ -35,16 +35,31 @@
 #define PVH_FEATURES (0)
 #endif
 
-	__INIT
-ENTRY(startup_xen)
-	cld
 #ifdef CONFIG_X86_32
-	mov %esi,xen_start_info
-	mov $init_thread_union+THREAD_SIZE,%esp
+#define REG(register)	%e##register
+#define WSIZE_SHIFT	2
+#define STOS		stosl
 #else
-	mov %rsi,xen_start_info
-	mov $init_thread_union+THREAD_SIZE,%rsp
+#define REG(register)	%r##register
+#define WSIZE_SHIFT	3
+#define STOS		stosq
 #endif
+
+	__INIT
+ENTRY(startup_xen)
+	cld
+
+	/* Clear .bss */
+	xor REG(ax),REG(ax)
+	mov $__bss_start,REG(di)
+	mov $__bss_stop,REG(cx)
+	sub REG(di),REG(cx)
+	shr $WSIZE_SHIFT,REG(cx)
+	rep STOS
+
+	mov REG(si),xen_start_info
+	mov $init_thread_union+THREAD_SIZE,REG(sp)
+
 	jmp xen_start_kernel
 
 	__FINIT
-- 
2.1.0

[toc] | [next] | [standalone]


#1342160

FromBrian Gerst <brgerst@gmail.com>
Date2016-02-24 17:10 +0100
Message-ID<r5KaL-6ZF-33@gated-at.bofh.it>
In reply to#1342137
On Wed, Feb 24, 2016 at 10:19 AM, Boris Ostrovsky
<boris.ostrovsky@oracle.com> wrote:
> 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.
>
> (Since we introduce macros for specifying 32- and 64-bit registers we
> can get rid of ifdefs in startup_xen())
>
> Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
> Cc: stable@vger.kernel.org
> ---
>  arch/x86/xen/xen-head.S | 29 ++++++++++++++++++++++-------
>  1 file changed, 22 insertions(+), 7 deletions(-)
>
> diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
> index b65f59a..2af87d1 100644
> --- a/arch/x86/xen/xen-head.S
> +++ b/arch/x86/xen/xen-head.S
> @@ -35,16 +35,31 @@
>  #define PVH_FEATURES (0)
>  #endif
>
> -       __INIT
> -ENTRY(startup_xen)
> -       cld
>  #ifdef CONFIG_X86_32
> -       mov %esi,xen_start_info
> -       mov $init_thread_union+THREAD_SIZE,%esp
> +#define REG(register)  %e##register
> +#define WSIZE_SHIFT    2
> +#define STOS           stosl
>  #else
> -       mov %rsi,xen_start_info
> -       mov $init_thread_union+THREAD_SIZE,%rsp
> +#define REG(register)  %r##register
> +#define WSIZE_SHIFT    3
> +#define STOS           stosq
>  #endif
> +
> +       __INIT
> +ENTRY(startup_xen)
> +       cld
> +
> +       /* Clear .bss */
> +       xor REG(ax),REG(ax)
> +       mov $__bss_start,REG(di)
> +       mov $__bss_stop,REG(cx)
> +       sub REG(di),REG(cx)
> +       shr $WSIZE_SHIFT,REG(cx)
> +       rep STOS
> +
> +       mov REG(si),xen_start_info
> +       mov $init_thread_union+THREAD_SIZE,REG(sp)
> +
>         jmp xen_start_kernel
>
>         __FINIT

Use the macros in <asm/asm.h> instead of defining your own.  Also,
xorl %eax,%eax is good for 64-bit too, since the upper bits are
cleared.

--
Brian Gerst

[toc] | [prev] | [next] | [standalone]


#1342183

FromBoris Ostrovsky <boris.ostrovsky@oracle.com>
Date2016-02-24 17:40 +0100
Message-ID<r5KDM-7ce-15@gated-at.bofh.it>
In reply to#1342160
On 02/24/2016 11:05 AM, Brian Gerst wrote:
>
> Use the macros in <asm/asm.h> instead of defining your own.  Also,
> xorl %eax,%eax is good for 64-bit too, since the upper bits are
> cleared.

I suspected this would have to be defined somewhere but couldn't find 
it. Thanks!

-boris

[toc] | [prev] | [next] | [standalone]


#1342247 — Re: [Xen-devel] [PATCH v2] xen/x86: Zero out .bss for PV guests

FromAndrew Cooper <andrew.cooper3@citrix.com>
Date2016-02-24 18:30 +0100
SubjectRe: [Xen-devel] [PATCH v2] xen/x86: Zero out .bss for PV guests
Message-ID<r5Lqb-7M2-27@gated-at.bofh.it>
In reply to#1342137
On 24/02/16 15:19, Boris Ostrovsky wrote:
> 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.
>
> (Since we introduce macros for specifying 32- and 64-bit registers we
> can get rid of ifdefs in startup_xen())
>
> Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
> Cc: stable@vger.kernel.org
> ---
>  arch/x86/xen/xen-head.S | 29 ++++++++++++++++++++++-------
>  1 file changed, 22 insertions(+), 7 deletions(-)
>
> diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
> index b65f59a..2af87d1 100644
> --- a/arch/x86/xen/xen-head.S
> +++ b/arch/x86/xen/xen-head.S
> @@ -35,16 +35,31 @@
>  #define PVH_FEATURES (0)
>  #endif
>  
> -	__INIT
> -ENTRY(startup_xen)
> -	cld
>  #ifdef CONFIG_X86_32
> -	mov %esi,xen_start_info
> -	mov $init_thread_union+THREAD_SIZE,%esp
> +#define REG(register)	%e##register
> +#define WSIZE_SHIFT	2
> +#define STOS		stosl
>  #else
> -	mov %rsi,xen_start_info
> -	mov $init_thread_union+THREAD_SIZE,%rsp
> +#define REG(register)	%r##register
> +#define WSIZE_SHIFT	3
> +#define STOS		stosq
>  #endif
> +
> +	__INIT
> +ENTRY(startup_xen)
> +	cld
> +
> +	/* Clear .bss */
> +	xor REG(ax),REG(ax)

If we are nitpicking,

This should be xor %eax, %eax even in 64bit.  Functionally identical,
and shorter to encode.

~Andrew

[toc] | [prev] | [next] | [standalone]


#1342261 — Re: [Xen-devel] [PATCH v2] xen/x86: Zero out .bss for PV guests

FromBoris Ostrovsky <boris.ostrovsky@oracle.com>
Date2016-02-24 18:50 +0100
SubjectRe: [Xen-devel] [PATCH v2] xen/x86: Zero out .bss for PV guests
Message-ID<r5LJx-7WC-29@gated-at.bofh.it>
In reply to#1342247
On 02/24/2016 12:26 PM, Andrew Cooper wrote:
> On 24/02/16 15:19, Boris Ostrovsky wrote:
>> +	/* Clear .bss */
>> +	xor REG(ax),REG(ax)
> If we are nitpicking,
>
> This should be xor %eax, %eax even in 64bit.  Functionally identical,
> and shorter to encode.

Right, Brian Gerst pointed this out too in another message.

-boris

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web