linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Masayoshi Mizuma <msys.mizuma@gmail.com>
To: Chao Fan <fanc.fnst@cn.fujitsu.com>,
	Borislav Petkov <bp@alien8.de>, Baoquan He <bhe@redhat.com>,
	Ingo Molnar <mingo@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org, x86@kernel.org,
	linux-efi@vger.kernel.org, linux-acpi@vger.kernel.org,
	mingo@redhat.com, hpa@zytor.com, keescook@chromium.org,
	rjw@rjwysocki.net, lenb@kernel.org, ard.biesheuvel@linaro.org,
	indou.takao@jp.fujitsu.com, caoj.fnst@cn.fujitsu.com
Subject: Re: [PATCH v8 0/3] x86/boot/KASLR: Parse ACPI table and limit kaslr in immovable memory
Date: Wed, 24 Oct 2018 15:21:36 -0400	[thread overview]
Message-ID: <20181024192135.7qhhfbbrgb4ojgqe@gabell> (raw)
In-Reply-To: <20181023024801.GA25978@localhost.localdomain>

On Tue, Oct 23, 2018 at 10:48:02AM +0800, Chao Fan wrote:
> On Mon, Oct 22, 2018 at 11:42:05AM -0400, Masayoshi Mizuma wrote:
> >Hi Boris,
> 
> Hi Mizuma-san,
> 
> I have several questions:

Thank you for your comments! I think your suggestions are
right.
However, the prototype patch works EFI environment only.
The memory hot-plug affinity in SRAT and KASLR are also available
on legacy BIOS environment, so I need to get the patch useful
for legacy BIOS as well, but I have no idea to add such things...
If you have ideas, could you let me know?

Probably I should have another idea, for example,
add the SRAT parsing code, looks like you are adding to
arch/x86/boot/compressed/acpitb.c, to arch/x86/mm/kaslr.c.

Thanks,
Masa

