public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Chao Fan <fanc.fnst@cn.fujitsu.com>
To: Borislav Petkov <bp@alien8.de>
Cc: <linux-kernel@vger.kernel.org>, <x86@kernel.org>,
	<tglx@linutronix.de>, <mingo@redhat.com>, <hpa@zytor.com>,
	<keescook@chromium.org>, <bhe@redhat.com>,
	<msys.mizuma@gmail.com>, <indou.takao@jp.fujitsu.com>,
	<caoj.fnst@cn.fujitsu.com>
Subject: Re: [PATCH v13 2/6] x86/boot: Introduce get_acpi_rsdp() to parse RSDP in cmdline from KEXEC
Date: Fri, 14 Dec 2018 09:31:05 +0800	[thread overview]
Message-ID: <20181214013105.GC24409@localhost.localdomain> (raw)
In-Reply-To: <20181213194230.GF25287@zn.tnic>

On Thu, Dec 13, 2018 at 08:42:30PM +0100, Borislav Petkov wrote:
>On Wed, Dec 12, 2018 at 11:10:49AM +0800, Chao Fan wrote:
>> Memory information in SRAT is necessary to fix the conflict between
>> KASLR and memory-hotremove.
>> 
>> ACPI SRAT (System/Static Resource Affinity Table) shows the details
>> about memory ranges, including ranges of memory provided by hot-added
>> memory devices. SRAT is introduced by Root System Description
>> Pointer(RSDP). So RSDP should be found firstly.
>> 
>> When booting form KEXEC/EFI/BIOS, the methods to find RSDP
>> are different. When booting from KEXEC, 'acpi_rsdp' may have been
>> added to cmdline, so parse cmdline to find RSDP.
>> 
>> Since 'RANDOMIZE_BASE' && 'MEMORY_HOTREMOVE' is needed, introduce
>> 'CONFIG_EARLY_PARSE_RSDP' to make ifdeffery clear.
>> 
>> Signed-off-by: Chao Fan <fanc.fnst@cn.fujitsu.com>
>> ---
>>  arch/x86/Kconfig                | 10 ++++++++++
>>  arch/x86/boot/compressed/acpi.c | 30 ++++++++++++++++++++++++++++++
>>  arch/x86/boot/compressed/misc.h |  6 ++++++
>>  3 files changed, 46 insertions(+)
>>  create mode 100644 arch/x86/boot/compressed/acpi.c
>> 
>> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
>> index ba7e3464ee92..455da382fa9e 100644
>> --- a/arch/x86/Kconfig
>> +++ b/arch/x86/Kconfig
>> @@ -2149,6 +2149,16 @@ config X86_NEED_RELOCS
>>  	def_bool y
>>  	depends on RANDOMIZE_BASE || (X86_32 && RELOCATABLE)
>>  
>> +config EARLY_PARSE_RSDP
>
>That should be EARLY_SRAT_PARSE or so
>
>> +	bool "Parse RSDP pointer on compressed period for KASLR"
>
>and that should be
>
>	bool "Early SRAT table parsing"
>
>> +	def_bool y
>> +	depends on RANDOMIZE_BASE && MEMORY_HOTREMOVE
>> +	help
>> +	  This option parses RSDP in compressed period. Works
>
>do s/compressed period/compressed stage/g
>
>I think "compressed stage" or "compressed boot stage" is more precise.
>
>> +	  for KASLR to get memory information from SRAT table and choose
>> +	  immovable memory to extract kernel.
>> +	  Say Y if you want to use both KASLR and memory-hotremove.
>
>This help text needs to explain what the functionality is for. "This
>option parses RSDP in compressed period" doesn't tell a whole lot to the
>normal user wondering whether she should enable this or not. You need to
>explain whether people would need this or not so should start along the
>lines of:
>
>"This option enables early SRAT parsing so that memory hot remove ranges do not
>overlap with KASLR chosen ranges..."
>
>Basically, the "***Background" in your 0th message.
>

Thanks, I will rewrite this part.

