Re: [PATCH v12 1/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdline from KEXEC

2018-12-06 Thread Chao Fan
On Fri, Dec 07, 2018 at 10:50:21AM +0800, Baoquan He wrote:
>On 12/07/18 at 10:10am, Baoquan He wrote:
>> Hi,
>> 
>> On 11/29/18 at 04:10pm, Masayoshi Mizuma wrote:
>> > > diff --git a/arch/x86/boot/compressed/misc.c 
>> > > b/arch/x86/boot/compressed/misc.c
>> > > index 8dd1d5ccae58..e51713fe3add 100644
>> > > --- a/arch/x86/boot/compressed/misc.c
>> > > +++ b/arch/x86/boot/compressed/misc.c
>> > > @@ -12,6 +12,7 @@
>> > >   * High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
>> > >   */
>> > >  
>> > > +#define BOOT_CTYPE_H
>> > >  #include "misc.h"
>> > >  #include "error.h"
>> > >  #include "pgtable.h"
>> > > @@ -426,3 +427,7 @@ void fortify_panic(const char *name)
>> > >  {
>> > >  error("detected buffer overflow");
>> > >  }
>> > > +
>> > > +#ifdef BOOT_STRING
>> > > +#include "../../../../lib/kstrtox.c"
>> > > +#endif
>> > > diff --git a/arch/x86/boot/compressed/misc.h 
>> > > b/arch/x86/boot/compressed/misc.h
>> > > index a1d5918765f3..809c31effa4b 100644
>> > > --- a/arch/x86/boot/compressed/misc.h
>> > > +++ b/arch/x86/boot/compressed/misc.h
>> > > @@ -116,3 +116,7 @@ static inline void console_init(void)
>> > >  void set_sev_encryption_mask(void);
>> > >  
>> > >  #endif
>> > > +
>> > > +/* acpitb.c */
>> > > +#define BOOT_STRING
>> > > +extern int kstrtoull(const char *s, unsigned int base, unsigned long 
>> > > long *res);
>> > > diff --git a/lib/kstrtox.c b/lib/kstrtox.c
>> > > index 1006bf70bf74..a0ac1b2257b8 100644
>> > > --- a/lib/kstrtox.c
>> > > +++ b/lib/kstrtox.c
>> > > @@ -126,6 +126,9 @@ int kstrtoull(const char *s, unsigned int base, 
>> > > unsigned long long *res)
>> > >  }
>> > >  EXPORT_SYMBOL(kstrtoull);
>> > >  
>> > > +/* Make compressed period code be able to use kstrtoull(). */
>> > > +#ifndef BOOT_STRING
>> > 
>> > I got the following build error.
>> > 
>> > ]$ make arch/x86/boot/compressed/misc.o
>> >   CALLscripts/checksyscalls.sh
>> >   DESCEND  objtool
>> >   CC  arch/x86/boot/compressed/misc.o
>> > ld: -r and -pie may not be used together
>> > make[1]: *** [scripts/Makefile.build:294: arch/x86/boot/compressed/misc.o] 
>> > Error 1
>> > make: *** [Makefile:1715: arch/x86/boot/compressed/misc.o] Error 2
>> 
>> I have met this issue when change code in boot/compressed/kaslr.c.
>> 
>> I remember Ingo merged my patch and found this build error. Since if 
>> CONFIG_MODULES=n EXPORT_SYMBOL is defined as empty in
>> include/linux/export.h, that's why you can only meet it only if
>> CONFIG_MODULES=y.
>> 
>> I remember I just muted it with below code, please check commit
>> d52e7d5a95.
>> 
>> +#define _LINUX_EXPORT_H
>> +#define EXPORT_SYMBOL(sym)
>
>I made below change, it passed. My another question is why you need
>include "lib/kstrtox.c" into misc.c. Does it make sense if you plan to
>use it to replace simple_strtoull() in arch/x86/boot/string.c ?
>
>diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
>index e51713fe3add..777e807756e8 100644
>--- a/arch/x86/boot/compressed/misc.c
>+++ b/arch/x86/boot/compressed/misc.c
>@@ -13,6 +13,8 @@
>  */
> 
> #define BOOT_CTYPE_H
>+#define __DISABLE_EXPORTS
>+
> #include "misc.h"
> #include "error.h"
> #include "pgtable.h"
>
>I just tried to include it into boot/string.c, there's no any problem.

Thanks for your help, I think it's better to include it into
boot/string.c.

Thanks,
Chao Fan
>
>Thanks
>Baoquan
>
>




Re: [PATCH v12 1/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdline from KEXEC

2018-12-06 Thread Chao Fan
On Fri, Dec 07, 2018 at 10:50:21AM +0800, Baoquan He wrote:
>On 12/07/18 at 10:10am, Baoquan He wrote:
>> Hi,
>> 
>> On 11/29/18 at 04:10pm, Masayoshi Mizuma wrote:
>> > > diff --git a/arch/x86/boot/compressed/misc.c 
>> > > b/arch/x86/boot/compressed/misc.c
>> > > index 8dd1d5ccae58..e51713fe3add 100644
>> > > --- a/arch/x86/boot/compressed/misc.c
>> > > +++ b/arch/x86/boot/compressed/misc.c
>> > > @@ -12,6 +12,7 @@
>> > >   * High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
>> > >   */
>> > >  
>> > > +#define BOOT_CTYPE_H
>> > >  #include "misc.h"
>> > >  #include "error.h"
>> > >  #include "pgtable.h"
>> > > @@ -426,3 +427,7 @@ void fortify_panic(const char *name)
>> > >  {
>> > >  error("detected buffer overflow");
>> > >  }
>> > > +
>> > > +#ifdef BOOT_STRING
>> > > +#include "../../../../lib/kstrtox.c"
>> > > +#endif
>> > > diff --git a/arch/x86/boot/compressed/misc.h 
>> > > b/arch/x86/boot/compressed/misc.h
>> > > index a1d5918765f3..809c31effa4b 100644
>> > > --- a/arch/x86/boot/compressed/misc.h
>> > > +++ b/arch/x86/boot/compressed/misc.h
>> > > @@ -116,3 +116,7 @@ static inline void console_init(void)
>> > >  void set_sev_encryption_mask(void);
>> > >  
>> > >  #endif
>> > > +
>> > > +/* acpitb.c */
>> > > +#define BOOT_STRING
>> > > +extern int kstrtoull(const char *s, unsigned int base, unsigned long 
>> > > long *res);
>> > > diff --git a/lib/kstrtox.c b/lib/kstrtox.c
>> > > index 1006bf70bf74..a0ac1b2257b8 100644
>> > > --- a/lib/kstrtox.c
>> > > +++ b/lib/kstrtox.c
>> > > @@ -126,6 +126,9 @@ int kstrtoull(const char *s, unsigned int base, 
>> > > unsigned long long *res)
>> > >  }
>> > >  EXPORT_SYMBOL(kstrtoull);
>> > >  
>> > > +/* Make compressed period code be able to use kstrtoull(). */
>> > > +#ifndef BOOT_STRING
>> > 
>> > I got the following build error.
>> > 
>> > ]$ make arch/x86/boot/compressed/misc.o
>> >   CALLscripts/checksyscalls.sh
>> >   DESCEND  objtool
>> >   CC  arch/x86/boot/compressed/misc.o
>> > ld: -r and -pie may not be used together
>> > make[1]: *** [scripts/Makefile.build:294: arch/x86/boot/compressed/misc.o] 
>> > Error 1
>> > make: *** [Makefile:1715: arch/x86/boot/compressed/misc.o] Error 2
>> 
>> I have met this issue when change code in boot/compressed/kaslr.c.
>> 
>> I remember Ingo merged my patch and found this build error. Since if 
>> CONFIG_MODULES=n EXPORT_SYMBOL is defined as empty in
>> include/linux/export.h, that's why you can only meet it only if
>> CONFIG_MODULES=y.
>> 
>> I remember I just muted it with below code, please check commit
>> d52e7d5a95.
>> 
>> +#define _LINUX_EXPORT_H
>> +#define EXPORT_SYMBOL(sym)
>
>I made below change, it passed. My another question is why you need
>include "lib/kstrtox.c" into misc.c. Does it make sense if you plan to
>use it to replace simple_strtoull() in arch/x86/boot/string.c ?
>
>diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
>index e51713fe3add..777e807756e8 100644
>--- a/arch/x86/boot/compressed/misc.c
>+++ b/arch/x86/boot/compressed/misc.c
>@@ -13,6 +13,8 @@
>  */
> 
> #define BOOT_CTYPE_H
>+#define __DISABLE_EXPORTS
>+
> #include "misc.h"
> #include "error.h"
> #include "pgtable.h"
>
>I just tried to include it into boot/string.c, there's no any problem.

Thanks for your help, I think it's better to include it into
boot/string.c.

Thanks,
Chao Fan
>
>Thanks
>Baoquan
>
>




Re: [PATCH v12 1/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdline from KEXEC

2018-12-06 Thread Baoquan He
On 12/07/18 at 10:10am, Baoquan He wrote:
> Hi,
> 
> On 11/29/18 at 04:10pm, Masayoshi Mizuma wrote:
> > > diff --git a/arch/x86/boot/compressed/misc.c 
> > > b/arch/x86/boot/compressed/misc.c
> > > index 8dd1d5ccae58..e51713fe3add 100644
> > > --- a/arch/x86/boot/compressed/misc.c
> > > +++ b/arch/x86/boot/compressed/misc.c
> > > @@ -12,6 +12,7 @@
> > >   * High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
> > >   */
> > >  
> > > +#define BOOT_CTYPE_H
> > >  #include "misc.h"
> > >  #include "error.h"
> > >  #include "pgtable.h"
> > > @@ -426,3 +427,7 @@ void fortify_panic(const char *name)
> > >  {
> > >   error("detected buffer overflow");
> > >  }
> > > +
> > > +#ifdef BOOT_STRING
> > > +#include "../../../../lib/kstrtox.c"
> > > +#endif
> > > diff --git a/arch/x86/boot/compressed/misc.h 
> > > b/arch/x86/boot/compressed/misc.h
> > > index a1d5918765f3..809c31effa4b 100644
> > > --- a/arch/x86/boot/compressed/misc.h
> > > +++ b/arch/x86/boot/compressed/misc.h
> > > @@ -116,3 +116,7 @@ static inline void console_init(void)
> > >  void set_sev_encryption_mask(void);
> > >  
> > >  #endif
> > > +
> > > +/* acpitb.c */
> > > +#define BOOT_STRING
> > > +extern int kstrtoull(const char *s, unsigned int base, unsigned long 
> > > long *res);
> > > diff --git a/lib/kstrtox.c b/lib/kstrtox.c
> > > index 1006bf70bf74..a0ac1b2257b8 100644
> > > --- a/lib/kstrtox.c
> > > +++ b/lib/kstrtox.c
> > > @@ -126,6 +126,9 @@ int kstrtoull(const char *s, unsigned int base, 
> > > unsigned long long *res)
> > >  }
> > >  EXPORT_SYMBOL(kstrtoull);
> > >  
> > > +/* Make compressed period code be able to use kstrtoull(). */
> > > +#ifndef BOOT_STRING
> > 
> > I got the following build error.
> > 
> > ]$ make arch/x86/boot/compressed/misc.o
> >   CALLscripts/checksyscalls.sh
> >   DESCEND  objtool
> >   CC  arch/x86/boot/compressed/misc.o
> > ld: -r and -pie may not be used together
> > make[1]: *** [scripts/Makefile.build:294: arch/x86/boot/compressed/misc.o] 
> > Error 1
> > make: *** [Makefile:1715: arch/x86/boot/compressed/misc.o] Error 2
> 
> I have met this issue when change code in boot/compressed/kaslr.c.
> 
> I remember Ingo merged my patch and found this build error. Since if 
> CONFIG_MODULES=n EXPORT_SYMBOL is defined as empty in
> include/linux/export.h, that's why you can only meet it only if
> CONFIG_MODULES=y.
> 
> I remember I just muted it with below code, please check commit
> d52e7d5a95.
> 
> +#define _LINUX_EXPORT_H
> +#define EXPORT_SYMBOL(sym)

I made below change, it passed. My another question is why you need
include "lib/kstrtox.c" into misc.c. Does it make sense if you plan to
use it to replace simple_strtoull() in arch/x86/boot/string.c ?

diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
index e51713fe3add..777e807756e8 100644
--- a/arch/x86/boot/compressed/misc.c
+++ b/arch/x86/boot/compressed/misc.c
@@ -13,6 +13,8 @@
  */
 
 #define BOOT_CTYPE_H
+#define __DISABLE_EXPORTS
+
 #include "misc.h"
 #include "error.h"
 #include "pgtable.h"

I just tried to include it into boot/string.c, there's no any problem.

Thanks
Baoquan


