From: Laszlo Ersek <lersek@redhat.com>
To: "Michael S. Tsirkin" <mst@redhat.com>,
Dongjiu Geng <gengdongjiu@huawei.com>
Cc: imammedo@redhat.com, famz@redhat.com, qemu-devel@nongnu.org,
zhaoshenglong@huawei.com, peter.maydell@linaro.org,
qemu-arm@nongnu.org, james.morse@arm.com,
zhengqiang10@huawei.com, huangshaoyu@huawei.com,
wuquanming@huawei.com
Subject: Re: [Qemu-devel] [PATCH v5 2/3] ACPI: Add APEI GHES Table Generation support
Date: Thu, 13 Jul 2017 21:41:03 +0200 [thread overview]
Message-ID: <660d600a-107c-e44a-7322-ae4a74bc5565@redhat.com> (raw)
In-Reply-To: <20170713201407-mutt-send-email-mst@kernel.org>
On 07/13/17 19:32, Michael S. Tsirkin wrote:
> On Wed, Jul 12, 2017 at 10:08:16AM +0800, Dongjiu Geng wrote:
snip
>> etc/acpi/tables etc/hardware_errors
>> ================ ==========================================
>> +-----------+
>> +--------------+ | address | +-> +--------------+
>> | HEST + | registers | | | Error Status |
>> + +------------+ | +---------+ | | Data Block 0 |
>> | | GHES0 | --> | |address0 | --------+ | +------------+
>> | | GHES1 | --> | |address1 | ------+ | | CPER |
>> | | GHES2 | --> | |address2 | ----+ | | | CPER |
>> | | .... | --> | | ....... | | | | | CPER |
>> | | GHES10 | --> | |address10| -+ | | | | CPER |
>> +-+------------+ +-+---------+ | | | +-+------------+
>> | | |
>> | | +---> +--------------+
>> | | | Error Status |
>> | | | Data Block 1 |
>> | | | +------------+
>> | | | | CPER |
>> | | | | CPER |
>> | | +-+------------+
>> | |
>> | +-----> +--------------+
>> | | Error Status |
>> | | Data Block 2 |
>> | | +------------+
>> | | | CPER |
>> | +-+------------+
>> | ...........
>> +--------> +--------------+
>> | Error Status |
>> | Data Block 10|
>> | +------------+
>> | | CPER |
>> | | CPER |
>> | | CPER |
>> +-+------------+
snip
>> +
>> + error_source_table = (AcpiHardwareErrorSourceTable *)(table_data->data
>> + + table_data->len - buffer->len);
>> + error_source_table->error_source_count = GHES_ACPI_HEST_NOTIFY_RESERVED;
>> + error_source = (AcpiGenericHardwareErrorSource *)
>> + ((AcpiHardwareErrorSourceTable *)error_source_table + 1);
>
> Concern with all these casts and pointer math is that it is barely readable.
> We can easily overflow the array and get hard to debug heap corruption
> errors.
>
> What can I suggest? Just add this to the array in steps. Then you will
> not need all the math.
>
> Or again, you can just add things as you init them using build_append_int_noprefix.
>
>
>> +
>> + bios_linker_loader_write_pointer(linker, GHES_DATA_ADDR_FW_CFG_FILE,
>> + 0, sizeof(uint64_t), GHES_ERRORS_FW_CFG_FILE,
>> + GHES_ACPI_HEST_NOTIFY_RESERVED * sizeof(uint64_t));
>
> What does this uint64_t refer to? It's repeated everywhere.
>
>> +
>> + for (i = 0; i < GHES_ACPI_HEST_NOTIFY_RESERVED; i++) {
>> + error_source->type = ACPI_HEST_SOURCE_GENERIC_ERROR;
>> + error_source->source_id = cpu_to_le16(i);
>> + error_source->related_source_id = 0xffff;
>> + error_source->flags = 0;
>> + error_source->enabled = 1;
>> + /* The number of error status block per Generic Hardware Error Source */
>
> number of ... blocks ?
>
>> + error_source->number_of_records = 1;
>> + error_source->max_sections_per_record = 1;
>> + error_source->max_raw_data_length = GHES_MAX_RAW_DATA_LENGTH;
>> + error_source->error_status_address.space_id =
>> + AML_SYSTEM_MEMORY;
>> + error_source->error_status_address.bit_width = 64;
>> + error_source->error_status_address.bit_offset = 0;
>> + error_source->error_status_address.access_width = 4;
>> + error_source->notify.type = i;
>> + error_source->notify.length = sizeof(AcpiHestNotify);
>> +
>> + error_source->error_status_block_length = GHES_MAX_RAW_DATA_LENGTH;
>> +
>> + bios_linker_loader_add_pointer(linker,
>> + ACPI_BUILD_TABLE_FILE, address_registers_offset + i *
>> + sizeof(AcpiGenericHardwareErrorSource), sizeof(uint64_t),
>> + GHES_ERRORS_FW_CFG_FILE, i * sizeof(uint64_t));
>
> and what's this math for?
>
>> +
>> + error_source++;
>> + }
>> +
>> + for (i = 0; i < GHES_ACPI_HEST_NOTIFY_RESERVED; i++) {
>> + bios_linker_loader_add_pointer(linker,
>> + GHES_ERRORS_FW_CFG_FILE, sizeof(uint64_t) * i, sizeof(uint64_t),
>> + GHES_ERRORS_FW_CFG_FILE, GHES_ACPI_HEST_NOTIFY_RESERVED *
>> + sizeof(uint64_t) + i * GHES_MAX_RAW_DATA_LENGTH);
>> + }
So basically all this math exists to set up the pointers that are shown
in the diagram in the commit message. It is a bit tricky because most of
those pointer fields (all 8-bytes wide) are individually embedded into
their own containing structures. In the previous version of this patch
set, I painstakingly verified the math, and pointed out wherever I
thought updates were necessary.
I agree the math is hard to read, the code is very "dense". My
suggestion (supporting yours) would be to calculate the fw_cfg blob
offsets that should be patched in more fine-grained steps, possibly with
multiple separate increments, using:
- structure type names,
- sizeof operators,
- offsetof macros,
- and possibly a separate comment for each offset increment.
Thanks,
Laszlo
next prev parent reply other threads:[~2017-07-13 19:41 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-12 2:08 [Qemu-devel] [PATCH v5 0/3] Generate APEI GHES table and dynamically record CPER Dongjiu Geng
2017-07-12 2:08 ` [Qemu-devel] [PATCH v5 1/3] ACPI: Add new ACPI structures and macros Dongjiu Geng
2017-07-13 10:33 ` Laszlo Ersek
2017-07-13 12:00 ` gengdongjiu
2017-07-13 15:33 ` Laszlo Ersek
2017-07-13 17:13 ` Michael S. Tsirkin
2017-07-14 8:25 ` gengdongjiu
2017-07-13 17:35 ` Michael S. Tsirkin
2017-07-13 17:01 ` Michael S. Tsirkin
2017-07-14 5:51 ` gengdongjiu
2017-07-13 17:11 ` Michael S. Tsirkin
2017-07-14 8:22 ` gengdongjiu
2017-07-12 2:08 ` [Qemu-devel] [PATCH v5 2/3] ACPI: Add APEI GHES Table Generation support Dongjiu Geng
2017-07-13 17:32 ` Michael S. Tsirkin
2017-07-13 19:41 ` Laszlo Ersek [this message]
2017-07-13 22:31 ` Michael S. Tsirkin
2017-07-17 4:43 ` gengdongjiu
2017-07-12 2:08 ` [Qemu-devel] [PATCH v5 3/3] ACPI: build and enable APEI GHES in the Makefile and configuration Dongjiu Geng
2017-07-13 17:36 ` [Qemu-devel] [PATCH v5 0/3] Generate APEI GHES table and dynamically record CPER Michael S. Tsirkin
-- strict thread matches above, loose matches on Subject: below --
2017-07-15 15:29 [Qemu-devel] [PATCH v5 2/3] ACPI: Add APEI GHES Table Generation support gengdongjiu
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=660d600a-107c-e44a-7322-ae4a74bc5565@redhat.com \
--to=lersek@redhat.com \
--cc=famz@redhat.com \
--cc=gengdongjiu@huawei.com \
--cc=huangshaoyu@huawei.com \
--cc=imammedo@redhat.com \
--cc=james.morse@arm.com \
--cc=mst@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=wuquanming@huawei.com \
--cc=zhaoshenglong@huawei.com \
--cc=zhengqiang10@huawei.com \
/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).