lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20190117032027.GA31097@localhost.localdomain>
Date:   Thu, 17 Jan 2019 11:20:27 +0800
From:   Chao Fan <fanc.fnst@...fujitsu.com>
To:     Borislav Petkov <bp@...en8.de>
CC:     <linux-kernel@...r.kernel.org>, <x86@...nel.org>,
        <tglx@...utronix.de>, <mingo@...hat.com>, <hpa@...or.com>,
        <keescook@...omium.org>, <bhe@...hat.com>, <msys.mizuma@...il.com>,
        <indou.takao@...fujitsu.com>, <caoj.fnst@...fujitsu.com>
Subject: Re: [PATCH v15 5/6] x86/boot: Parse SRAT address from RSDP and store
 immovable memory

On Wed, Jan 16, 2019 at 12:01:58PM +0100, Borislav Petkov wrote:
>On Mon, Jan 07, 2019 at 11:22:42AM +0800, Chao Fan wrote:
>> +void get_immovable_mem(void)
>> +{
>> +	struct acpi_table_header *table_header;
>> +	struct acpi_subtable_header *table;
>> +	struct acpi_srat_mem_affinity *ma;
>> +	char arg[MAX_ACPI_ARG_LENGTH];
>> +	unsigned long table_end;
>> +	int i = 0;
>> +
>> +	if (cmdline_find_option("acpi", arg, sizeof(arg)) == 3 &&
>> +	    !strncmp(arg, "off", 3))
>> +		return;
>> +
>> +	table_header = get_acpi_srat_table();
>> +	if (!table_header)
>> +		return;
>> +
>> +	table_end = (unsigned long)table_header + table_header->length;
>> +	table = (struct acpi_subtable_header *)
>> +		((unsigned long)table_header + sizeof(struct acpi_table_srat));
>> +
>> +	while (((unsigned long)table) +
>> +		       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)) {
>> +				immovable_mem[i].start = ma->base_address;
>> +				immovable_mem[i].size = ma->length;
>> +				i++;
>> +			}
>> +
>> +			if (i >= MAX_NUMNODES*2) {
>> +				debug_putstr("Too many immovable memory regions, aborting.\n");
>> +				return;
>> +			}
>> +		}
>> +		table = (struct acpi_subtable_header *)
>> +			((unsigned long)table + table->length);
>
>That's a lot of unnecessary casting AFAICT. You can return an unsigned
>long from get_acpi_srat_table() and get rid of all that casting here.
>
Hi Boris,

I have changed as you suggested, looks clear without type cast, and
we need some variable as long to calculate the address, and at same
time as the struct pointer to find it's length, so I change as below,
and get_acpi_srat_table() return an unsigned long.
How do you think of that.

int get_immovable_mem_num(void)
{
        unsigned long table_addr, table_end, table;
        struct acpi_table_header *table_header;
        struct acpi_subtable_header *sub_table;
        char arg[MAX_ACPI_ARG_LENGTH];
        int num = 0;

        if (cmdline_find_option("acpi", arg, sizeof(arg)) == 3 &&
            !strncmp(arg, "off", 3))
                return;

        table_addr = get_acpi_srat_table();
        if (!table_addr)
                return;

        table_header = (struct acpi_table_header *)table_addr;
        table_end = table_addr + table_header->length;
        table = table_addr + sizeof(struct acpi_table_srat);

        while (table + sizeof(struct acpi_subtable_header) < table_end) {
                sub_table = (struct acpi_subtable_header *)table;
                if (sub_table->type == ACPI_SRAT_TYPE_MEMORY_AFFINITY) {
                        struct acpi_srat_mem_affinity *ma;

                        ma = (struct acpi_srat_mem_affinity *)table;
                        if (!(ma->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE)) {
                                immovable_mem[num].start = ma->base_address;
                                immovable_mem[num].size = ma->length;
                                num++;
                        }

                        if (num >= MAX_NUMNODES*2) {
                                debug_putstr("Too many immovable memory regions, aborting.\n");
                                return 0;
                        }
                }
                table += sub_table->length;
        }
        return num;
}

Thanks,
Chao Fan


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