[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v19 3/9] pc: add a Virtual Machine Generation ID
From: |
Laszlo Ersek |
Subject: |
Re: [Qemu-devel] [PATCH v19 3/9] pc: add a Virtual Machine Generation ID device |
Date: |
Wed, 10 Feb 2016 11:00:22 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 |
On 02/10/16 10:28, Michael S. Tsirkin wrote:
> On Wed, Feb 10, 2016 at 10:51:47AM +0200, Michael S. Tsirkin wrote:
>> So maybe we should
>> leave this alone, wait until we see an actual user - this way we can
>> figure out the implementation constraints better.
>
> What I'm definitely interested in seeing is improving the
> bios_linker_loader API within QEMU.
>
> Is the below going in the right direction, in your opinion?
>
>
> diff --git a/include/hw/acpi/bios-linker-loader.h
> b/include/hw/acpi/bios-linker-loader.h
> index 498c0af..78d9a16 100644
> --- a/include/hw/acpi/bios-linker-loader.h
> +++ b/include/hw/acpi/bios-linker-loader.h
> @@ -17,6 +17,17 @@ void bios_linker_loader_add_checksum(GArray *linker, const
> char *file,
> void *start, unsigned size,
> uint8_t *checksum);
>
> +/*
> + * bios_linker_loader_add_pointer: ask guest to append address of source file
> + * into destination file at the specified pointer.
> + *
> + * @linker: linker file array
> + * @dest_file: destination file that must be changed
> + * @src_file: source file whos address must be taken
> + * @table: destination file array
> + * @pointer: location of the pointer to be patched within destination file
> + * @pointer_size: size of pointer to be patched, in bytes
> + */
> void bios_linker_loader_add_pointer(GArray *linker,
> const char *dest_file,
> const char *src_file,
> diff --git a/hw/acpi/bios-linker-loader.c b/hw/acpi/bios-linker-loader.c
> index e04d60a..84be25a 100644
> --- a/hw/acpi/bios-linker-loader.c
> +++ b/hw/acpi/bios-linker-loader.c
> @@ -142,7 +142,13 @@ void bios_linker_loader_add_pointer(GArray *linker,
> uint8_t pointer_size)
> {
> BiosLinkerLoaderEntry entry;
> - size_t offset = (gchar *)pointer - table->data;
> + size_t offset;
> +
> + assert((gchar *)pointer >= table->data);
> +
> + offset = (gchar *)pointer - table->data;
> +
> + assert(offset + pointer_size < table->len);
>
> memset(&entry, 0, sizeof entry);
> strncpy(entry.pointer.dest_file, dest_file,
>
I have two suggestions (independently of Igor's upcoming opinion):
(1) I propose to do all this arithmetic in uintptr_t, not (char*).
(2) In the last assertion, < should be <=. Both sides are exclusive, so
equality is valid.
(BTW the OVMF implementation of the linker-loader client is chock full
of verifications like the above, done in UINT64, so I can only agree
with the above safety measures, independently of vmgenid.)
Thanks
Laszlo