[pve-devel] [PATCH qemu-server v11 1/5] add C program to get hardware capabilities from CPUID

Fiona Ebner f.ebner at proxmox.com
Wed Jul 24 15:05:49 CEST 2024


Am 29.05.24 um 14:23 schrieb Markus Frank:
> Implement a C program that extracts AMD SEV hardware information such
> as reduced-phys-bios and cbitpos from CPUID at boot time, looks if
> SEV, SEV-ES & SEV-SNP are enabled, and outputs these details as JSON
> to /run/qemu-server/host-hw-capabilities.json
> 
> This programm can also be used to read and save other hardware

Typo: should be "program"

> information at boot time.
> 
> Signed-off-by: Markus Frank <m.frank at proxmox.com>
> Co-authored-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
> Tested-by: Filip Schauer <f.schauer at proxmox.com>

Since there were changes, the Tested-by trailer should be removed.

With the suggested changes below:

Reviewed-by: Fiona Ebner <f.ebner at proxmox.com>

> ---
> changes v11:
> * removed systemd service

* improved error handling

> +    ret = fprintf(file,
> +	"{"
> +	" \"amd-sev\": {"
> +	" \"cbitpos\": %u,"
> +	" \"reduced-phys-bits\": %u,"
> +	" \"sev-support\": %s,"
> +	" \"sev-support-es\": %s,"
> +	" \"sev-support-snp\": %s"
> +	" }"
> +	" }\n",
> +	cbitpos,
> +	reduced_phys_bits,
> +	sev_support ? "true" : "false",
> +	sev_es_support ? "true" : "false",
> +	sev_snp_support ? "true" : "false"
> +    );
> +    if (ret == -1) {

"man 3 fprintf" states:

> If an output error is encountered, a negative value is returned."

and while a quick glance at the source code shows that -1 is used in
many places, I'm not sure that's true for all error paths. Let's check
for < 0 instead.

> +	printf("Error writing to file %s: %s\n", path, strerror(errno));
> +    }
> +
> +    ret = fclose(file);

Nit:

"man 3 fclose" states:

> Upon successful completion, 0 is returned. Otherwise, EOF is returned
> and errno is set to indicate the error.

While EOF is defined to be -1 in stdio.h, it's better to use the
constant explicitly (or could also use ret != 0).

> +    if (ret == -1) {
> +	printf("Error closing file %s: %s\n", path, strerror(errno));
> +    }
> +
> +    return 0;
> +}




More information about the pve-devel mailing list