Re: [PATCH v12 1/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdline from KEXEC

2018-12-06 Thread Baoquan He
On 12/07/18 at 10:10am, Baoquan He wrote:
> Hi,
> 
> On 11/29/18 at 04:10pm, Masayoshi Mizuma wrote:
> > > diff --git a/arch/x86/boot/compressed/misc.c 
> > > b/arch/x86/boot/compressed/misc.c
> > > index 8dd1d5ccae58..e51713fe3add 100644
> > > --- a/arch/x86/boot/compressed/misc.c
> > > +++ b/arch/x86/boot/compressed/misc.c
> > > @@ -12,6 +12,7 @@
> > >   * High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
> > >   */
> > >  
> > > +#define BOOT_CTYPE_H
> > >  #include "misc.h"
> > >  #include "error.h"
> > >  #include "pgtable.h"
> > > @@ -426,3 +427,7 @@ void fortify_panic(const char *name)
> > >  {
> > >   error("detected buffer overflow");
> > >  }
> > > +
> > > +#ifdef BOOT_STRING
> > > +#include "../../../../lib/kstrtox.c"
> > > +#endif
> > > diff --git a/arch/x86/boot/compressed/misc.h 
> > > b/arch/x86/boot/compressed/misc.h
> > > index a1d5918765f3..809c31effa4b 100644
> > > --- a/arch/x86/boot/compressed/misc.h
> > > +++ b/arch/x86/boot/compressed/misc.h
> > > @@ -116,3 +116,7 @@ static inline void console_init(void)
> > >  void set_sev_encryption_mask(void);
> > >  
> > >  #endif
> > > +
> > > +/* acpitb.c */
> > > +#define BOOT_STRING
> > > +extern int kstrtoull(const char *s, unsigned int base, unsigned long 
> > > long *res);
> > > diff --git a/lib/kstrtox.c b/lib/kstrtox.c
> > > index 1006bf70bf74..a0ac1b2257b8 100644
> > > --- a/lib/kstrtox.c
> > > +++ b/lib/kstrtox.c
> > > @@ -126,6 +126,9 @@ int kstrtoull(const char *s, unsigned int base, 
> > > unsigned long long *res)
> > >  }
> > >  EXPORT_SYMBOL(kstrtoull);
> > >  
> > > +/* Make compressed period code be able to use kstrtoull(). */
> > > +#ifndef BOOT_STRING
> > 
> > I got the following build error.
> > 
> > ]$ make arch/x86/boot/compressed/misc.o
> >   CALLscripts/checksyscalls.sh
> >   DESCEND  objtool
> >   CC  arch/x86/boot/compressed/misc.o
> > ld: -r and -pie may not be used together
> > make[1]: *** [scripts/Makefile.build:294: arch/x86/boot/compressed/misc.o] 
> > Error 1
> > make: *** [Makefile:1715: arch/x86/boot/compressed/misc.o] Error 2
> 
> I have met this issue when change code in boot/compressed/kaslr.c.
> 
> I remember Ingo merged my patch and found this build error. Since if 
> CONFIG_MODULES=n EXPORT_SYMBOL is defined as empty in
> include/linux/export.h, that's why you can only meet it only if
> CONFIG_MODULES=y.
> 
> I remember I just muted it with below code, please check commit
> d52e7d5a95.
> 
> +#define _LINUX_EXPORT_H
> +#define EXPORT_SYMBOL(sym)

I made below change, it passed. My another question is why you need
include "lib/kstrtox.c" into misc.c. Does it make sense if you plan to
use it to replace simple_strtoull() in arch/x86/boot/string.c ?

diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
index e51713fe3add..777e807756e8 100644
--- a/arch/x86/boot/compressed/misc.c
+++ b/arch/x86/boot/compressed/misc.c
@@ -13,6 +13,8 @@
  */
 
 #define BOOT_CTYPE_H
+#define __DISABLE_EXPORTS
+
 #include "misc.h"
 #include "error.h"
 #include "pgtable.h"

I just tried to include it into boot/string.c, there's no any problem.

Thanks
Baoquan


Re: [PATCH v12 1/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdline from KEXEC

2018-12-06 Thread Baoquan He
Hi,

On 11/29/18 at 04:10pm, Masayoshi Mizuma wrote:
> > diff --git a/arch/x86/boot/compressed/misc.c 
> > b/arch/x86/boot/compressed/misc.c
> > index 8dd1d5ccae58..e51713fe3add 100644
> > --- a/arch/x86/boot/compressed/misc.c
> > +++ b/arch/x86/boot/compressed/misc.c
> > @@ -12,6 +12,7 @@
> >   * High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
> >   */
> >  
> > +#define BOOT_CTYPE_H
> >  #include "misc.h"
> >  #include "error.h"
> >  #include "pgtable.h"
> > @@ -426,3 +427,7 @@ void fortify_panic(const char *name)
> >  {
> > error("detected buffer overflow");
> >  }
> > +
> > +#ifdef BOOT_STRING
> > +#include "../../../../lib/kstrtox.c"
> > +#endif
> > diff --git a/arch/x86/boot/compressed/misc.h 
> > b/arch/x86/boot/compressed/misc.h
> > index a1d5918765f3..809c31effa4b 100644
> > --- a/arch/x86/boot/compressed/misc.h
> > +++ b/arch/x86/boot/compressed/misc.h
> > @@ -116,3 +116,7 @@ static inline void console_init(void)
> >  void set_sev_encryption_mask(void);
> >  
> >  #endif
> > +
> > +/* acpitb.c */
> > +#define BOOT_STRING
> > +extern int kstrtoull(const char *s, unsigned int base, unsigned long long 
> > *res);
> > diff --git a/lib/kstrtox.c b/lib/kstrtox.c
> > index 1006bf70bf74..a0ac1b2257b8 100644
> > --- a/lib/kstrtox.c
> > +++ b/lib/kstrtox.c
> > @@ -126,6 +126,9 @@ int kstrtoull(const char *s, unsigned int base, 
> > unsigned long long *res)
> >  }
> >  EXPORT_SYMBOL(kstrtoull);
> >  
> > +/* Make compressed period code be able to use kstrtoull(). */
> > +#ifndef BOOT_STRING
> 
> I got the following build error.
> 
> ]$ make arch/x86/boot/compressed/misc.o
>   CALLscripts/checksyscalls.sh
>   DESCEND  objtool
>   CC  arch/x86/boot/compressed/misc.o
> ld: -r and -pie may not be used together
> make[1]: *** [scripts/Makefile.build:294: arch/x86/boot/compressed/misc.o] 
> Error 1
> make: *** [Makefile:1715: arch/x86/boot/compressed/misc.o] Error 2

I have met this issue when change code in boot/compressed/kaslr.c.

I remember Ingo merged my patch and found this build error. Since if 
CONFIG_MODULES=n EXPORT_SYMBOL is defined as empty in
include/linux/export.h, that's why you can only meet it only if
CONFIG_MODULES=y.

I remember I just muted it with below code, please check commit
d52e7d5a95.

+#define _LINUX_EXPORT_H
+#define EXPORT_SYMBOL(sym)

commit d52e7d5a952c5e35783f96e8c5b7fcffbb0d7c60
Author: Baoquan He 
Date:   Sat May 13 13:46:28 2017 +0800

x86/KASLR: Parse all 'memmap=' boot option entries

Later in commit f922c4abdf76, Ard added a new switch __DISABLE_EXPORTS.
So you can just add #define __DISABLE_EXPORTS into misc.c. Then you
don't need to copy those lib functions to boot. Maintaining two copies
might have trouble if it has updates later.

commit f922c4abdf7648523589abee9460c87f51630d2f
Author: Ard Biesheuvel 
Date:   Tue Aug 21 21:56:04 2018 -0700

module: allow symbol exports to be disabled

Thanks
Baoquan

> ]$
> 
> I think this error gets fixed by changing the BOOT_STRING ifndef
> order before the EXPORT_SYMBOL, like this:
> 
> #ifndef BOOT_STRING
> EXPORT_SYMBOL(kstrtoull);
> 
> I'm not sure this change is a good way...
> 
> Thanks,
> Masa


Re: [PATCH v12 1/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdline from KEXEC

2018-12-06 Thread Baoquan He
Hi,

On 11/29/18 at 04:10pm, Masayoshi Mizuma wrote:
> > diff --git a/arch/x86/boot/compressed/misc.c 
> > b/arch/x86/boot/compressed/misc.c
> > index 8dd1d5ccae58..e51713fe3add 100644
> > --- a/arch/x86/boot/compressed/misc.c
> > +++ b/arch/x86/boot/compressed/misc.c
> > @@ -12,6 +12,7 @@
> >   * High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
> >   */
> >  
> > +#define BOOT_CTYPE_H
> >  #include "misc.h"
> >  #include "error.h"
> >  #include "pgtable.h"
> > @@ -426,3 +427,7 @@ void fortify_panic(const char *name)
> >  {
> > error("detected buffer overflow");
> >  }
> > +
> > +#ifdef BOOT_STRING
> > +#include "../../../../lib/kstrtox.c"
> > +#endif
> > diff --git a/arch/x86/boot/compressed/misc.h 
> > b/arch/x86/boot/compressed/misc.h
> > index a1d5918765f3..809c31effa4b 100644
> > --- a/arch/x86/boot/compressed/misc.h
> > +++ b/arch/x86/boot/compressed/misc.h
> > @@ -116,3 +116,7 @@ static inline void console_init(void)
> >  void set_sev_encryption_mask(void);
> >  
> >  #endif
> > +
> > +/* acpitb.c */
> > +#define BOOT_STRING
> > +extern int kstrtoull(const char *s, unsigned int base, unsigned long long 
> > *res);
> > diff --git a/lib/kstrtox.c b/lib/kstrtox.c
> > index 1006bf70bf74..a0ac1b2257b8 100644
> > --- a/lib/kstrtox.c
> > +++ b/lib/kstrtox.c
> > @@ -126,6 +126,9 @@ int kstrtoull(const char *s, unsigned int base, 
> > unsigned long long *res)
> >  }
> >  EXPORT_SYMBOL(kstrtoull);
> >  
> > +/* Make compressed period code be able to use kstrtoull(). */
> > +#ifndef BOOT_STRING
> 
> I got the following build error.
> 
> ]$ make arch/x86/boot/compressed/misc.o
>   CALLscripts/checksyscalls.sh
>   DESCEND  objtool
>   CC  arch/x86/boot/compressed/misc.o
> ld: -r and -pie may not be used together
> make[1]: *** [scripts/Makefile.build:294: arch/x86/boot/compressed/misc.o] 
> Error 1
> make: *** [Makefile:1715: arch/x86/boot/compressed/misc.o] Error 2

I have met this issue when change code in boot/compressed/kaslr.c.

I remember Ingo merged my patch and found this build error. Since if 
CONFIG_MODULES=n EXPORT_SYMBOL is defined as empty in
include/linux/export.h, that's why you can only meet it only if
CONFIG_MODULES=y.

I remember I just muted it with below code, please check commit
d52e7d5a95.

+#define _LINUX_EXPORT_H
+#define EXPORT_SYMBOL(sym)

commit d52e7d5a952c5e35783f96e8c5b7fcffbb0d7c60
Author: Baoquan He 
Date:   Sat May 13 13:46:28 2017 +0800

x86/KASLR: Parse all 'memmap=' boot option entries

Later in commit f922c4abdf76, Ard added a new switch __DISABLE_EXPORTS.
So you can just add #define __DISABLE_EXPORTS into misc.c. Then you
don't need to copy those lib functions to boot. Maintaining two copies
might have trouble if it has updates later.

commit f922c4abdf7648523589abee9460c87f51630d2f
Author: Ard Biesheuvel 
Date:   Tue Aug 21 21:56:04 2018 -0700

module: allow symbol exports to be disabled

Thanks
Baoquan

> ]$
> 
> I think this error gets fixed by changing the BOOT_STRING ifndef
> order before the EXPORT_SYMBOL, like this:
> 
> #ifndef BOOT_STRING
> EXPORT_SYMBOL(kstrtoull);
> 
> I'm not sure this change is a good way...
> 
> Thanks,
> Masa


Re: [PATCH v12 1/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdline from KEXEC

2018-12-06 Thread Chao Fan
Hi Boris, Baoquan and Masa,

When copying kstrtoull() and functions needed to arch/x86/boot/string.c,
I got an error in LD period:

  LD  arch/x86/boot/setup.elf
ld: arch/x86/boot/string.o: in function `div_u64_rem':
/home/cfan/code/tip/./include/linux/math64.h:28: undefined reference to 
`__udivdi3'
make[1]: *** [arch/x86/boot/Makefile:105: arch/x86/boot/setup.elf] Error 1
make: *** [arch/x86/Makefile:289: bzImage] Error 2

I google it and the key problem is div_u64(ULLONG_MAX - val, base))
when dividend is u64 and divisor is u32, the dividend must be a variable,
since the result will be stored in the first variable.
So here when I changed it to ((ULLONG_MAX - val) / base), I got the
same error.
But what puzzled me is, why the cdoe in lib/kstrtox.c works well.
And in old version PATCHSET, I ever copy the code to
arch/x86/boot/compressed/misc.c, it also worked well.