>> +
>>  config PHYSICAL_ALIGN
>>  	hex "Alignment value to which kernel should be aligned"
>>  	default "0x200000"
>> diff --git a/arch/x86/boot/compressed/acpi.c b/arch/x86/boot/compressed/acpi.c
>> new file mode 100644
>> index 000000000000..cad15686f82c
>> --- /dev/null
>> +++ b/arch/x86/boot/compressed/acpi.c
>> @@ -0,0 +1,30 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +#define BOOT_CTYPE_H
>> +#include "misc.h"
>> +#include "error.h"
>> +
>> +#include <linux/efi.h>
>> +#include <linux/numa.h>
>> +#include <linux/acpi.h>
>> +#include <asm/efi.h>
>> +
>> +#define STATIC
>> +#include <linux/decompress/mm.h>
>> +
>> +#include "../string.h"
>> +
>> +static acpi_physical_address get_acpi_rsdp(void)
>> +{
>> +#ifdef CONFIG_KEXEC
>> +	unsigned long long res;
>> +	int len = 0;
>> +	char val[MAX_ADDRESS_LENGTH+1];
>
>Please sort function local variables declaration in a reverse christmas
>tree order:
>
>	<type A> longest_variable_name;
>	<type B> shorter_var_name;
>	<type C> even_shorter;
>	<type D> i;

I will change the position and check other places like this.

>
>> +
>> +	len = cmdline_find_option("acpi_rsdp", val, MAX_ADDRESS_LENGTH+1);
>
>That MAX_ADDRESS_LENGTH define is used only here, right? So put it at
>the top in this file - no need to have it in a header.
>
>> +	if (len > 0) {
>> +		val[len] = 0;
>> +		return (acpi_physical_address)kstrtoull(val, 16, &res);
>> +	}
>> +	return 0;
>> +#endif
>
>Those two lines need to be the other way around:
>
>#endif
>	return 0;
>
>because in the !CONFIG_KEXEC case that function won't return anything.
>gcc is smart enough to optimize that function away so that there's no
>build error but still.
>
>Ditto for efi_get_rsdp_addr() in your next patch.

Yes, I will change all places like this.

Thanks,
Chao Fan

>
>> +}
>> diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h
>> index a1d5918765f3..72fcfbfec3c6 100644
>> --- a/arch/x86/boot/compressed/misc.h
>> +++ b/arch/x86/boot/compressed/misc.h
>> @@ -116,3 +116,9 @@ static inline void console_init(void)
>>  void set_sev_encryption_mask(void);
>>  
>>  #endif
>> +
>> +/* acpi.c */
>> +#ifdef CONFIG_EARLY_PARSE_RSDP
>> +/* Max length of 64-bit hex address string is 18, prefix "0x" + 16 hex digit. */
>> +#define MAX_ADDRESS_LENGTH 18
>> +#endif
>> -- 
>
>Yeah, just put that define in acpi.c.
>
>-- 
>Regards/Gruss,
>    Boris.
>
>Good mailing practices for 400: avoid top-posting and trim the reply.
>
>



  reply	other threads:[~2018-12-14  1:31 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-12  3:10 [PATCH v13 0/6] x86/boot/KASLR: Parse ACPI table and limit KASLR to choosing immovable memory Chao Fan
2018-12-12  3:10 ` [PATCH v13 1/6] x86/boot: Introduce kstrtoull() to boot directory instead of simple_strtoull() Chao Fan
2018-12-12  4:12   ` Chao Fan
2018-12-12  8:03     ` Baoquan He
2018-12-13 13:26       ` Borislav Petkov
2018-12-14  1:34         ` Chao Fan
2018-12-14 10:38           ` Borislav Petkov
2018-12-17  1:27         ` Chao Fan
2018-12-17 15:45           ` Borislav Petkov
2018-12-18  3:20             ` Chao Fan
2018-12-12  7:46   ` Baoquan He
2018-12-12  8:10     ` Chao Fan
2018-12-13 12:50   ` Borislav Petkov
2018-12-14  2:59     ` Chao Fan
2018-12-14 11:57       ` Borislav Petkov
2018-12-16 19:22   ` kbuild test robot
2018-12-16 20:31     ` Borislav Petkov
2018-12-12  3:10 ` [PATCH v13 2/6] x86/boot: Introduce get_acpi_rsdp() to parse RSDP in cmdline from KEXEC Chao Fan
2018-12-13 19:25   ` Masayoshi Mizuma
2018-12-13 19:29     ` Borislav Petkov
2018-12-13 19:38       ` Masayoshi Mizuma
2018-12-14  1:32     ` Chao Fan
2018-12-13 19:42   ` Borislav Petkov
2018-12-14  1:31     ` Chao Fan [this message]
2018-12-12  3:10 ` [PATCH v13 3/6] x86/boot: Introduce efi_get_rsdp_addr() to find RSDP from EFI table Chao Fan
2018-12-13 20:23   ` Borislav Petkov
2018-12-14  1:28     ` Chao Fan
2018-12-17 17:16   ` Masayoshi Mizuma
2018-12-12  3:10 ` [PATCH v13 4/6] x86/boot: Introduce bios_get_rsdp_addr() to search RSDP in memory Chao Fan
2018-12-12  3:10 ` [PATCH v13 5/6] x86/boot: Parse SRAT from RSDP and store immovable memory Chao Fan
2018-12-12  3:10 ` [PATCH v13 6/6] x86/boot/KASLR: Limit KASLR to extracting kernel in " Chao Fan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181214013105.GC24409@localhost.localdomain \
    --to=fanc.fnst@cn.fujitsu.com \
    --cc=bhe@redhat.com \
    --cc=bp@alien8.de \
    --cc=caoj.fnst@cn.fujitsu.com \
    --cc=hpa@zytor.com \
    --cc=indou.takao@jp.fujitsu.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=msys.mizuma@gmail.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox