AMD SEV实现

SEV使用流程

启动虚拟机参考流程

image.png

image.png

迁移参考流程

image.png

libvirt SEV相关代码分析

struct _virDomainObj {
    ...
    virDomainDefPtr def; /* The current definition */
    ...
}
struct _virDomainDef {
   ...
    virDomainSEVDefPtr sev;
    ...
}
struct _virDomainSEVDef {
    int sectype; /* enum virDomainLaunchSecurity */
    char *dh_cert;
    char *session;
    unsigned int policy;
    bool haveCbitpos;
    unsigned int cbitpos;
    bool haveReducedPhysBits;
    unsigned int reduced_phys_bits;
};
typedef struct _virDomainSEVDef virDomainSEVDef;
typedef virDomainSEVDef *virDomainSEVDefPtr;
typedef enum {
    VIR_DOMAIN_LAUNCH_SECURITY_NONE,
    VIR_DOMAIN_LAUNCH_SECURITY_SEV,
    VIR_DOMAIN_LAUNCH_SECURITY_LAST,
} virDomainLaunchSecurity;
struct _virQEMUCaps {
    ...
    virSEVCapability *sevCapabilities;
    ...
};
typedef struct _virSEVCapability virSEVCapability;
typedef virSEVCapability *virSEVCapabilityPtr;
struct _virSEVCapability {
    char *pdh;
    char *cert_chain;
    unsigned int cbitpos;
    unsigned int reduced_phys_bits;
};
/**
 *
 * SEV Parameters
 */
/**
 * VIR_NODE_SEV_PDH:
 *
 * Macro represents the Platform Diffie-Hellman key, as VIR_TYPED_PARAMS_STRING.
 */
# define VIR_NODE_SEV_PDH "pdh"
/**
 * VIR_NODE_SEV_CERT_CHAIN:
 *
 * Macro represents the platform certificate chain that includes the platform
 * endorsement key (PEK), owner certificate authority (OCD) and chip
 * endorsement key (CEK), as VIR_TYPED_PARAMS_STRING.
 */
# define VIR_NODE_SEV_CERT_CHAIN "cert-chain"

virDomainSEVDefParseXML函数通过解析虚拟机xml来填充struct virDomainSEVDef。

qemuProcessLaunch

    ->qemuDomainBuildNamespace

        ->qemuDomainSetupLaunchSecurity # 里面将/dev/sev添加到paths中。

qemuProcessLaunch

    ->qemuBuildCommandLine

        ->qemuBuildSEVCommandLine # 添加-object sev-guest,id=sev0,cbitpos=<cbitpos>,reduced-phys-bits=<reduced_phys_bits>,policy=0x<policy>,dh-cert-file=<priv->libDir>/dh_cert.base64,session-file=<priv->libDir>/session.base64

        ->qemuBuildMachineCommandLine # 为-machine参数添加memory-encryption:-machine ...,memory-encryption=sev0

DH算法是用来进行密钥交换的算法。在使用SEV虚拟机的场景下,DH算法用于交换guest owner(用户)与SEV固件的主密钥(master secret key),该主密钥用于guest owner与SEV固件进行加密通信。

首次调用virsh domcapabilities流程如下(libvirt-6.9,/var/cache/libvirt/qemu/capabilities/没有之前缓存的情况下):

virConnectGetDomainCapabilities

    ->qemuConnectGetDomainCapabilities

        ->virQEMUCapsCacheLookupDefault

            ->virQEMUCapsCacheLookup

                ->virFileCacheLookup

                    ->virFileCacheValidate

                        ->virFileCacheNewData

                            ->virQEMUCapsNewData

                                ->virQEMUCapsNewForBinaryInternal

                                    ->virQEMUCapsInitQMP

                                        ->virQEMUCapsInitQMPSingle

                                            ->virQEMUCapsInitQMPMonitor

         

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值