So I wonder if there are some options I miss or some problems.
The patch is below.

Thanks,
Chao Fan


diff --git a/arch/x86/boot/string.c b/arch/x86/boot/string.c
index c4428a176973..62ffe0437c8e 100644
--- a/arch/x86/boot/string.c
+++ b/arch/x86/boot/string.c
@@ -13,6 +13,9 @@
  */

 #include 
+#include 
+#include 
+#include 
 #include 
 #include "ctype.h"
 #include "string.h"
@@ -187,3 +190,112 @@ char *strchr(const char *s, int c)
return NULL;
return (char *)s;
 }
+
+static inline char _tolower(const char c)
+{
+   return c | 0x20;
+}
+
+const char *_parse_integer_fixup_radix(const char *s, unsigned int *base)
+{
+   if (*base == 0) {
+   if (s[0] == '0') {
+   if (_tolower(s[1]) == 'x' && isxdigit(s[2]))
+   *base = 16;
+   else
+   *base = 8;
+   } else
+   *base = 10;
+   }
+   if (*base == 16 && s[0] == '0' && _tolower(s[1]) == 'x')
+   s += 2;
+   return s;
+}
+
+/*
+ * Convert non-negative integer string representation in explicitly given radix
+ * to an integer.
+ * Return number of characters consumed maybe or-ed with overflow bit.
+ * If overflow occurs, result integer (incorrect) is still returned.
+ *
+ * Don't you dare use this function.
+ */
+unsigned int _parse_integer(const char *s, unsigned int base, unsigned long 
long *p)
+{
+   unsigned long long res;
+   unsigned int rv;
+
+   res = 0;
+   rv = 0;
+   while (1) {
+   unsigned int c = *s;
+   unsigned int lc = c | 0x20; /* don't tolower() this line */
+   unsigned int val;
+
+   if ('0' <= c && c <= '9')
+   val = c - '0';
+   else if ('a' <= lc && lc <= 'f')
+   val = lc - 'a' + 10;
+   else
+   break;
+
+   if (val >= base)
+   break;
+   /*
+* Check for overflow only if we are within range of
+* it in the max base we support (16)
+*/
+   if (unlikely(res & (~0ull << 60))) {
+   if (res > div_u64(ULLONG_MAX - val, base))
+   rv |= KSTRTOX_OVERFLOW;
+   }
+   res = res * base + val;
+   rv++;
+   s++;
+   }
+   *p = res;
+   return rv;
+}
+
+static int _kstrtoull(const char *s, unsigned int base, unsigned long long 
*res)
+{
+   unsigned long long _res;
+   unsigned int rv;
+
+   s = _parse_integer_fixup_radix(s, );
+   rv = _parse_integer(s, base, &_res);
+   if (rv & KSTRTOX_OVERFLOW)
+   return -ERANGE;
+   if (rv == 0)
+   return -EINVAL;
+   s += rv;
+   if (*s == '\n')
+   s++;
+   if (*s)
+   return -EINVAL;
+   *res = _res;
+   return 0;
+}
+
+/**
+ * kstrtoull - convert a string to an unsigned long long
+ * @s: The start of the string. The string must be null-terminated, and may 
also
+ *  include a single newline before its terminating null. The first character
+ *  may also be a plus sign, but not a minus sign.
+ * @base: The number base to use. The maximum supported base is 16. If base is
+ *  given as 0, then the base of the string is automatically detected with the
+ *  conventional semantics - If it begins with 0x the number will be parsed as 
a
+ *  hexadecimal (case insensitive), if it otherwise begins with 0, it will be
+ *  parsed as an octal number. Otherwise it will be parsed as a decimal.
+ * @res: Where to write the result of the conversion on success.
+ *
+ * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
+ * Used as a replacement for the obsolete simple_strtoull. Return code must
+ * be checked.
+ */
+int kstrtoull(const char *s, unsigned int base, unsigned long long *res)
+{
+   if (s[0] == '+')
+   s++;
+   return _kstrtoull(s, base, res);
+}
diff 

Re: [PATCH v12 1/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdline from KEXEC

2018-12-06 Thread Chao Fan
Hi Boris, Baoquan and Masa,

When copying kstrtoull() and functions needed to arch/x86/boot/string.c,
I got an error in LD period:

  LD  arch/x86/boot/setup.elf
ld: arch/x86/boot/string.o: in function `div_u64_rem':
/home/cfan/code/tip/./include/linux/math64.h:28: undefined reference to 
`__udivdi3'
make[1]: *** [arch/x86/boot/Makefile:105: arch/x86/boot/setup.elf] Error 1
make: *** [arch/x86/Makefile:289: bzImage] Error 2

I google it and the key problem is div_u64(ULLONG_MAX - val, base))
when dividend is u64 and divisor is u32, the dividend must be a variable,
since the result will be stored in the first variable.
So here when I changed it to ((ULLONG_MAX - val) / base), I got the
same error.
But what puzzled me is, why the cdoe in lib/kstrtox.c works well.
And in old version PATCHSET, I ever copy the code to
arch/x86/boot/compressed/misc.c, it also worked well.

So I wonder if there are some options I miss or some problems.
The patch is below.

Thanks,
Chao Fan


diff --git a/arch/x86/boot/string.c b/arch/x86/boot/string.c
index c4428a176973..62ffe0437c8e 100644
--- a/arch/x86/boot/string.c
+++ b/arch/x86/boot/string.c
@@ -13,6 +13,9 @@
  */

 #include 
+#include 
+#include 
+#include 
 #include 
 #include "ctype.h"
 #include "string.h"
@@ -187,3 +190,112 @@ char *strchr(const char *s, int c)
return NULL;
return (char *)s;
 }
+
+static inline char _tolower(const char c)
+{
+   return c | 0x20;
+}
+
+const char *_parse_integer_fixup_radix(const char *s, unsigned int *base)
+{
+   if (*base == 0) {
+   if (s[0] == '0') {
+   if (_tolower(s[1]) == 'x' && isxdigit(s[2]))
+   *base = 16;
+   else
+   *base = 8;
+   } else
+   *base = 10;
+   }
+   if (*base == 16 && s[0] == '0' && _tolower(s[1]) == 'x')
+   s += 2;
+   return s;
+}
+
+/*
+ * Convert non-negative integer string representation in explicitly given radix
+ * to an integer.
+ * Return number of characters consumed maybe or-ed with overflow bit.
+ * If overflow occurs, result integer (incorrect) is still returned.
+ *
+ * Don't you dare use this function.
+ */
+unsigned int _parse_integer(const char *s, unsigned int base, unsigned long 
long *p)
+{
+   unsigned long long res;
+   unsigned int rv;
+
+   res = 0;
+   rv = 0;
+   while (1) {
+   unsigned int c = *s;
+   unsigned int lc = c | 0x20; /* don't tolower() this line */
+   unsigned int val;
+
+   if ('0' <= c && c <= '9')
+   val = c - '0';
+   else if ('a' <= lc && lc <= 'f')
+   val = lc - 'a' + 10;
+   else
+   break;
+
+   if (val >= base)
+   break;
+   /*
+* Check for overflow only if we are within range of
+* it in the max base we support (16)
+*/
+   if (unlikely(res & (~0ull << 60))) {
+   if (res > div_u64(ULLONG_MAX - val, base))
+   rv |= KSTRTOX_OVERFLOW;
+   }
+   res = res * base + val;
+   rv++;
+   s++;
+   }
+   *p = res;
+   return rv;
+}
+
+static int _kstrtoull(const char *s, unsigned int base, unsigned long long 
*res)
+{
+   unsigned long long _res;
+   unsigned int rv;
+
+   s = _parse_integer_fixup_radix(s, );
+   rv = _parse_integer(s, base, &_res);
+   if (rv & KSTRTOX_OVERFLOW)
+   return -ERANGE;
+   if (rv == 0)
+   return -EINVAL;
+   s += rv;
+   if (*s == '\n')
+   s++;
+   if (*s)
+   return -EINVAL;
+   *res = _res;
+   return 0;
+}
+
+/**
+ * kstrtoull - convert a string to an unsigned long long
+ * @s: The start of the string. The string must be null-terminated, and may 
also
+ *  include a single newline before its terminating null. The first character
+ *  may also be a plus sign, but not a minus sign.
+ * @base: The number base to use. The maximum supported base is 16. If base is
+ *  given as 0, then the base of the string is automatically detected with the
+ *  conventional semantics - If it begins with 0x the number will be parsed as 
a
+ *  hexadecimal (case insensitive), if it otherwise begins with 0, it will be
+ *  parsed as an octal number. Otherwise it will be parsed as a decimal.
+ * @res: Where to write the result of the conversion on success.
+ *
+ * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
+ * Used as a replacement for the obsolete simple_strtoull. Return code must
+ * be checked.
+ */
+int kstrtoull(const char *s, unsigned int base, unsigned long long *res)
+{
+   if (s[0] == '+')
+   s++;
+   return _kstrtoull(s, base, res);
+}
diff 

