public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] xen/x86: Zero out .bss for PV guests
@ 2016-02-24 15:19 Boris Ostrovsky
  2016-02-24 16:05 ` Brian Gerst
  2016-02-24 17:26 ` [Xen-devel] " Andrew Cooper
  0 siblings, 2 replies; 5+ messages in thread
From: Boris Ostrovsky @ 2016-02-24 15:19 UTC (permalink / raw)
  To: konrad.wilk, david.vrabel
  Cc: xen-devel, linux-kernel, mcgrof, Boris Ostrovsky, stable

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

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

* Re: [PATCH v2] xen/x86: Zero out .bss for PV guests
  2016-02-24 15:19 [PATCH v2] xen/x86: Zero out .bss for PV guests Boris Ostrovsky
@ 2016-02-24 16:05 ` Brian Gerst
  2016-02-24 16:33   ` Boris Ostrovsky
  2016-02-24 17:26 ` [Xen-devel] " Andrew Cooper
  1 sibling, 1 reply; 5+ messages in thread
From: Brian Gerst @ 2016-02-24 16:05 UTC (permalink / raw)
  To: Boris Ostrovsky
  Cc: Konrad Rzeszutek Wilk, David Vrabel, xen-devel,
	Linux Kernel Mailing List, mcgrof, stable

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

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

* Re: [PATCH v2] xen/x86: Zero out .bss for PV guests
  2016-02-24 16:05 ` Brian Gerst
@ 2016-02-24 16:33   ` Boris Ostrovsky
  0 siblings, 0 replies; 5+ messages in thread
From: Boris Ostrovsky @ 2016-02-24 16:33 UTC (permalink / raw)
  To: Brian Gerst
  Cc: Konrad Rzeszutek Wilk, David Vrabel, xen-devel,
	Linux Kernel Mailing List, mcgrof, stable

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

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

* Re: [Xen-devel] [PATCH v2] xen/x86: Zero out .bss for PV guests
  2016-02-24 15:19 [PATCH v2] xen/x86: Zero out .bss for PV guests Boris Ostrovsky
  2016-02-24 16:05 ` Brian Gerst
@ 2016-02-24 17:26 ` Andrew Cooper
  2016-02-24 17:48   ` Boris Ostrovsky
  1 sibling, 1 reply; 5+ messages in thread
From: Andrew Cooper @ 2016-02-24 17:26 UTC (permalink / raw)
  To: Boris Ostrovsky, konrad.wilk, david.vrabel
  Cc: xen-devel, mcgrof, linux-kernel, stable

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

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

* Re: [Xen-devel] [PATCH v2] xen/x86: Zero out .bss for PV guests
  2016-02-24 17:26 ` [Xen-devel] " Andrew Cooper
@ 2016-02-24 17:48   ` Boris Ostrovsky
  0 siblings, 0 replies; 5+ messages in thread
From: Boris Ostrovsky @ 2016-02-24 17:48 UTC (permalink / raw)
  To: Andrew Cooper, konrad.wilk, david.vrabel
  Cc: xen-devel, mcgrof, linux-kernel, stable

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

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

end of thread, other threads:[~2016-02-24 17:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-24 15:19 [PATCH v2] xen/x86: Zero out .bss for PV guests Boris Ostrovsky
2016-02-24 16:05 ` Brian Gerst
2016-02-24 16:33   ` Boris Ostrovsky
2016-02-24 17:26 ` [Xen-devel] " Andrew Cooper
2016-02-24 17:48   ` Boris Ostrovsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox