[pve-devel] [PATCH qemu-server v3 3/5] Convert policy calculation
Fiona Ebner
f.ebner at proxmox.com
Wed Mar 5 16:35:15 CET 2025
Am 24.02.25 um 13:37 schrieb Philipp Giersfeld:
> Convert policy calcucalation to use shift operators and OR operation
Nit: there is a typo here: calcucalation
> instead of binary numbers and addition.
>
> Signed-off-by: Philipp Giersfeld <philipp.giersfeld at canarybit.eu>
> Reviewed-by: Daniel Kral <d.kral at proxmox.com>
> Tested-by: Markus Frank <m.frank at proxmox.com>
With the typo above fixed:
Reviewed-by: Fiona Ebner <f.ebner at proxmox.com>
> ---
>
> no changes since last version
>
> PVE/QemuServer/CPUConfig.pm | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/PVE/QemuServer/CPUConfig.pm b/PVE/QemuServer/CPUConfig.pm
> index e65d8c26..ad0be16e 100644
> --- a/PVE/QemuServer/CPUConfig.pm
> +++ b/PVE/QemuServer/CPUConfig.pm
> @@ -846,12 +846,12 @@ sub get_amd_sev_object {
>
> # guest policy bit calculation as described here:
> # https://documentation.suse.com/sles/15-SP5/html/SLES-amd-sev/article-amd-sev.html#table-guestpolicy
> - my $policy = 0b0000;
> - $policy += 0b0001 if $amd_sev_conf->{'no-debug'};
> - $policy += 0b0010 if $amd_sev_conf->{'no-key-sharing'};
> - $policy += 0b0100 if $amd_sev_conf->{type} eq 'es';
> + my $policy = 0;
> + $policy |= 1 << 0 if $amd_sev_conf->{'no-debug'};
> + $policy |= 1 << 1 if $amd_sev_conf->{'no-key-sharing'};
> + $policy |= 1 << 2 if $amd_sev_conf->{type} eq 'es';
> # disable migration with bit 3 nosend to prevent amd-sev-migration-attack
> - $policy += 0b1000;
> + $policy |= 1 << 3;
>
> $sev_mem_object .= ',policy='.sprintf("%#x", $policy);
> $sev_mem_object .= ',kernel-hashes=on' if ($amd_sev_conf->{'kernel-hashes'});
While at it, we could also go for using constants, i.e. something like:
$policy |= AMD_SEV_POLICY_NO_DEBUG if $amd_sev_conf->{'no-debug'};
and for the one in the next patch, AMD_SEV_SNP_POLICY_NO_DEBUG.
But not a blocker from my side, if you don't want to go for it.
More information about the pve-devel
mailing list