Re: [PATCH v12 1/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdline from KEXEC

2018-12-05 Thread Chao Fan
On Wed, Dec 05, 2018 at 03:58:14PM +0100, Borislav Petkov wrote:
>On Thu, Nov 29, 2018 at 04:16:27PM +0800, Chao Fan wrote:
>> To fix the conflict between KASLR and memory-hotremove, memory
>> information in SRAT table is necessary.
>> 
>> ACPI SRAT (System/Static Resource Affinity Table) can show the details
>> about memory ranges, including ranges of memory provided by hot-added
>> memory devices. SRAT table must be introduced by RSDP pointer (Root
>> System Description Pointer). So RSDP should be found firstly.
>> 
>> When booting form KEXEC/EFI/BIOS, the methods to find RSDP pointer
>> are different. When booting from KEXEC, 'acpi_rsdp' may have been
>> added to cmdline, so parse the cmdline and find the RSDP pointer.
>> 
>> Signed-off-by: Chao Fan 
>> ---
>>  arch/x86/boot/compressed/acpitb.c | 33 +++
>>  arch/x86/boot/compressed/misc.c   |  5 +
>>  arch/x86/boot/compressed/misc.h   |  4 
>>  lib/kstrtox.c |  5 +
>>  4 files changed, 47 insertions(+)
>>  create mode 100644 arch/x86/boot/compressed/acpitb.c
>> 
>> diff --git a/arch/x86/boot/compressed/acpitb.c 
>> b/arch/x86/boot/compressed/acpitb.c
>> new file mode 100644
>> index ..614c45655cff
>> --- /dev/null
>> +++ b/arch/x86/boot/compressed/acpitb.c
>
>Also, I guess calling that file simply "acpi.c" is good enough.

Fine, so change it next version.

>
>> @@ -0,0 +1,33 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +#define BOOT_CTYPE_H
>> +#include "misc.h"
>> +#include "error.h"
>> +
>> +#include 
>> +#include 
>
>asm/ headers come after linux/ header.

Will change the place of header.

Thanks,
Chao Fan

>
>...
>
>Thx.
>
>-- 
>Regards/Gruss,
>Boris.
>
>Good mailing practices for 400: avoid top-posting and trim the reply.
>
>




Re: [PATCH v12 1/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdline from KEXEC

2018-12-05 Thread Chao Fan
On Wed, Dec 05, 2018 at 03:58:14PM +0100, Borislav Petkov wrote:
>On Thu, Nov 29, 2018 at 04:16:27PM +0800, Chao Fan wrote:
>> To fix the conflict between KASLR and memory-hotremove, memory
>> information in SRAT table is necessary.
>> 
>> ACPI SRAT (System/Static Resource Affinity Table) can show the details
>> about memory ranges, including ranges of memory provided by hot-added
>> memory devices. SRAT table must be introduced by RSDP pointer (Root
>> System Description Pointer). So RSDP should be found firstly.
>> 
>> When booting form KEXEC/EFI/BIOS, the methods to find RSDP pointer
>> are different. When booting from KEXEC, 'acpi_rsdp' may have been
>> added to cmdline, so parse the cmdline and find the RSDP pointer.
>> 
>> Signed-off-by: Chao Fan 
>> ---
>>  arch/x86/boot/compressed/acpitb.c | 33 +++
>>  arch/x86/boot/compressed/misc.c   |  5 +
>>  arch/x86/boot/compressed/misc.h   |  4 
>>  lib/kstrtox.c |  5 +
>>  4 files changed, 47 insertions(+)
>>  create mode 100644 arch/x86/boot/compressed/acpitb.c
>> 
>> diff --git a/arch/x86/boot/compressed/acpitb.c 
>> b/arch/x86/boot/compressed/acpitb.c
>> new file mode 100644
>> index ..614c45655cff
>> --- /dev/null
>> +++ b/arch/x86/boot/compressed/acpitb.c
>
>Also, I guess calling that file simply "acpi.c" is good enough.

Fine, so change it next version.

>
>> @@ -0,0 +1,33 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +#define BOOT_CTYPE_H
>> +#include "misc.h"
>> +#include "error.h"
>> +
>> +#include 
>> +#include 
>
>asm/ headers come after linux/ header.

Will change the place of header.

Thanks,
Chao Fan

>
>...
>
>Thx.
>
>-- 
>Regards/Gruss,
>Boris.
>
>Good mailing practices for 400: avoid top-posting and trim the reply.
>
>




Re: [PATCH v12 1/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdline from KEXEC

2018-12-05 Thread Borislav Petkov
On Thu, Nov 29, 2018 at 04:16:27PM +0800, Chao Fan wrote:
> To fix the conflict between KASLR and memory-hotremove, memory
> information in SRAT table is necessary.
> 
> ACPI SRAT (System/Static Resource Affinity Table) can show the details
> about memory ranges, including ranges of memory provided by hot-added
> memory devices. SRAT table must be introduced by RSDP pointer (Root
> System Description Pointer). So RSDP should be found firstly.
> 
> When booting form KEXEC/EFI/BIOS, the methods to find RSDP pointer
> are different. When booting from KEXEC, 'acpi_rsdp' may have been
> added to cmdline, so parse the cmdline and find the RSDP pointer.
> 
> Signed-off-by: Chao Fan 
> ---
>  arch/x86/boot/compressed/acpitb.c | 33 +++
>  arch/x86/boot/compressed/misc.c   |  5 +
>  arch/x86/boot/compressed/misc.h   |  4 
>  lib/kstrtox.c |  5 +
>  4 files changed, 47 insertions(+)
>  create mode 100644 arch/x86/boot/compressed/acpitb.c
> 
> diff --git a/arch/x86/boot/compressed/acpitb.c 
> b/arch/x86/boot/compressed/acpitb.c
> new file mode 100644
> index ..614c45655cff
> --- /dev/null
> +++ b/arch/x86/boot/compressed/acpitb.c

Also, I guess calling that file simply "acpi.c" is good enough.

> @@ -0,0 +1,33 @@
> +// SPDX-License-Identifier: GPL-2.0
> +#define BOOT_CTYPE_H
> +#include "misc.h"
> +#include "error.h"
> +
> +#include 
> +#include 

asm/ headers come after linux/ header.

...

Thx.

-- 
Regards/Gruss,
Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.


Re: [PATCH v12 1/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdline from KEXEC

2018-12-05 Thread Borislav Petkov
On Thu, Nov 29, 2018 at 04:16:27PM +0800, Chao Fan wrote:
> To fix the conflict between KASLR and memory-hotremove, memory
> information in SRAT table is necessary.
> 
> ACPI SRAT (System/Static Resource Affinity Table) can show the details
> about memory ranges, including ranges of memory provided by hot-added
> memory devices. SRAT table must be introduced by RSDP pointer (Root
> System Description Pointer). So RSDP should be found firstly.
> 
> When booting form KEXEC/EFI/BIOS, the methods to find RSDP pointer
> are different. When booting from KEXEC, 'acpi_rsdp' may have been
> added to cmdline, so parse the cmdline and find the RSDP pointer.
> 
> Signed-off-by: Chao Fan 
> ---
>  arch/x86/boot/compressed/acpitb.c | 33 +++
>  arch/x86/boot/compressed/misc.c   |  5 +
>  arch/x86/boot/compressed/misc.h   |  4 
>  lib/kstrtox.c |  5 +
>  4 files changed, 47 insertions(+)
>  create mode 100644 arch/x86/boot/compressed/acpitb.c
> 
> diff --git a/arch/x86/boot/compressed/acpitb.c 
> b/arch/x86/boot/compressed/acpitb.c
> new file mode 100644
> index ..614c45655cff
> --- /dev/null
> +++ b/arch/x86/boot/compressed/acpitb.c

Also, I guess calling that file simply "acpi.c" is good enough.

> @@ -0,0 +1,33 @@
> +// SPDX-License-Identifier: GPL-2.0
> +#define BOOT_CTYPE_H
> +#include "misc.h"
> +#include "error.h"
> +
> +#include 
> +#include 

asm/ headers come after linux/ header.

...

Thx.

-- 
Regards/Gruss,
Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.


Re: [PATCH v12 1/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdline from KEXEC

2018-12-04 Thread Chao Fan
On Tue, Dec 04, 2018 at 07:34:00PM +0100, Borislav Petkov wrote:
>On Fri, Nov 30, 2018 at 10:29:14AM +0800, Chao Fan wrote:
>> Oh, thanks, will change it
>> char val[19];
>
>And make that 19 a define.

I will do that.

Thanks,
Chao Fan

>
>-- 
>Regards/Gruss,
>Boris.
>
>Good mailing practices for 400: avoid top-posting and trim the reply.
>
>




Re: [PATCH v12 1/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdline from KEXEC

2018-12-04 Thread Chao Fan
On Tue, Dec 04, 2018 at 07:34:00PM +0100, Borislav Petkov wrote:
>On Fri, Nov 30, 2018 at 10:29:14AM +0800, Chao Fan wrote:
>> Oh, thanks, will change it
>> char val[19];
>
>And make that 19 a define.

I will do that.

Thanks,
Chao Fan

>
>-- 
>Regards/Gruss,
>Boris.
>
>Good mailing practices for 400: avoid top-posting and trim the reply.
>
>




Re: [PATCH v12 1/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdline from KEXEC

2018-12-04 Thread Chao Fan
On Tue, Dec 04, 2018 at 07:42:20PM +0100, Borislav Petkov wrote:
>On Sat, Dec 01, 2018 at 02:05:39PM +0800, Chao Fan wrote:
>> >I built your whole patchset and got the error.
>> >The error depends on CONFIG_MODVERSIONS.
>> >If CONFIG_MODVERSIONS=y, you will get the build error.
>> 
>> Hi Masa,
>> 
>> Thanks, after that, I got the error.
>> About your solution, it can fix the error. But I am not sure whether
>> it's good.
>
>What does CONFIG_MODVERSIONS=y have to do with this? I don't see the
>connection.
>
>Also, your patch triggers another build error:
>
>ld -m elf_x86_64 -z noreloc-overflow -pie --no-dynamic-linker   -T 
>arch/x86/boot/compressed/vmlinux.lds arch/x86/boot/compressed/head_64.o 
>arch/x86/boot/compressed/misc.o arch/x86/boot/compressed/string.o 
>arch/x86/boot/compressed/cmdline.o arch/x86/boot/compressed/error.o 
>arch/x86/boot/compressed/piggy.o arch/x86/boot/compressed/cpuflags.o 
>arch/x86/boot/compressed/early_serial_console.o 
>arch/x86/boot/compressed/mem_encrypt.o arch/x86/boot/compressed/pgtable_64.o 
>arch/x86/boot/compressed/eboot.o arch/x86/boot/compressed/efi_stub_64.o 
>drivers/firmware/efi/libstub/lib.a arch/x86/boot/compressed/efi_thunk_64.o -o 
>arch/x86/boot/compressed/vmlinux
>ld: arch/x86/boot/compressed/misc.o: in function `_parse_integer_fixup_radix':
>misc.c:(.text+0x3057): undefined reference to `_ctype'
>make[2]: *** [arch/x86/boot/compressed/Makefile:116: 
>arch/x86/boot/compressed/vmlinux] Error 1
>make[1]: *** [arch/x86/boot/Makefile:112: arch/x86/boot/compressed/vmlinux] 
>Error 2
>make: *** [arch/x86/Makefile:289: bzImage] Error 2
>make: *** Waiting for unfinished jobs
>
>due to misc.o not seeing _ctype.
>
>Looks like this is going to become too hairy and perhaps it would
>be easier and cleaner if you copy all the functions needed into
>arch/x86/boot/cmdline.c and this way get rid of the crazy ifdeffery and
>the subtle build issues.
>
>I mean, we do this already in other places like perf tool is copying
>stuff selectively from kernel proper and since compressed/ is a
>completely separate stage, we probably should do that for the sake of
>keeping our sanity. :)

Thank you, I will do the copying job and consider more about putting
functions to arch/x86/boot/cmdline.c or arch/x86/boot/string.c.
Anyway, this method is simple.

Thanks,
Chao Fan

>
>Thx.
>
>-- 
>Regards/Gruss,
>Boris.
>
>Good mailing practices for 400: avoid top-posting and trim the reply.
>
>




Re: [PATCH v12 1/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdline from KEXEC

2018-12-04 Thread Chao Fan
On Tue, Dec 04, 2018 at 07:42:20PM +0100, Borislav Petkov wrote:
>On Sat, Dec 01, 2018 at 02:05:39PM +0800, Chao Fan wrote:
>> >I built your whole patchset and got the error.
>> >The error depends on CONFIG_MODVERSIONS.
>> >If CONFIG_MODVERSIONS=y, you will get the build error.
>> 
>> Hi Masa,
>> 
>> Thanks, after that, I got the error.
>> About your solution, it can fix the error. But I am not sure whether
>> it's good.
>
>What does CONFIG_MODVERSIONS=y have to do with this? I don't see the
>connection.
>
>Also, your patch triggers another build error:
>
>ld -m elf_x86_64 -z noreloc-overflow -pie --no-dynamic-linker   -T 
>arch/x86/boot/compressed/vmlinux.lds arch/x86/boot/compressed/head_64.o 
>arch/x86/boot/compressed/misc.o arch/x86/boot/compressed/string.o 
>arch/x86/boot/compressed/cmdline.o arch/x86/boot/compressed/error.o 
>arch/x86/boot/compressed/piggy.o arch/x86/boot/compressed/cpuflags.o 
>arch/x86/boot/compressed/early_serial_console.o 
>arch/x86/boot/compressed/mem_encrypt.o arch/x86/boot/compressed/pgtable_64.o 
>arch/x86/boot/compressed/eboot.o arch/x86/boot/compressed/efi_stub_64.o 
>drivers/firmware/efi/libstub/lib.a arch/x86/boot/compressed/efi_thunk_64.o -o 
>arch/x86/boot/compressed/vmlinux
>ld: arch/x86/boot/compressed/misc.o: in function `_parse_integer_fixup_radix':
>misc.c:(.text+0x3057): undefined reference to `_ctype'
>make[2]: *** [arch/x86/boot/compressed/Makefile:116: 
>arch/x86/boot/compressed/vmlinux] Error 1
>make[1]: *** [arch/x86/boot/Makefile:112: arch/x86/boot/compressed/vmlinux] 
>Error 2
>make: *** [arch/x86/Makefile:289: bzImage] Error 2
>make: *** Waiting for unfinished jobs
>
>due to misc.o not seeing _ctype.
>
>Looks like this is going to become too hairy and perhaps it would
>be easier and cleaner if you copy all the functions needed into
>arch/x86/boot/cmdline.c and this way get rid of the crazy ifdeffery and
>the subtle build issues.
>
>I mean, we do this already in other places like perf tool is copying
>stuff selectively from kernel proper and since compressed/ is a
>completely separate stage, we probably should do that for the sake of
>keeping our sanity. :)

Thank you, I will do the copying job and consider more about putting
functions to arch/x86/boot/cmdline.c or arch/x86/boot/string.c.
Anyway, this method is simple.

Thanks,
Chao Fan

>
>Thx.
>
>-- 
>Regards/Gruss,
>Boris.
>
>Good mailing practices for 400: avoid top-posting and trim the reply.
>
>




Re: [PATCH v12 1/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdline from KEXEC

2018-12-04 Thread Borislav Petkov
On Sat, Dec 01, 2018 at 02:05:39PM +0800, Chao Fan wrote:
> >I built your whole patchset and got the error.
> >The error depends on CONFIG_MODVERSIONS.
> >If CONFIG_MODVERSIONS=y, you will get the build error.
> 
> Hi Masa,
> 
> Thanks, after that, I got the error.
> About your solution, it can fix the error. But I am not sure whether
> it's good.

What does CONFIG_MODVERSIONS=y have to do with this? I don't see the
connection.

Also, your patch triggers another build error:

ld -m elf_x86_64 -z noreloc-overflow -pie --no-dynamic-linker   -T 
arch/x86/boot/compressed/vmlinux.lds arch/x86/boot/compressed/head_64.o 
arch/x86/boot/compressed/misc.o arch/x86/boot/compressed/string.o 
arch/x86/boot/compressed/cmdline.o arch/x86/boot/compressed/error.o 
arch/x86/boot/compressed/piggy.o arch/x86/boot/compressed/cpuflags.o 
arch/x86/boot/compressed/early_serial_console.o 
arch/x86/boot/compressed/mem_encrypt.o arch/x86/boot/compressed/pgtable_64.o 
arch/x86/boot/compressed/eboot.o arch/x86/boot/compressed/efi_stub_64.o 
drivers/firmware/efi/libstub/lib.a arch/x86/boot/compressed/efi_thunk_64.o -o 
arch/x86/boot/compressed/vmlinux
ld: arch/x86/boot/compressed/misc.o: in function `_parse_integer_fixup_radix':
misc.c:(.text+0x3057): undefined reference to `_ctype'
make[2]: *** [arch/x86/boot/compressed/Makefile:116: 
arch/x86/boot/compressed/vmlinux] Error 1
make[1]: *** [arch/x86/boot/Makefile:112: arch/x86/boot/compressed/vmlinux] 
Error 2
make: *** [arch/x86/Makefile:289: bzImage] Error 2
make: *** Waiting for unfinished jobs

due to misc.o not seeing _ctype.

Looks like this is going to become too hairy and perhaps it would
be easier and cleaner if you copy all the functions needed into
arch/x86/boot/cmdline.c and this way get rid of the crazy ifdeffery and
the subtle build issues.

I mean, we do this already in other places like perf tool is copying
stuff selectively from kernel proper and since compressed/ is a
completely separate stage, we probably should do that for the sake of
keeping our sanity. :)

Thx.

-- 
Regards/Gruss,
Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.


Re: [PATCH v12 1/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdline from KEXEC

2018-12-04 Thread Borislav Petkov
On Sat, Dec 01, 2018 at 02:05:39PM +0800, Chao Fan wrote:
> >I built your whole patchset and got the error.
> >The error depends on CONFIG_MODVERSIONS.
> >If CONFIG_MODVERSIONS=y, you will get the build error.
> 
> Hi Masa,
> 
> Thanks, after that, I got the error.
> About your solution, it can fix the error. But I am not sure whether
> it's good.

What does CONFIG_MODVERSIONS=y have to do with this? I don't see the
connection.

Also, your patch triggers another build error:

ld -m elf_x86_64 -z noreloc-overflow -pie --no-dynamic-linker   -T 
arch/x86/boot/compressed/vmlinux.lds arch/x86/boot/compressed/head_64.o 
arch/x86/boot/compressed/misc.o arch/x86/boot/compressed/string.o 
arch/x86/boot/compressed/cmdline.o arch/x86/boot/compressed/error.o 
arch/x86/boot/compressed/piggy.o arch/x86/boot/compressed/cpuflags.o 
arch/x86/boot/compressed/early_serial_console.o 
arch/x86/boot/compressed/mem_encrypt.o arch/x86/boot/compressed/pgtable_64.o 
arch/x86/boot/compressed/eboot.o arch/x86/boot/compressed/efi_stub_64.o 
drivers/firmware/efi/libstub/lib.a arch/x86/boot/compressed/efi_thunk_64.o -o 
arch/x86/boot/compressed/vmlinux
ld: arch/x86/boot/compressed/misc.o: in function `_parse_integer_fixup_radix':
misc.c:(.text+0x3057): undefined reference to `_ctype'
make[2]: *** [arch/x86/boot/compressed/Makefile:116: 
arch/x86/boot/compressed/vmlinux] Error 1
make[1]: *** [arch/x86/boot/Makefile:112: arch/x86/boot/compressed/vmlinux] 
Error 2
make: *** [arch/x86/Makefile:289: bzImage] Error 2
make: *** Waiting for unfinished jobs

due to misc.o not seeing _ctype.

Looks like this is going to become too hairy and perhaps it would
be easier and cleaner if you copy all the functions needed into
arch/x86/boot/cmdline.c and this way get rid of the crazy ifdeffery and
the subtle build issues.

I mean, we do this already in other places like perf tool is copying
stuff selectively from kernel proper and since compressed/ is a
completely separate stage, we probably should do that for the sake of
keeping our sanity. :)

Thx.

-- 
Regards/Gruss,
Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.


Re: [PATCH v12 1/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdline from KEXEC

2018-12-04 Thread Borislav Petkov
On Fri, Nov 30, 2018 at 10:29:14AM +0800, Chao Fan wrote:
> Oh, thanks, will change it
> char val[19];

And make that 19 a define.

-- 
Regards/Gruss,
Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.


Re: [PATCH v12 1/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdline from KEXEC

2018-12-04 Thread Borislav Petkov
On Fri, Nov 30, 2018 at 10:29:14AM +0800, Chao Fan wrote:
> Oh, thanks, will change it
> char val[19];

And make that 19 a define.

-- 
Regards/Gruss,
Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.


Re: [PATCH v12 1/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdline from KEXEC

2018-11-30 Thread Chao Fan
On Fri, Nov 30, 2018 at 12:35:16PM -0500, Masayoshi Mizuma wrote:
>On Fri, Nov 30, 2018 at 10:43:47AM +0800, Chao Fan wrote:
>...
>> >]$ make arch/x86/boot/compressed/misc.o
>> >  CALLscripts/checksyscalls.sh
>> >  DESCEND  objtool
>> >  CC  arch/x86/boot/compressed/misc.o
>> >ld: -r and -pie may not be used together
>> >make[1]: *** [scripts/Makefile.build:294: arch/x86/boot/compressed/misc.o] 
>> >Error 1
>> >make: *** [Makefile:1715: arch/x86/boot/compressed/misc.o] Error 2
>> >]$
>> 
>> Hi Masa,
>> 
>> So many thanks for your test.
>> 
>> Could you give me more details about this error? More error message.
>> Just on the first commit or the whole PATCHSET?
>> Cause I didn't get error both on this commit and on the whole PATCHSET.
>
>I built your whole patchset and got the error.
>The error depends on CONFIG_MODVERSIONS.
>If CONFIG_MODVERSIONS=y, you will get the build error.

Hi Masa,

Thanks, after that, I got the error.
About your solution, it can fix the error. But I am not sure whether
it's good.

Boris and Baoquan,
How do you think this issue.

Thanks,
Chao Fan

>
>Thanks,
>Masa
>
>




Re: [PATCH v12 1/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdline from KEXEC

2018-11-30 Thread Chao Fan
On Fri, Nov 30, 2018 at 12:35:16PM -0500, Masayoshi Mizuma wrote:
>On Fri, Nov 30, 2018 at 10:43:47AM +0800, Chao Fan wrote:
>...
>> >]$ make arch/x86/boot/compressed/misc.o
>> >  CALLscripts/checksyscalls.sh
>> >  DESCEND  objtool
>> >  CC  arch/x86/boot/compressed/misc.o
>> >ld: -r and -pie may not be used together
>> >make[1]: *** [scripts/Makefile.build:294: arch/x86/boot/compressed/misc.o] 
>> >Error 1
>> >make: *** [Makefile:1715: arch/x86/boot/compressed/misc.o] Error 2
>> >]$
>> 
>> Hi Masa,
>> 
>> So many thanks for your test.
>> 
>> Could you give me more details about this error? More error message.
>> Just on the first commit or the whole PATCHSET?
>> Cause I didn't get error both on this commit and on the whole PATCHSET.
>
>I built your whole patchset and got the error.
>The error depends on CONFIG_MODVERSIONS.
>If CONFIG_MODVERSIONS=y, you will get the build error.

Hi Masa,

Thanks, after that, I got the error.
About your solution, it can fix the error. But I am not sure whether
it's good.

Boris and Baoquan,
How do you think this issue.

Thanks,
Chao Fan

>
>Thanks,
>Masa
>
>




Re: [PATCH v12 1/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdline from KEXEC

2018-11-30 Thread Masayoshi Mizuma
On Fri, Nov 30, 2018 at 10:43:47AM +0800, Chao Fan wrote:
...
> >]$ make arch/x86/boot/compressed/misc.o
> >  CALLscripts/checksyscalls.sh
> >  DESCEND  objtool
> >  CC  arch/x86/boot/compressed/misc.o
> >ld: -r and -pie may not be used together
> >make[1]: *** [scripts/Makefile.build:294: arch/x86/boot/compressed/misc.o] 
> >Error 1
> >make: *** [Makefile:1715: arch/x86/boot/compressed/misc.o] Error 2
> >]$
> 
> Hi Masa,
> 
> So many thanks for your test.
> 
> Could you give me more details about this error? More error message.
> Just on the first commit or the whole PATCHSET?
> Cause I didn't get error both on this commit and on the whole PATCHSET.

I built your whole patchset and got the error.
The error depends on CONFIG_MODVERSIONS.
If CONFIG_MODVERSIONS=y, you will get the build error.

Thanks,
Masa


Re: [PATCH v12 1/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdline from KEXEC

2018-11-30 Thread Masayoshi Mizuma
On Fri, Nov 30, 2018 at 10:43:47AM +0800, Chao Fan wrote:
...
> >]$ make arch/x86/boot/compressed/misc.o
> >  CALLscripts/checksyscalls.sh
> >  DESCEND  objtool
> >  CC  arch/x86/boot/compressed/misc.o
> >ld: -r and -pie may not be used together
> >make[1]: *** [scripts/Makefile.build:294: arch/x86/boot/compressed/misc.o] 
> >Error 1
> >make: *** [Makefile:1715: arch/x86/boot/compressed/misc.o] Error 2
> >]$
> 
> Hi Masa,
> 
> So many thanks for your test.
> 
> Could you give me more details about this error? More error message.
> Just on the first commit or the whole PATCHSET?
> Cause I didn't get error both on this commit and on the whole PATCHSET.

I built your whole patchset and got the error.
The error depends on CONFIG_MODVERSIONS.
If CONFIG_MODVERSIONS=y, you will get the build error.

Thanks,
Masa


Re: [PATCH v12 1/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdline from KEXEC

2018-11-29 Thread Chao Fan
>> +
>> +/* acpitb.c */
>> +#define BOOT_STRING
>> +extern int kstrtoull(const char *s, unsigned int base, unsigned long long 
>> *res);
>> diff --git a/lib/kstrtox.c b/lib/kstrtox.c
>> index 1006bf70bf74..a0ac1b2257b8 100644
>> --- a/lib/kstrtox.c
>> +++ b/lib/kstrtox.c
>> @@ -126,6 +126,9 @@ int kstrtoull(const char *s, unsigned int base, unsigned 
>> long long *res)
>>  }
>>  EXPORT_SYMBOL(kstrtoull);
>>  
>> +/* Make compressed period code be able to use kstrtoull(). */
>> +#ifndef BOOT_STRING
>
>I got the following build error.
>
>]$ make arch/x86/boot/compressed/misc.o
>  CALLscripts/checksyscalls.sh
>  DESCEND  objtool
>  CC  arch/x86/boot/compressed/misc.o
>ld: -r and -pie may not be used together
>make[1]: *** [scripts/Makefile.build:294: arch/x86/boot/compressed/misc.o] 
>Error 1
>make: *** [Makefile:1715: arch/x86/boot/compressed/misc.o] Error 2
>]$

Hi Masa,

So many thanks for your test.

Could you give me more details about this error? More error message.
Just on the first commit or the whole PATCHSET?
Cause I didn't get error both on this commit and on the whole PATCHSET.

Thanks,
Chao Fan

>
>I think this error gets fixed by changing the BOOT_STRING ifndef
>order before the EXPORT_SYMBOL, like this:
>
>#ifndef BOOT_STRING
>EXPORT_SYMBOL(kstrtoull);
>
>I'm not sure this change is a good way...
>
>Thanks,
>Masa
>
>




Re: [PATCH v12 1/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdline from KEXEC

2018-11-29 Thread Chao Fan
>> +
>> +/* acpitb.c */
>> +#define BOOT_STRING
>> +extern int kstrtoull(const char *s, unsigned int base, unsigned long long 
>> *res);
>> diff --git a/lib/kstrtox.c b/lib/kstrtox.c
>> index 1006bf70bf74..a0ac1b2257b8 100644
>> --- a/lib/kstrtox.c
>> +++ b/lib/kstrtox.c
>> @@ -126,6 +126,9 @@ int kstrtoull(const char *s, unsigned int base, unsigned 
>> long long *res)
>>  }
>>  EXPORT_SYMBOL(kstrtoull);
>>  
>> +/* Make compressed period code be able to use kstrtoull(). */
>> +#ifndef BOOT_STRING
>
>I got the following build error.
>
>]$ make arch/x86/boot/compressed/misc.o
>  CALLscripts/checksyscalls.sh
>  DESCEND  objtool
>  CC  arch/x86/boot/compressed/misc.o
>ld: -r and -pie may not be used together
>make[1]: *** [scripts/Makefile.build:294: arch/x86/boot/compressed/misc.o] 
>Error 1
>make: *** [Makefile:1715: arch/x86/boot/compressed/misc.o] Error 2
>]$

