diff mbox series

[v9,5/8] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdlien from kexec

Message ID 20181017102012.872-6-fanc.fnst@cn.fujitsu.com (mailing list archive)
State Not Applicable, archived
Headers show
Series x86/boot/KASLR: Parse ACPI table and limit kaslr in immovable memory | expand

Commit Message

Chao Fan Oct. 17, 2018, 10:20 a.m. UTC
If KEXEC write the RSDP pointer to cmdline, parse the cmdline
and use it.
Imitate from early_param of "acpi_rsdp".

Signed-off-by: Chao Fan <fanc.fnst@cn.fujitsu.com>
---
 arch/x86/boot/compressed/acpitb.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

Comments

Baoquan He Oct. 21, 2018, 2:26 a.m. UTC | #1
On 10/17/18 at 06:20pm, Chao Fan wrote:
> If KEXEC write the RSDP pointer to cmdline, parse the cmdline
> and use it.
> Imitate from early_param of "acpi_rsdp".
> 
> Signed-off-by: Chao Fan <fanc.fnst@cn.fujitsu.com>
> ---
>  arch/x86/boot/compressed/acpitb.c | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
> 
> diff --git a/arch/x86/boot/compressed/acpitb.c b/arch/x86/boot/compressed/acpitb.c
> index 50fa65cf824d..37b1f4407be8 100644
> --- a/arch/x86/boot/compressed/acpitb.c
> +++ b/arch/x86/boot/compressed/acpitb.c
> @@ -8,6 +8,9 @@
>  #include <linux/numa.h>
>  #include <linux/acpi.h>
>  
> +#define STATIC
> +#include <linux/decompress/mm.h>
> +
>  /* Search EFI table for RSDP table. */
>  static void efi_get_rsdp_addr(acpi_physical_address *rsdp_addr)
>  {
> @@ -200,3 +203,23 @@ static void bios_get_rsdp_addr(acpi_physical_address *rsdp_addr)
>  		*rsdp_addr = (acpi_physical_address)address;
>  	}
>  }
> +
> +static void get_acpi_rsdp(acpi_physical_address *rsdp_addr)
> +{
> +#ifdef CONFIG_KEXEC
> +	unsigned long long res;
> +	int len = 0;
> +	char *val;
> +
> +	val = malloc(20);

Why is the length 20? Defined a macro?

> +	len = cmdline_find_option("acpi_rsdp", val, 20);
> +
> +	if (len == -1)
> +		return;
> +
> +	if (len > 0) {
> +		val[len] = 0;
> +		*rsdp_addr = (acpi_physical_address)kstrtoull(val, 0, &res);
> +	}
> +#endif
> +}
> -- 
> 2.17.2
> 
> 
>
Chao Fan Oct. 22, 2018, 5:30 a.m. UTC | #2
On Sun, Oct 21, 2018 at 10:26:50AM +0800, Baoquan He wrote:
>On 10/17/18 at 06:20pm, Chao Fan wrote:
>> If KEXEC write the RSDP pointer to cmdline, parse the cmdline
>> and use it.
>> Imitate from early_param of "acpi_rsdp".
>> 
>> Signed-off-by: Chao Fan <fanc.fnst@cn.fujitsu.com>
>> ---
>>  arch/x86/boot/compressed/acpitb.c | 23 +++++++++++++++++++++++
>>  1 file changed, 23 insertions(+)
>> 
>> diff --git a/arch/x86/boot/compressed/acpitb.c b/arch/x86/boot/compressed/acpitb.c
>> index 50fa65cf824d..37b1f4407be8 100644
>> --- a/arch/x86/boot/compressed/acpitb.c
>> +++ b/arch/x86/boot/compressed/acpitb.c
>> @@ -8,6 +8,9 @@
>>  #include <linux/numa.h>
>>  #include <linux/acpi.h>
>>  
>> +#define STATIC
>> +#include <linux/decompress/mm.h>
>> +
>>  /* Search EFI table for RSDP table. */
>>  static void efi_get_rsdp_addr(acpi_physical_address *rsdp_addr)
>>  {
>> @@ -200,3 +203,23 @@ static void bios_get_rsdp_addr(acpi_physical_address *rsdp_addr)
>>  		*rsdp_addr = (acpi_physical_address)address;
>>  	}
>>  }
>> +
>> +static void get_acpi_rsdp(acpi_physical_address *rsdp_addr)
>> +{
>> +#ifdef CONFIG_KEXEC
>> +	unsigned long long res;
>> +	int len = 0;
>> +	char *val;
>> +
>> +	val = malloc(20);
>
>Why is the length 20? Defined a macro?
>

Not a calculation, if it's enough to store the address, that will be OK.

Thanks,
Chao Fan

>> +	len = cmdline_find_option("acpi_rsdp", val, 20);
>> +
>> +	if (len == -1)
>> +		return;
>> +
>> +	if (len > 0) {
>> +		val[len] = 0;
>> +		*rsdp_addr = (acpi_physical_address)kstrtoull(val, 0, &res);
>> +	}
>> +#endif
>> +}
>> -- 
>> 2.17.2
>> 
>> 
>> 
>
>
Baoquan He Oct. 22, 2018, 6:06 a.m. UTC | #3
On 10/22/18 at 05:30am, Fan, Chao wrote:
> >> +static void get_acpi_rsdp(acpi_physical_address *rsdp_addr)
> >> +{
> >> +#ifdef CONFIG_KEXEC
> >> +	unsigned long long res;
> >> +	int len = 0;
> >> +	char *val;
> >> +
> >> +	val = malloc(20);
> >
> >Why is the length 20? Defined a macro?
> >
> 
> Not a calculation, if it's enough to store the address, that will be OK.

Sorry, I didn't catch. It's 16 in setup_acpi_rsdp() of
drivers/acpi/osl.c . What does 'that' mean?

Wondering why not making it 200, it's also enough to store the address.
Chao Fan Oct. 22, 2018, 7:30 a.m. UTC | #4
On Mon, Oct 22, 2018 at 02:06:13PM +0800, Baoquan He wrote:
>On 10/22/18 at 05:30am, Fan, Chao wrote:
>> >> +static void get_acpi_rsdp(acpi_physical_address *rsdp_addr)
>> >> +{
>> >> +#ifdef CONFIG_KEXEC
>> >> +	unsigned long long res;
>> >> +	int len = 0;
>> >> +	char *val;
>> >> +
>> >> +	val = malloc(20);
>> >
>> >Why is the length 20? Defined a macro?
>> >
>> 
>> Not a calculation, if it's enough to store the address, that will be OK.
>
>Sorry, I didn't catch. It's 16 in setup_acpi_rsdp() of
>drivers/acpi/osl.c . What does 'that' mean?

The second parameter of kstrtoull(), the 16 you mentioned means
hexadecimal, not the length.
I checked my host and guest, the value are ACPI20=0xbfbfa014, ACPI20=0xdb807000.
The length of memory is 8. Well the max memory address is 16, add
"0x" and '\0' is 19. So I set it as 20.
I am not sure whether 8 is enough for the address, if OK, 11 will
be enough, or 19 is OK.
If my understanding is wrong, please tell me.

Thanks,
Chao Fan

>
>Wondering why not making it 200, it's also enough to store the address.
>
>
Baoquan He Oct. 22, 2018, 7:36 a.m. UTC | #5
On 10/22/18 at 03:30pm, Chao Fan wrote:
> On Mon, Oct 22, 2018 at 02:06:13PM +0800, Baoquan He wrote:
> >On 10/22/18 at 05:30am, Fan, Chao wrote:
> >> >> +static void get_acpi_rsdp(acpi_physical_address *rsdp_addr)
> >> >> +{
> >> >> +#ifdef CONFIG_KEXEC
> >> >> +	unsigned long long res;
> >> >> +	int len = 0;
> >> >> +	char *val;
> >> >> +
> >> >> +	val = malloc(20);
> >> >
> >> >Why is the length 20? Defined a macro?
> >> >
> >> 
> >> Not a calculation, if it's enough to store the address, that will be OK.
> >
> >Sorry, I didn't catch. It's 16 in setup_acpi_rsdp() of
> >drivers/acpi/osl.c . What does 'that' mean?
> 
> The second parameter of kstrtoull(), the 16 you mentioned means
> hexadecimal, not the length.

Yes, you are right.

> I checked my host and guest, the value are ACPI20=0xbfbfa014, ACPI20=0xdb807000.
> The length of memory is 8. Well the max memory address is 16, add
> "0x" and '\0' is 19. So I set it as 20.
> I am not sure whether 8 is enough for the address, if OK, 11 will
> be enough, or 19 is OK.

I am fine with 20. Thanks.
diff mbox series

Patch

diff --git a/arch/x86/boot/compressed/acpitb.c b/arch/x86/boot/compressed/acpitb.c
index 50fa65cf824d..37b1f4407be8 100644
--- a/arch/x86/boot/compressed/acpitb.c
+++ b/arch/x86/boot/compressed/acpitb.c
@@ -8,6 +8,9 @@ 
 #include <linux/numa.h>
 #include <linux/acpi.h>
 
+#define STATIC
+#include <linux/decompress/mm.h>
+
 /* Search EFI table for RSDP table. */
 static void efi_get_rsdp_addr(acpi_physical_address *rsdp_addr)
 {
@@ -200,3 +203,23 @@  static void bios_get_rsdp_addr(acpi_physical_address *rsdp_addr)
 		*rsdp_addr = (acpi_physical_address)address;
 	}
 }
+
+static void get_acpi_rsdp(acpi_physical_address *rsdp_addr)
+{
+#ifdef CONFIG_KEXEC
+	unsigned long long res;
+	int len = 0;
+	char *val;
+
+	val = malloc(20);
+	len = cmdline_find_option("acpi_rsdp", val, 20);
+
+	if (len == -1)
+		return;
+
+	if (len > 0) {
+		val[len] = 0;
+		*rsdp_addr = (acpi_physical_address)kstrtoull(val, 0, &res);
+	}
+#endif
+}