> 
> >+static void store_possible_addr(unsigned long long possible)
> >+{
> >+	struct setup_data *data;
> >+
> >+	data = (struct setup_data *)(unsigned long)boot_params->hdr.setup_data;
> I suggest you add check:
> 
> 	if (!data) {
> 		debug_putstr("No setup_data found.\n");
> 		return;
> 	}
> 
> >+	while (data) {
> >+		if (data->type == SETUP_KASLR) {
> >+			*(unsigned long long *)data->data = possible;
> >+			return;
> >+		}
> >+		data = (struct setup_data *)(unsigned long)data->next;
> >+	}
> >+}
> >+
> > /*
> >  * According to ACPI table, filter the immvoable memory regions
> >  * and store them in immovable_mem[].
> >@@ -319,6 +333,7 @@ void get_immovable_mem(void)
> > 	struct acpi_subtable_header *table;
> > 	struct acpi_srat_mem_affinity *ma;
> > 	unsigned long table_end;
> >+	unsigned long long possible_addr, max_possible_addr = 0;
> > 	int i = 0;
> >
> > 	if (!cmdline_find_option_bool("movable_node") ||
> >@@ -338,7 +353,12 @@ void get_immovable_mem(void)
> > 		       sizeof(struct acpi_subtable_header) < table_end) {
> > 		if (table->type == ACPI_SRAT_TYPE_MEMORY_AFFINITY) {
> > 			ma = (struct acpi_srat_mem_affinity *)table;
> >-			if (!(ma->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE)) {
> >+
> >+			if (ma->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE) {
> >+				possible_addr = ma->base_address + ma->length;
> >+				if (possible_addr > max_possible_addr)
> >+					max_possible_addr = possible_addr;
> >+			} else {
> > 				immovable_mem[i].start = ma->base_address;
> > 				immovable_mem[i].size = ma->length;
> > 				i++;
> >@@ -351,4 +371,5 @@ void get_immovable_mem(void)
> > 			((unsigned long)table + table->length);
> > 	}
> > 	num_immovable_mem = i;
> >+	store_possible_addr(max_possible_addr);
> > }
> >diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
> >index 1458b17..9b95fba 100644
> >--- a/arch/x86/boot/compressed/eboot.c
> >+++ b/arch/x86/boot/compressed/eboot.c
> >@@ -192,6 +192,40 @@ static void setup_efi_pci(struct boot_params *params)
> > 	efi_call_early(free_pool, pci_handle);
> > }
> >
> >+#ifdef CONFIG_RANDOMIZE_MEMORY
> >+static void setup_kaslr(struct boot_params *params)
> >+{
> >+	struct setup_data *kaslr_data = NULL;
> >+	struct setup_data *data;
> >+	unsigned long size;
> >+	efi_status_t status;
> >+
> >+	size = sizeof(struct setup_data) + sizeof(unsigned long long);
> >+
> >+	status = efi_call_early(allocate_pool, EFI_LOADER_DATA,
> >+			size, (void **)&kaslr_data);
> >+	if (status != EFI_SUCCESS) {
> >+		efi_printk(sys_table, "Failed to allocate memory for 'kaslr_data'\n");
> >+		return;
> >+	}
> >+
> >+	kaslr_data->type = SETUP_KASLR;
> >+	kaslr_data->next = 0;
> >+	kaslr_data->len = size;
> >+
> >+	data = (struct setup_data *)(unsigned long)params->hdr.setup_data;
> >+	if (data)
> >+		data->next = (unsigned long)kaslr_data;
> Why just put the kaslr_data in data->next. You can't make sure
> data->next was NULL.
> >+	else {
> If data is NULL, go to this else{}, so these two lines below work?
> >+		while (data->next)
> >+			data = (struct setup_data *)(unsigned long)data->next;
> >+		data->next = (unsigned long)kaslr_data;
> >+	}
> If my understanding is not wrong, it should be:
> 
> 	data = (struct setup_data *)(unsigned long)params->hdr.setup_data;
> 	if (!data)
> 		params->hdr.setup_data = (unsigned long)kaslr_data;
> 	else {
> 		while (data->next)
> 			data = (struct setup_data *)(unsigned long)data->next;
> 		data->next = (unsigned long)kaslr_data;
> 	}
> 
> If I misunderstand something, please tell me.
> 
> Thanks,
> Chao Fan
> 
> 

  reply	other threads:[~2018-10-24 19:21 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-10  8:41 [PATCH v8 0/3] x86/boot/KASLR: Parse ACPI table and limit kaslr in immovable memory Chao Fan
2018-10-10  8:41 ` [PATCH v8 1/3] x86/boot: Add acpitb.c to parse acpi tables Chao Fan
2018-10-11 10:57   ` Borislav Petkov
2018-10-12  1:56     ` Chao Fan
2018-10-12  9:36     ` Chao Fan
2018-10-12  9:46       ` Borislav Petkov
2018-10-12 10:03         ` Chao Fan
2018-10-16  2:48     ` Chao Fan
2018-10-16 12:40       ` Borislav Petkov
2018-10-17  1:10         ` Chao Fan
2018-10-15 20:26   ` Masayoshi Mizuma
2018-10-16  1:50     ` Chao Fan
2018-10-10  8:41 ` [PATCH v8 2/3] x86/boot/KASLR: Walk srat tables to filter immovable memory Chao Fan
2018-10-10  8:41 ` [PATCH v8 3/3] x86/boot/KASLR: Limit kaslr to choosing the " Chao Fan
2018-10-10  8:59 ` [PATCH v8 0/3] x86/boot/KASLR: Parse ACPI table and limit kaslr in " Borislav Petkov
2018-10-10  9:06   ` Baoquan He
2018-10-10  9:12     ` Chao Fan
2018-10-10  9:21       ` Baoquan He
2018-10-10  9:14     ` Thomas Gleixner
2018-10-10  9:19       ` Borislav Petkov
2018-10-10  9:30         ` Baoquan He
2018-10-10 19:44           ` Masayoshi Mizuma
2018-10-11  0:29             ` Baoquan He
2018-10-11  5:51               ` Chao Fan
2018-10-13 20:19                 ` Masayoshi Mizuma
2018-10-13 20:34                   ` Borislav Petkov
2018-10-13 21:45                     ` Masayoshi Mizuma
2018-10-13 22:05                       ` Borislav Petkov
2018-10-15  0:50                         ` Masayoshi Mizuma
2018-10-16 15:13                           ` Masayoshi Mizuma
2018-10-16 19:11                             ` Borislav Petkov
2018-10-16 19:54                               ` Masayoshi Mizuma
2018-10-16 19:59                                 ` Borislav Petkov
2018-10-22 15:42                                   ` Masayoshi Mizuma
2018-10-23  2:48                                     ` Chao Fan
2018-10-24 19:21                                       ` Masayoshi Mizuma [this message]
2018-10-25  1:22                                         ` Chao Fan
2018-10-25 10:33                                     ` Borislav Petkov
2018-10-25 13:40                                       ` Masayoshi Mizuma
2018-11-06 12:10                                         ` Borislav Petkov
2018-11-06 14:07                                           ` Baoquan He
2018-11-07  1:21                                             ` Chao Fan
2018-11-06 18:45                                         ` Borislav Petkov
2018-11-06 19:36                                           ` Masayoshi Mizuma
2018-11-06 20:45                                             ` Borislav Petkov
2018-11-06 22:21                                               ` Masayoshi Mizuma
2018-11-08 10:51                                                 ` Borislav Petkov
2018-11-10 10:54                                                   ` Borislav Petkov
2018-11-11 13:45                                                     ` Masayoshi Mizuma
2019-02-05 15:05                                                       ` Masayoshi Mizuma
2019-02-08 18:26                                                         ` Borislav Petkov
2019-02-09  0:24                                                           ` Masayoshi Mizuma
2019-02-11  1:46                                                         ` Chao Fan
2019-02-11 20:11                                                           ` Masayoshi Mizuma
2018-10-10 17:16 ` Borislav Petkov
2018-10-11  1:30   ` 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=20181024192135.7qhhfbbrgb4ojgqe@gabell \
    --to=msys.mizuma@gmail.com \
    --cc=ard.biesheuvel@linaro.org \
    --cc=bhe@redhat.com \
    --cc=bp@alien8.de \
    --cc=caoj.fnst@cn.fujitsu.com \
    --cc=fanc.fnst@cn.fujitsu.com \
    --cc=hpa@zytor.com \
    --cc=indou.takao@jp.fujitsu.com \
    --cc=keescook@chromium.org \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=mingo@redhat.com \
    --cc=rjw@rjwysocki.net \
    --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;
as well as URLs for NNTP newsgroup(s).