Hi Masa,

So many thanks for your test.

Could you give me more details about this error? More error message.
Just on the first commit or the whole PATCHSET?
Cause I didn't get error both on this commit and on the whole PATCHSET.

Thanks,
Chao Fan

>
>I think this error gets fixed by changing the BOOT_STRING ifndef
>order before the EXPORT_SYMBOL, like this:
>
>#ifndef BOOT_STRING
>EXPORT_SYMBOL(kstrtoull);
>
>I'm not sure this change is a good way...
>
>Thanks,
>Masa
>
>




Re: [PATCH v12 1/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdline from KEXEC

2018-11-29 Thread Chao Fan
On Thu, Nov 29, 2018 at 11:20:13AM -0500, Masayoshi Mizuma wrote:
>On Thu, Nov 29, 2018 at 04:16:27PM +0800, Chao Fan wrote:
>> To fix the conflict between KASLR and memory-hotremove, memory
>> information in SRAT table is necessary.
>> 
>> ACPI SRAT (System/Static Resource Affinity Table) can show the details
>> about memory ranges, including ranges of memory provided by hot-added
>> memory devices. SRAT table must be introduced by RSDP pointer (Root
>> System Description Pointer). So RSDP should be found firstly.
>> 
>> When booting form KEXEC/EFI/BIOS, the methods to find RSDP pointer
>> are different. When booting from KEXEC, 'acpi_rsdp' may have been
>> added to cmdline, so parse the cmdline and find the RSDP pointer.
>> 
>> Signed-off-by: Chao Fan 
>> ---
>>  arch/x86/boot/compressed/acpitb.c | 33 +++
>>  arch/x86/boot/compressed/misc.c   |  5 +
>>  arch/x86/boot/compressed/misc.h   |  4 
>>  lib/kstrtox.c |  5 +
>>  4 files changed, 47 insertions(+)
>>  create mode 100644 arch/x86/boot/compressed/acpitb.c
>> 
>> diff --git a/arch/x86/boot/compressed/acpitb.c 
>> b/arch/x86/boot/compressed/acpitb.c
>> new file mode 100644
>> index ..614c45655cff
>> --- /dev/null
>> +++ b/arch/x86/boot/compressed/acpitb.c
>> @@ -0,0 +1,33 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +#define BOOT_CTYPE_H
>> +#include "misc.h"
>> +#include "error.h"
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#define STATIC
>> +#include 
>> +
>> +/* Store the immovable memory regions. */
>> +struct mem_vector immovable_mem[MAX_NUMNODES*2];
>> +#endif
>> +
>> +static acpi_physical_address get_acpi_rsdp(void)
>> +{
>> +#ifdef CONFIG_KEXEC
>> +unsigned long long res;
>> +int len = 0;
>
>> +char *val;
>> +
>> +val = malloc(19);
>> +len = cmdline_find_option("acpi_rsdp", val, 19);
>> +if (len > 0) {
>> +val[len] = 0;
>
>   val[len] = '\0';
>
>> +return (acpi_physical_address)kstrtoull(val, 16, );
>> +}
>
>I think free() is needed. Or why don't you use stack?

Oh, thanks, will change it
char val[19];

Thanks,
Chao Fan
>
>   char val[19];
>
>   len = cmdline_find_option("acpi_rsdp", val, sizeof(val));
>   if (len > 0) {
>   val[len] = '\0';
>   return (acpi_physical_address)kstrtoull(val, 16, );
>   }
>
>Thanks,
>Masa
>
>> +return 0;
>> +#endif
>> +}
>> diff --git a/arch/x86/boot/compressed/misc.c 
>> b/arch/x86/boot/compressed/misc.c
>> index 8dd1d5ccae58..e51713fe3add 100644
>> --- a/arch/x86/boot/compressed/misc.c
>> +++ b/arch/x86/boot/compressed/misc.c
>> @@ -12,6 +12,7 @@
>>   * High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
>>   */
>>  
>> +#define BOOT_CTYPE_H
>>  #include "misc.h"
>>  #include "error.h"
>>  #include "pgtable.h"
>> @@ -426,3 +427,7 @@ void fortify_panic(const char *name)
>>  {
>>  error("detected buffer overflow");
>>  }
>> +
>> +#ifdef BOOT_STRING
>> +#include "../../../../lib/kstrtox.c"
>> +#endif
>> diff --git a/arch/x86/boot/compressed/misc.h 
>> b/arch/x86/boot/compressed/misc.h
>> index a1d5918765f3..809c31effa4b 100644
>> --- a/arch/x86/boot/compressed/misc.h
>> +++ b/arch/x86/boot/compressed/misc.h
>> @@ -116,3 +116,7 @@ static inline void console_init(void)
>>  void set_sev_encryption_mask(void);
>>  
>>  #endif
>> +
>> +/* acpitb.c */
>> +#define BOOT_STRING
>> +extern int kstrtoull(const char *s, unsigned int base, unsigned long long 
>> *res);
>> diff --git a/lib/kstrtox.c b/lib/kstrtox.c
>> index 1006bf70bf74..a0ac1b2257b8 100644
>> --- a/lib/kstrtox.c
>> +++ b/lib/kstrtox.c
>> @@ -126,6 +126,9 @@ int kstrtoull(const char *s, unsigned int base, unsigned 
>> long long *res)
>>  }
>>  EXPORT_SYMBOL(kstrtoull);
>>  
>> +/* Make compressed period code be able to use kstrtoull(). */
>> +#ifndef BOOT_STRING
>> +
>>  /**
>>   * kstrtoll - convert a string to a long long
>>   * @s: The start of the string. The string must be null-terminated, and may 
>> also
>> @@ -408,3 +411,5 @@ kstrto_from_user(kstrtou16_from_user,kstrtou16,  
>> u16);
>>  kstrto_from_user(kstrtos16_from_user,   kstrtos16,  s16);
>>  kstrto_from_user(kstrtou8_from_user,kstrtou8,   u8);
>>  kstrto_from_user(kstrtos8_from_user,kstrtos8,   s8);
>> +
>> +#endif /* BOOT_STRING */
>> -- 
>> 2.19.1
>> 
>> 
>> 
>
>




