lkml.org 
[lkml]   [2018]   [Oct]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v8 0/3] x86/boot/KASLR: Parse ACPI table and limit kaslr in immovable memory
On Wed, Oct 24, 2018 at 03:21:36PM -0400, Masayoshi Mizuma wrote:
>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.

Yes, I agree. But I think this method is much better than
adding code to arch/x86/mm/kaslr.c.

>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?

I have no idea. I will work on it, try to help figure out the BIOS issue.

Thanks,
Chao Fan

>
>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
>>
>>
>
>


\
 
 \ /
  Last update: 2018-10-25 03:24    [W:0.084 / U:1.148 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site