Re: [PATCH v12 1/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdline from KEXEC

2018-11-29 Thread Chao Fan
On Thu, Nov 29, 2018 at 11:20:13AM -0500, Masayoshi Mizuma wrote:
>On Thu, Nov 29, 2018 at 04:16:27PM +0800, Chao Fan wrote:
>> To fix the conflict between KASLR and memory-hotremove, memory
>> information in SRAT table is necessary.
>> 
>> ACPI SRAT (System/Static Resource Affinity Table) can show the details
>> about memory ranges, including ranges of memory provided by hot-added
>> memory devices. SRAT table must be introduced by RSDP pointer (Root
>> System Description Pointer). So RSDP should be found firstly.
>> 
>> When booting form KEXEC/EFI/BIOS, the methods to find RSDP pointer
>> are different. When booting from KEXEC, 'acpi_rsdp' may have been
>> added to cmdline, so parse the cmdline and find the RSDP pointer.
>> 
>> Signed-off-by: Chao Fan 
>> ---
>>  arch/x86/boot/compressed/acpitb.c | 33 +++
>>  arch/x86/boot/compressed/misc.c   |  5 +
>>  arch/x86/boot/compressed/misc.h   |  4 
>>  lib/kstrtox.c |  5 +
>>  4 files changed, 47 insertions(+)
>>  create mode 100644 arch/x86/boot/compressed/acpitb.c
>> 
>> diff --git a/arch/x86/boot/compressed/acpitb.c 
>> b/arch/x86/boot/compressed/acpitb.c
>> new file mode 100644
>> index ..614c45655cff
>> --- /dev/null
>> +++ b/arch/x86/boot/compressed/acpitb.c
>> @@ -0,0 +1,33 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +#define BOOT_CTYPE_H
>> +#include "misc.h"
>> +#include "error.h"
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#define STATIC
>> +#include 
>> +
>> +/* Store the immovable memory regions. */
>> +struct mem_vector immovable_mem[MAX_NUMNODES*2];
>> +#endif
>> +
>> +static acpi_physical_address get_acpi_rsdp(void)
>> +{
>> +#ifdef CONFIG_KEXEC
>> +unsigned long long res;
>> +int len = 0;
>
>> +char *val;
>> +
>> +val = malloc(19);
>> +len = cmdline_find_option("acpi_rsdp", val, 19);
>> +if (len > 0) {
>> +val[len] = 0;
>
>   val[len] = '\0';
>
>> +return (acpi_physical_address)kstrtoull(val, 16, );
>> +}
>
>I think free() is needed. Or why don't you use stack?

Oh, thanks, will change it
char val[19];

Thanks,
Chao Fan
>
>   char val[19];
>
>   len = cmdline_find_option("acpi_rsdp", val, sizeof(val));
>   if (len > 0) {
>   val[len] = '\0';
>   return (acpi_physical_address)kstrtoull(val, 16, );
>   }
>
>Thanks,
>Masa
>
>> +return 0;
>> +#endif
>> +}
>> diff --git a/arch/x86/boot/compressed/misc.c 
>> b/arch/x86/boot/compressed/misc.c
>> index 8dd1d5ccae58..e51713fe3add 100644
>> --- a/arch/x86/boot/compressed/misc.c
>> +++ b/arch/x86/boot/compressed/misc.c
>> @@ -12,6 +12,7 @@
>>   * High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
>>   */
>>  
>> +#define BOOT_CTYPE_H
>>  #include "misc.h"
>>  #include "error.h"
>>  #include "pgtable.h"
>> @@ -426,3 +427,7 @@ void fortify_panic(const char *name)
>>  {
>>  error("detected buffer overflow");
>>  }
>> +
>> +#ifdef BOOT_STRING
>> +#include "../../../../lib/kstrtox.c"
>> +#endif
>> diff --git a/arch/x86/boot/compressed/misc.h 
>> b/arch/x86/boot/compressed/misc.h
>> index a1d5918765f3..809c31effa4b 100644
>> --- a/arch/x86/boot/compressed/misc.h
>> +++ b/arch/x86/boot/compressed/misc.h
>> @@ -116,3 +116,7 @@ static inline void console_init(void)
>>  void set_sev_encryption_mask(void);
>>  
>>  #endif
>> +
>> +/* acpitb.c */
>> +#define BOOT_STRING
>> +extern int kstrtoull(const char *s, unsigned int base, unsigned long long 
>> *res);
>> diff --git a/lib/kstrtox.c b/lib/kstrtox.c
>> index 1006bf70bf74..a0ac1b2257b8 100644
>> --- a/lib/kstrtox.c
>> +++ b/lib/kstrtox.c
>> @@ -126,6 +126,9 @@ int kstrtoull(const char *s, unsigned int base, unsigned 
>> long long *res)
>>  }
>>  EXPORT_SYMBOL(kstrtoull);
>>  
>> +/* Make compressed period code be able to use kstrtoull(). */
>> +#ifndef BOOT_STRING
>> +
>>  /**
>>   * kstrtoll - convert a string to a long long
>>   * @s: The start of the string. The string must be null-terminated, and may 
>> also
>> @@ -408,3 +411,5 @@ kstrto_from_user(kstrtou16_from_user,kstrtou16,  
>> u16);
>>  kstrto_from_user(kstrtos16_from_user,   kstrtos16,  s16);
>>  kstrto_from_user(kstrtou8_from_user,kstrtou8,   u8);
>>  kstrto_from_user(kstrtos8_from_user,kstrtos8,   s8);
>> +
>> +#endif /* BOOT_STRING */
>> -- 
>> 2.19.1
>> 
>> 
>> 
>
>




Re: [PATCH v12 1/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdline from KEXEC

2018-11-29 Thread Masayoshi Mizuma
On Thu, Nov 29, 2018 at 04:16:27PM +0800, Chao Fan wrote:
> To fix the conflict between KASLR and memory-hotremove, memory
> information in SRAT table is necessary.
> 
> ACPI SRAT (System/Static Resource Affinity Table) can show the details
> about memory ranges, including ranges of memory provided by hot-added
> memory devices. SRAT table must be introduced by RSDP pointer (Root
> System Description Pointer). So RSDP should be found firstly.
> 
> When booting form KEXEC/EFI/BIOS, the methods to find RSDP pointer
> are different. When booting from KEXEC, 'acpi_rsdp' may have been
> added to cmdline, so parse the cmdline and find the RSDP pointer.
> 
> Signed-off-by: Chao Fan 
> ---
>  arch/x86/boot/compressed/acpitb.c | 33 +++
>  arch/x86/boot/compressed/misc.c   |  5 +
>  arch/x86/boot/compressed/misc.h   |  4 
>  lib/kstrtox.c |  5 +
>  4 files changed, 47 insertions(+)
>  create mode 100644 arch/x86/boot/compressed/acpitb.c
> 
> diff --git a/arch/x86/boot/compressed/acpitb.c 
> b/arch/x86/boot/compressed/acpitb.c
> new file mode 100644
> index ..614c45655cff
> --- /dev/null
> +++ b/arch/x86/boot/compressed/acpitb.c
> @@ -0,0 +1,33 @@
> +// SPDX-License-Identifier: GPL-2.0
> +#define BOOT_CTYPE_H
> +#include "misc.h"
> +#include "error.h"
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define STATIC
> +#include 
> +
> +/* Store the immovable memory regions. */
> +struct mem_vector immovable_mem[MAX_NUMNODES*2];
> +#endif
> +
> +static acpi_physical_address get_acpi_rsdp(void)
> +{
> +#ifdef CONFIG_KEXEC
> + unsigned long long res;
> + int len = 0;
> + char *val;
> +
> + val = malloc(19);
> + len = cmdline_find_option("acpi_rsdp", val, 19);
> + if (len > 0) {
> + val[len] = 0;
> + return (acpi_physical_address)kstrtoull(val, 16, );
> + }
> + return 0;
> +#endif
> +}
> diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
> index 8dd1d5ccae58..e51713fe3add 100644
> --- a/arch/x86/boot/compressed/misc.c
> +++ b/arch/x86/boot/compressed/misc.c
> @@ -12,6 +12,7 @@
>   * High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
>   */
>  
> +#define BOOT_CTYPE_H
>  #include "misc.h"
>  #include "error.h"
>  #include "pgtable.h"
> @@ -426,3 +427,7 @@ void fortify_panic(const char *name)
>  {
>   error("detected buffer overflow");
>  }
> +
> +#ifdef BOOT_STRING
> +#include "../../../../lib/kstrtox.c"
> +#endif
> diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h
> index a1d5918765f3..809c31effa4b 100644
> --- a/arch/x86/boot/compressed/misc.h
> +++ b/arch/x86/boot/compressed/misc.h
> @@ -116,3 +116,7 @@ static inline void console_init(void)
>  void set_sev_encryption_mask(void);
>  
>  #endif
> +
> +/* acpitb.c */
> +#define BOOT_STRING
> +extern int kstrtoull(const char *s, unsigned int base, unsigned long long 
> *res);
> diff --git a/lib/kstrtox.c b/lib/kstrtox.c
> index 1006bf70bf74..a0ac1b2257b8 100644
> --- a/lib/kstrtox.c
> +++ b/lib/kstrtox.c
> @@ -126,6 +126,9 @@ int kstrtoull(const char *s, unsigned int base, unsigned 
> long long *res)
>  }
>  EXPORT_SYMBOL(kstrtoull);
>  
> +/* Make compressed period code be able to use kstrtoull(). */
> +#ifndef BOOT_STRING

I got the following build error.

]$ make arch/x86/boot/compressed/misc.o
  CALLscripts/checksyscalls.sh
  DESCEND  objtool
  CC  arch/x86/boot/compressed/misc.o
ld: -r and -pie may not be used together
make[1]: *** [scripts/Makefile.build:294: arch/x86/boot/compressed/misc.o] 
Error 1
make: *** [Makefile:1715: arch/x86/boot/compressed/misc.o] Error 2
]$

I think this error gets fixed by changing the BOOT_STRING ifndef
order before the EXPORT_SYMBOL, like this:

#ifndef BOOT_STRING
EXPORT_SYMBOL(kstrtoull);

I'm not sure this change is a good way...

Thanks,
Masa


Re: [PATCH v12 1/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdline from KEXEC

2018-11-29 Thread Masayoshi Mizuma
On Thu, Nov 29, 2018 at 04:16:27PM +0800, Chao Fan wrote:
> To fix the conflict between KASLR and memory-hotremove, memory
> information in SRAT table is necessary.
> 
> ACPI SRAT (System/Static Resource Affinity Table) can show the details
> about memory ranges, including ranges of memory provided by hot-added
> memory devices. SRAT table must be introduced by RSDP pointer (Root
> System Description Pointer). So RSDP should be found firstly.
> 
> When booting form KEXEC/EFI/BIOS, the methods to find RSDP pointer
> are different. When booting from KEXEC, 'acpi_rsdp' may have been
> added to cmdline, so parse the cmdline and find the RSDP pointer.
> 
> Signed-off-by: Chao Fan 
> ---
>  arch/x86/boot/compressed/acpitb.c | 33 +++
>  arch/x86/boot/compressed/misc.c   |  5 +
>  arch/x86/boot/compressed/misc.h   |  4 
>  lib/kstrtox.c |  5 +
>  4 files changed, 47 insertions(+)
>  create mode 100644 arch/x86/boot/compressed/acpitb.c
> 
> diff --git a/arch/x86/boot/compressed/acpitb.c 
> b/arch/x86/boot/compressed/acpitb.c
> new file mode 100644
> index ..614c45655cff
> --- /dev/null
> +++ b/arch/x86/boot/compressed/acpitb.c
> @@ -0,0 +1,33 @@
> +// SPDX-License-Identifier: GPL-2.0
> +#define BOOT_CTYPE_H
> +#include "misc.h"
> +#include "error.h"
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define STATIC
> +#include 
> +
> +/* Store the immovable memory regions. */
> +struct mem_vector immovable_mem[MAX_NUMNODES*2];
> +#endif
> +
> +static acpi_physical_address get_acpi_rsdp(void)
> +{
> +#ifdef CONFIG_KEXEC
> + unsigned long long res;
> + int len = 0;
> + char *val;
> +
> + val = malloc(19);
> + len = cmdline_find_option("acpi_rsdp", val, 19);
> + if (len > 0) {
> + val[len] = 0;
> + return (acpi_physical_address)kstrtoull(val, 16, );
> + }
> + return 0;
> +#endif
> +}
> diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
> index 8dd1d5ccae58..e51713fe3add 100644
> --- a/arch/x86/boot/compressed/misc.c
> +++ b/arch/x86/boot/compressed/misc.c
> @@ -12,6 +12,7 @@
>   * High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
>   */
>  
> +#define BOOT_CTYPE_H
>  #include "misc.h"
>  #include "error.h"
>  #include "pgtable.h"
> @@ -426,3 +427,7 @@ void fortify_panic(const char *name)
>  {
>   error("detected buffer overflow");
>  }
> +
> +#ifdef BOOT_STRING
> +#include "../../../../lib/kstrtox.c"
> +#endif
> diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h
> index a1d5918765f3..809c31effa4b 100644
> --- a/arch/x86/boot/compressed/misc.h
> +++ b/arch/x86/boot/compressed/misc.h
> @@ -116,3 +116,7 @@ static inline void console_init(void)
>  void set_sev_encryption_mask(void);
>  
>  #endif
> +
> +/* acpitb.c */
> +#define BOOT_STRING
> +extern int kstrtoull(const char *s, unsigned int base, unsigned long long 
> *res);
> diff --git a/lib/kstrtox.c b/lib/kstrtox.c
> index 1006bf70bf74..a0ac1b2257b8 100644
> --- a/lib/kstrtox.c
> +++ b/lib/kstrtox.c
> @@ -126,6 +126,9 @@ int kstrtoull(const char *s, unsigned int base, unsigned 
> long long *res)
>  }
>  EXPORT_SYMBOL(kstrtoull);
>  
> +/* Make compressed period code be able to use kstrtoull(). */
> +#ifndef BOOT_STRING

I got the following build error.

]$ make arch/x86/boot/compressed/misc.o
  CALLscripts/checksyscalls.sh
  DESCEND  objtool
  CC  arch/x86/boot/compressed/misc.o
ld: -r and -pie may not be used together
make[1]: *** [scripts/Makefile.build:294: arch/x86/boot/compressed/misc.o] 
Error 1
make: *** [Makefile:1715: arch/x86/boot/compressed/misc.o] Error 2
]$

I think this error gets fixed by changing the BOOT_STRING ifndef
order before the EXPORT_SYMBOL, like this:

#ifndef BOOT_STRING
EXPORT_SYMBOL(kstrtoull);

I'm not sure this change is a good way...

Thanks,
Masa


Re: [PATCH v12 1/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdline from KEXEC

2018-11-29 Thread Masayoshi Mizuma
On Thu, Nov 29, 2018 at 04:16:27PM +0800, Chao Fan wrote:
> To fix the conflict between KASLR and memory-hotremove, memory
> information in SRAT table is necessary.
> 
> ACPI SRAT (System/Static Resource Affinity Table) can show the details
> about memory ranges, including ranges of memory provided by hot-added
> memory devices. SRAT table must be introduced by RSDP pointer (Root
> System Description Pointer). So RSDP should be found firstly.
> 
> When booting form KEXEC/EFI/BIOS, the methods to find RSDP pointer
> are different. When booting from KEXEC, 'acpi_rsdp' may have been
> added to cmdline, so parse the cmdline and find the RSDP pointer.
> 
> Signed-off-by: Chao Fan 
> ---
>  arch/x86/boot/compressed/acpitb.c | 33 +++
>  arch/x86/boot/compressed/misc.c   |  5 +
>  arch/x86/boot/compressed/misc.h   |  4 
>  lib/kstrtox.c |  5 +
>  4 files changed, 47 insertions(+)
>  create mode 100644 arch/x86/boot/compressed/acpitb.c
> 
> diff --git a/arch/x86/boot/compressed/acpitb.c 
> b/arch/x86/boot/compressed/acpitb.c
> new file mode 100644
> index ..614c45655cff
> --- /dev/null
> +++ b/arch/x86/boot/compressed/acpitb.c
> @@ -0,0 +1,33 @@
> +// SPDX-License-Identifier: GPL-2.0
> +#define BOOT_CTYPE_H
> +#include "misc.h"
> +#include "error.h"
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define STATIC
> +#include 
> +
> +/* Store the immovable memory regions. */
> +struct mem_vector immovable_mem[MAX_NUMNODES*2];

> +#endif

Remove this #endif...

Thanks,
Masa

> +
> +static acpi_physical_address get_acpi_rsdp(void)
> +{
> +#ifdef CONFIG_KEXEC
> + unsigned long long res;
> + int len = 0;
> + char *val;
> +
> + val = malloc(19);
> + len = cmdline_find_option("acpi_rsdp", val, 19);
> + if (len > 0) {
> + val[len] = 0;
> + return (acpi_physical_address)kstrtoull(val, 16, );
> + }
> + return 0;
> +#endif
> +}
> diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
> index 8dd1d5ccae58..e51713fe3add 100644
> --- a/arch/x86/boot/compressed/misc.c
> +++ b/arch/x86/boot/compressed/misc.c
> @@ -12,6 +12,7 @@
>   * High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
>   */
>  
> +#define BOOT_CTYPE_H
>  #include "misc.h"
>  #include "error.h"
>  #include "pgtable.h"
> @@ -426,3 +427,7 @@ void fortify_panic(const char *name)
>  {
>   error("detected buffer overflow");
>  }
> +
> +#ifdef BOOT_STRING
> +#include "../../../../lib/kstrtox.c"
> +#endif
> diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h
> index a1d5918765f3..809c31effa4b 100644
> --- a/arch/x86/boot/compressed/misc.h
> +++ b/arch/x86/boot/compressed/misc.h
> @@ -116,3 +116,7 @@ static inline void console_init(void)
>  void set_sev_encryption_mask(void);
>  
>  #endif
> +
> +/* acpitb.c */
> +#define BOOT_STRING
> +extern int kstrtoull(const char *s, unsigned int base, unsigned long long 
> *res);
> diff --git a/lib/kstrtox.c b/lib/kstrtox.c
> index 1006bf70bf74..a0ac1b2257b8 100644
> --- a/lib/kstrtox.c
> +++ b/lib/kstrtox.c
> @@ -126,6 +126,9 @@ int kstrtoull(const char *s, unsigned int base, unsigned 
> long long *res)
>  }
>  EXPORT_SYMBOL(kstrtoull);
>  
> +/* Make compressed period code be able to use kstrtoull(). */
> +#ifndef BOOT_STRING
> +
>  /**
>   * kstrtoll - convert a string to a long long
>   * @s: The start of the string. The string must be null-terminated, and may 
> also
> @@ -408,3 +411,5 @@ kstrto_from_user(kstrtou16_from_user, kstrtou16,  
> u16);
>  kstrto_from_user(kstrtos16_from_user,kstrtos16,  s16);
>  kstrto_from_user(kstrtou8_from_user, kstrtou8,   u8);
>  kstrto_from_user(kstrtos8_from_user, kstrtos8,   s8);
> +
> +#endif /* BOOT_STRING */
> -- 
> 2.19.1
> 
> 
> 


Re: [PATCH v12 1/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdline from KEXEC

2018-11-29 Thread Masayoshi Mizuma
On Thu, Nov 29, 2018 at 04:16:27PM +0800, Chao Fan wrote:
> To fix the conflict between KASLR and memory-hotremove, memory
> information in SRAT table is necessary.
> 
> ACPI SRAT (System/Static Resource Affinity Table) can show the details
> about memory ranges, including ranges of memory provided by hot-added
> memory devices. SRAT table must be introduced by RSDP pointer (Root
> System Description Pointer). So RSDP should be found firstly.
> 
> When booting form KEXEC/EFI/BIOS, the methods to find RSDP pointer
> are different. When booting from KEXEC, 'acpi_rsdp' may have been
> added to cmdline, so parse the cmdline and find the RSDP pointer.
> 
> Signed-off-by: Chao Fan 
> ---
>  arch/x86/boot/compressed/acpitb.c | 33 +++
>  arch/x86/boot/compressed/misc.c   |  5 +
>  arch/x86/boot/compressed/misc.h   |  4 
>  lib/kstrtox.c |  5 +
>  4 files changed, 47 insertions(+)
>  create mode 100644 arch/x86/boot/compressed/acpitb.c
> 
> diff --git a/arch/x86/boot/compressed/acpitb.c 
> b/arch/x86/boot/compressed/acpitb.c
> new file mode 100644
> index ..614c45655cff
> --- /dev/null
> +++ b/arch/x86/boot/compressed/acpitb.c
> @@ -0,0 +1,33 @@
> +// SPDX-License-Identifier: GPL-2.0
> +#define BOOT_CTYPE_H
> +#include "misc.h"
> +#include "error.h"
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define STATIC
> +#include 
> +
> +/* Store the immovable memory regions. */
> +struct mem_vector immovable_mem[MAX_NUMNODES*2];

> +#endif

Remove this #endif...

Thanks,
Masa

> +
> +static acpi_physical_address get_acpi_rsdp(void)
> +{
> +#ifdef CONFIG_KEXEC
> + unsigned long long res;
> + int len = 0;
> + char *val;
> +
> + val = malloc(19);
> + len = cmdline_find_option("acpi_rsdp", val, 19);
> + if (len > 0) {
> + val[len] = 0;
> + return (acpi_physical_address)kstrtoull(val, 16, );
> + }
> + return 0;
> +#endif
> +}
> diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
> index 8dd1d5ccae58..e51713fe3add 100644
> --- a/arch/x86/boot/compressed/misc.c
> +++ b/arch/x86/boot/compressed/misc.c
> @@ -12,6 +12,7 @@
>   * High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
>   */
>  
> +#define BOOT_CTYPE_H
>  #include "misc.h"
>  #include "error.h"
>  #include "pgtable.h"
> @@ -426,3 +427,7 @@ void fortify_panic(const char *name)
>  {
>   error("detected buffer overflow");
>  }
> +
> +#ifdef BOOT_STRING
> +#include "../../../../lib/kstrtox.c"
> +#endif
> diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h
> index a1d5918765f3..809c31effa4b 100644
> --- a/arch/x86/boot/compressed/misc.h
> +++ b/arch/x86/boot/compressed/misc.h
> @@ -116,3 +116,7 @@ static inline void console_init(void)
>  void set_sev_encryption_mask(void);
>  
>  #endif
> +
> +/* acpitb.c */
> +#define BOOT_STRING
> +extern int kstrtoull(const char *s, unsigned int base, unsigned long long 
> *res);
> diff --git a/lib/kstrtox.c b/lib/kstrtox.c
> index 1006bf70bf74..a0ac1b2257b8 100644
> --- a/lib/kstrtox.c
> +++ b/lib/kstrtox.c
> @@ -126,6 +126,9 @@ int kstrtoull(const char *s, unsigned int base, unsigned 
> long long *res)
>  }
>  EXPORT_SYMBOL(kstrtoull);
>  
> +/* Make compressed period code be able to use kstrtoull(). */
> +#ifndef BOOT_STRING
> +
>  /**
>   * kstrtoll - convert a string to a long long
>   * @s: The start of the string. The string must be null-terminated, and may 
> also
> @@ -408,3 +411,5 @@ kstrto_from_user(kstrtou16_from_user, kstrtou16,  
> u16);
>  kstrto_from_user(kstrtos16_from_user,kstrtos16,  s16);
>  kstrto_from_user(kstrtou8_from_user, kstrtou8,   u8);
>  kstrto_from_user(kstrtos8_from_user, kstrtos8,   s8);
> +
> +#endif /* BOOT_STRING */
> -- 
> 2.19.1
> 
> 
> 


Re: [PATCH v12 1/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdline from KEXEC

2018-11-29 Thread Masayoshi Mizuma
On Thu, Nov 29, 2018 at 04:16:27PM +0800, Chao Fan wrote:
> To fix the conflict between KASLR and memory-hotremove, memory
> information in SRAT table is necessary.
> 
> ACPI SRAT (System/Static Resource Affinity Table) can show the details
> about memory ranges, including ranges of memory provided by hot-added
> memory devices. SRAT table must be introduced by RSDP pointer (Root
> System Description Pointer). So RSDP should be found firstly.
> 
> When booting form KEXEC/EFI/BIOS, the methods to find RSDP pointer
> are different. When booting from KEXEC, 'acpi_rsdp' may have been
> added to cmdline, so parse the cmdline and find the RSDP pointer.
> 
> Signed-off-by: Chao Fan 
> ---
>  arch/x86/boot/compressed/acpitb.c | 33 +++
>  arch/x86/boot/compressed/misc.c   |  5 +
>  arch/x86/boot/compressed/misc.h   |  4 
>  lib/kstrtox.c |  5 +
>  4 files changed, 47 insertions(+)
>  create mode 100644 arch/x86/boot/compressed/acpitb.c
> 
> diff --git a/arch/x86/boot/compressed/acpitb.c 
> b/arch/x86/boot/compressed/acpitb.c
> new file mode 100644
> index ..614c45655cff
> --- /dev/null
> +++ b/arch/x86/boot/compressed/acpitb.c
> @@ -0,0 +1,33 @@
> +// SPDX-License-Identifier: GPL-2.0
> +#define BOOT_CTYPE_H
> +#include "misc.h"
> +#include "error.h"
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define STATIC
> +#include 
> +
> +/* Store the immovable memory regions. */
> +struct mem_vector immovable_mem[MAX_NUMNODES*2];
> +#endif
> +
> +static acpi_physical_address get_acpi_rsdp(void)
> +{
> +#ifdef CONFIG_KEXEC
> + unsigned long long res;
> + int len = 0;

> + char *val;
> +
> + val = malloc(19);
> + len = cmdline_find_option("acpi_rsdp", val, 19);
> + if (len > 0) {
> + val[len] = 0;

val[len] = '\0';

> + return (acpi_physical_address)kstrtoull(val, 16, );
> + }

I think free() is needed. Or why don't you use stack?

char val[19];

len = cmdline_find_option("acpi_rsdp", val, sizeof(val));
if (len > 0) {
val[len] = '\0';
return (acpi_physical_address)kstrtoull(val, 16, );
}

Thanks,
Masa

> + return 0;
> +#endif
> +}
> diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
> index 8dd1d5ccae58..e51713fe3add 100644
> --- a/arch/x86/boot/compressed/misc.c
> +++ b/arch/x86/boot/compressed/misc.c
> @@ -12,6 +12,7 @@
>   * High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
>   */
>  
> +#define BOOT_CTYPE_H
>  #include "misc.h"
>  #include "error.h"
>  #include "pgtable.h"
> @@ -426,3 +427,7 @@ void fortify_panic(const char *name)
>  {
>   error("detected buffer overflow");
>  }
> +
> +#ifdef BOOT_STRING
> +#include "../../../../lib/kstrtox.c"
> +#endif
> diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h
> index a1d5918765f3..809c31effa4b 100644
> --- a/arch/x86/boot/compressed/misc.h
> +++ b/arch/x86/boot/compressed/misc.h
> @@ -116,3 +116,7 @@ static inline void console_init(void)
>  void set_sev_encryption_mask(void);
>  
>  #endif
> +
> +/* acpitb.c */
> +#define BOOT_STRING
> +extern int kstrtoull(const char *s, unsigned int base, unsigned long long 
> *res);
> diff --git a/lib/kstrtox.c b/lib/kstrtox.c
> index 1006bf70bf74..a0ac1b2257b8 100644
> --- a/lib/kstrtox.c
> +++ b/lib/kstrtox.c
> @@ -126,6 +126,9 @@ int kstrtoull(const char *s, unsigned int base, unsigned 
> long long *res)
>  }
>  EXPORT_SYMBOL(kstrtoull);
>  
> +/* Make compressed period code be able to use kstrtoull(). */
> +#ifndef BOOT_STRING
> +
>  /**
>   * kstrtoll - convert a string to a long long
>   * @s: The start of the string. The string must be null-terminated, and may 
> also
> @@ -408,3 +411,5 @@ kstrto_from_user(kstrtou16_from_user, kstrtou16,  
> u16);
>  kstrto_from_user(kstrtos16_from_user,kstrtos16,  s16);
>  kstrto_from_user(kstrtou8_from_user, kstrtou8,   u8);
>  kstrto_from_user(kstrtos8_from_user, kstrtos8,   s8);
> +
> +#endif /* BOOT_STRING */
> -- 
> 2.19.1
> 
> 
> 


Re: [PATCH v12 1/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdline from KEXEC

2018-11-29 Thread Masayoshi Mizuma
On Thu, Nov 29, 2018 at 04:16:27PM +0800, Chao Fan wrote:
> To fix the conflict between KASLR and memory-hotremove, memory
> information in SRAT table is necessary.
> 
> ACPI SRAT (System/Static Resource Affinity Table) can show the details
> about memory ranges, including ranges of memory provided by hot-added
> memory devices. SRAT table must be introduced by RSDP pointer (Root
> System Description Pointer). So RSDP should be found firstly.
> 
> When booting form KEXEC/EFI/BIOS, the methods to find RSDP pointer
> are different. When booting from KEXEC, 'acpi_rsdp' may have been
> added to cmdline, so parse the cmdline and find the RSDP pointer.
> 
> Signed-off-by: Chao Fan 
> ---
>  arch/x86/boot/compressed/acpitb.c | 33 +++
>  arch/x86/boot/compressed/misc.c   |  5 +
>  arch/x86/boot/compressed/misc.h   |  4 
>  lib/kstrtox.c |  5 +
>  4 files changed, 47 insertions(+)
>  create mode 100644 arch/x86/boot/compressed/acpitb.c
> 
> diff --git a/arch/x86/boot/compressed/acpitb.c 
> b/arch/x86/boot/compressed/acpitb.c
> new file mode 100644
> index ..614c45655cff
> --- /dev/null
> +++ b/arch/x86/boot/compressed/acpitb.c
> @@ -0,0 +1,33 @@
> +// SPDX-License-Identifier: GPL-2.0
> +#define BOOT_CTYPE_H
> +#include "misc.h"
> +#include "error.h"
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define STATIC
> +#include 
> +
> +/* Store the immovable memory regions. */
> +struct mem_vector immovable_mem[MAX_NUMNODES*2];
> +#endif
> +
> +static acpi_physical_address get_acpi_rsdp(void)
> +{
> +#ifdef CONFIG_KEXEC
> + unsigned long long res;
> + int len = 0;

> + char *val;
> +
> + val = malloc(19);
> + len = cmdline_find_option("acpi_rsdp", val, 19);
> + if (len > 0) {
> + val[len] = 0;

val[len] = '\0';

> + return (acpi_physical_address)kstrtoull(val, 16, );
> + }

I think free() is needed. Or why don't you use stack?

char val[19];

len = cmdline_find_option("acpi_rsdp", val, sizeof(val));
if (len > 0) {
val[len] = '\0';
return (acpi_physical_address)kstrtoull(val, 16, );
}

Thanks,
Masa

> + return 0;
> +#endif
> +}
> diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
> index 8dd1d5ccae58..e51713fe3add 100644
> --- a/arch/x86/boot/compressed/misc.c
> +++ b/arch/x86/boot/compressed/misc.c
> @@ -12,6 +12,7 @@
>   * High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
>   */
>  
> +#define BOOT_CTYPE_H
>  #include "misc.h"
>  #include "error.h"
>  #include "pgtable.h"
> @@ -426,3 +427,7 @@ void fortify_panic(const char *name)
>  {
>   error("detected buffer overflow");
>  }
> +
> +#ifdef BOOT_STRING
> +#include "../../../../lib/kstrtox.c"
> +#endif
> diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h
> index a1d5918765f3..809c31effa4b 100644
> --- a/arch/x86/boot/compressed/misc.h
> +++ b/arch/x86/boot/compressed/misc.h
> @@ -116,3 +116,7 @@ static inline void console_init(void)
>  void set_sev_encryption_mask(void);
>  
>  #endif
> +
> +/* acpitb.c */
> +#define BOOT_STRING
> +extern int kstrtoull(const char *s, unsigned int base, unsigned long long 
> *res);
> diff --git a/lib/kstrtox.c b/lib/kstrtox.c
> index 1006bf70bf74..a0ac1b2257b8 100644
> --- a/lib/kstrtox.c
> +++ b/lib/kstrtox.c
> @@ -126,6 +126,9 @@ int kstrtoull(const char *s, unsigned int base, unsigned 
> long long *res)
>  }
>  EXPORT_SYMBOL(kstrtoull);
>  
> +/* Make compressed period code be able to use kstrtoull(). */
> +#ifndef BOOT_STRING
> +
>  /**
>   * kstrtoll - convert a string to a long long
>   * @s: The start of the string. The string must be null-terminated, and may 
> also
> @@ -408,3 +411,5 @@ kstrto_from_user(kstrtou16_from_user, kstrtou16,  
> u16);
>  kstrto_from_user(kstrtos16_from_user,kstrtos16,  s16);
>  kstrto_from_user(kstrtou8_from_user, kstrtou8,   u8);
>  kstrto_from_user(kstrtos8_from_user, kstrtos8,   s8);
> +
> +#endif /* BOOT_STRING */
> -- 
> 2.19.1
> 
> 
>