From nobody Sat Feb 7 06:54:20 2026 Received: from mail.thorondor.fr (unknown [82.66.128.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E63622517AC; Wed, 28 Jan 2026 19:50:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=82.66.128.71 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769629826; cv=none; b=EhelzSoxyJCDc7bwYw+o5ZRVBM6iujYPbysvxK/SVUwo86d/lYMSqSax9I5p+flJFSHL9yiyjz3lHNIXhv1g7gKrExWho0ulgZ1wCiAA6of+V3sdQ2YRhJJzH29rOJjlT58OoliuvJov03JPAky6JW1RrERWVEvWlZEypAxbgOE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769629826; c=relaxed/simple; bh=hUxEQd9B/jtT2SP/nDIPRWt0LT8qLJgWnolLkxASwnI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Nkjr2JrbjCjjU/NVyRf4JLLrmKP9dP94oGHt1g8CM+yayZHr/MrUwWakHMHhpsaeAb1ZMVmOCZyWjC7pfzpw8j5slWRS4GoxijY6DlddZLmnNRxVnFzPSH3KyKLBm4PyTUrXUdV9vKgBh4GuPGVzmTaMM0R6GI8LCkvcWy3rcQg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=thorondor.fr; spf=pass smtp.mailfrom=thorondor.fr; dkim=pass (2048-bit key) header.d=thorondor.fr header.i=@thorondor.fr header.b=s2g0wOcv; arc=none smtp.client-ip=82.66.128.71 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=thorondor.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=thorondor.fr Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=thorondor.fr header.i=@thorondor.fr header.b="s2g0wOcv" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=thorondor.fr; s=mail; t=1769629816; bh=hUxEQd9B/jtT2SP/nDIPRWt0LT8qLJgWnolLkxASwnI=; h=From:To:Cc:Subject:In-Reply-To:References; b=s2g0wOcvGWRRmhRayxytT0j5r6TZCPHCeOCqNel/rQcq9UfgsUNrQONCVCrfHdHLx M/sleT5ltuhfq9zWXJpgh1cIyKNbQl2zY6aZORrqQH37QvjIe/Oo+vmAktumDhX78o Gfeg5qZIdYutiFcH/+kirfIOe9QMhRqmQHm6cb5BnWFEL02wIrSMFZ8o00PhgtfT6W HNwwYp2GlYenwCzlFtGkVmcLqlEBKg0S0d6eDp/A6kzfrEjj1deISwAECwcvsu9iyb iKan+SqgZR5rVorwIDwDrgVo9/71VGQM4S8kO+UhGbTPb6132tCMsSiMhC55NnSI// nh2KSNDlgexUA== From: Thomas Courrege To: ashish.kalra@amd.com, corbet@lwn.net, herbert@gondor.apana.org.au, john.allen@amd.com, nikunj@amd.com, pbonzini@redhat.com, seanjc@google.com, thomas.lendacky@amd.com Cc: kvm@vger.kernel.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org, Thomas Courrege Subject: [PATCH v6 1/1] KVM: SEV: Add KVM_SEV_SNP_HV_REPORT_REQ command Date: Wed, 28 Jan 2026 20:49:56 +0100 Message-ID: <20260128194956.314678-2-thomas.courrege@thorondor.fr> In-Reply-To: <20260128194956.314678-1-thomas.courrege@thorondor.fr> References: <20260128194956.314678-1-thomas.courrege@thorondor.fr> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add support for retrieving the SEV-SNP attestation report via the SNP_HV_REPORT_REQ firmware command and expose it through a new KVM ioctl for SNP guests. Signed-off-by: Thomas Courrege Reviewed-by: Tom Lendacky --- .../virt/kvm/x86/amd-memory-encryption.rst | 28 +++++++++ arch/x86/include/uapi/asm/kvm.h | 9 +++ arch/x86/kvm/svm/sev.c | 63 +++++++++++++++++++ drivers/crypto/ccp/sev-dev.c | 1 + include/linux/psp-sev.h | 31 +++++++++ 5 files changed, 132 insertions(+) diff --git a/Documentation/virt/kvm/x86/amd-memory-encryption.rst b/Documen= tation/virt/kvm/x86/amd-memory-encryption.rst index 1ddb6a86ce7f..46fc07d9942a 100644 --- a/Documentation/virt/kvm/x86/amd-memory-encryption.rst +++ b/Documentation/virt/kvm/x86/amd-memory-encryption.rst @@ -572,6 +572,34 @@ Returns: 0 on success, -negative on error See SNP_LAUNCH_FINISH in the SEV-SNP specification [snp-fw-abi]_ for furth= er details on the input parameters in ``struct kvm_sev_snp_launch_finish``. =20 +21. KVM_SEV_SNP_HV_REPORT_REQ +----------------------------- + +The KVM_SEV_SNP_HV_REPORT_REQ command requests a hypervisor-generated +SNP guest attestation report. This report is produced by the SEV firmware +using the key selected by the caller. + +The ``key_sel`` field indicates which key the platform will use to sign the +report: + * ``0``: If VLEK is installed, sign with VLEK. Otherwise, sign with VCEK. + * ``1``: Sign with VCEK. + * ``2``: Sign with VLEK. + * Other values are reserved. + +Parameters (in): struct kvm_sev_snp_hv_report_req + +Returns: 0 on success, -negative on error + +:: + struct kvm_sev_snp_hv_report_req { + __u64 report_uaddr; + __u64 report_len; + __u8 key_sel; + __u8 pad0[7]; + __u64 pad1[4]; + }; + + Device attribute API =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 diff --git a/arch/x86/include/uapi/asm/kvm.h b/arch/x86/include/uapi/asm/kv= m.h index 7ceff6583652..464146bed784 100644 --- a/arch/x86/include/uapi/asm/kvm.h +++ b/arch/x86/include/uapi/asm/kvm.h @@ -743,6 +743,7 @@ enum sev_cmd_id { KVM_SEV_SNP_LAUNCH_START =3D 100, KVM_SEV_SNP_LAUNCH_UPDATE, KVM_SEV_SNP_LAUNCH_FINISH, + KVM_SEV_SNP_HV_REPORT_REQ, =20 KVM_SEV_NR_MAX, }; @@ -871,6 +872,14 @@ struct kvm_sev_receive_update_data { __u32 pad2; }; =20 +struct kvm_sev_snp_hv_report_req { + __u64 report_uaddr; + __u64 report_len; + __u8 key_sel; + __u8 pad0[7]; + __u64 pad1[4]; +}; + struct kvm_sev_snp_launch_start { __u64 policy; __u8 gosvw[16]; diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index f59c65abe3cf..63026d254ab1 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -2261,6 +2261,66 @@ static int snp_launch_start(struct kvm *kvm, struct = kvm_sev_cmd *argp) return rc; } =20 +static int sev_snp_hv_report_request(struct kvm *kvm, struct kvm_sev_cmd *= argp) +{ + struct kvm_sev_info *sev =3D to_kvm_sev_info(kvm); + struct sev_data_snp_msg_report_rsp *report_rsp; + struct kvm_sev_snp_hv_report_req params; + struct sev_data_snp_hv_report_req data; + size_t rsp_size =3D sizeof(*report_rsp); + void __user *u_report; + void __user *u_params; + int ret; + + if (!sev_snp_guest(kvm)) + return -ENOTTY; + + u_params =3D u64_to_user_ptr(argp->data); + if (copy_from_user(¶ms, u_params, sizeof(params))) + return -EFAULT; + + if (params.report_len < rsp_size) + return -ENOSPC; + + u_report =3D u64_to_user_ptr(params.report_uaddr); + if (!u_report) + return -EINVAL; + + report_rsp =3D snp_alloc_firmware_page(GFP_KERNEL_ACCOUNT | __GFP_ZERO); + if (!report_rsp) + return -ENOMEM; + + data.len =3D sizeof(data); + data.key_sel =3D params.key_sel; + data.gctx_addr =3D __psp_pa(sev->snp_context); + data.hv_report_paddr =3D __psp_pa(report_rsp); + data.rsvd =3D 0; + + ret =3D sev_issue_cmd(kvm, SEV_CMD_SNP_HV_REPORT_REQ, &data, + &argp->error); + if (ret) + goto e_free_rsp; + + if (!report_rsp->status) { + if (params.report_len < (rsp_size + report_rsp->report_size)) + ret =3D -ENOSPC; + else + rsp_size +=3D report_rsp->report_size; + + params.report_len =3D sizeof(*report_rsp) + report_rsp->report_size; + } + + if (copy_to_user(u_report, report_rsp, rsp_size)) + ret =3D -EFAULT; + + if (copy_to_user(u_params, ¶ms, sizeof(params))) + ret =3D -EFAULT; + +e_free_rsp: + snp_free_firmware_page(report_rsp); + return ret; +} + struct sev_gmem_populate_args { __u8 type; int sev_fd; @@ -2672,6 +2732,9 @@ int sev_mem_enc_ioctl(struct kvm *kvm, void __user *a= rgp) case KVM_SEV_SNP_LAUNCH_FINISH: r =3D snp_launch_finish(kvm, &sev_cmd); break; + case KVM_SEV_SNP_HV_REPORT_REQ: + r =3D sev_snp_hv_report_request(kvm, &sev_cmd); + break; default: r =3D -EINVAL; goto out; diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index 956ea609d0cc..5dd7c3f0d50d 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -259,6 +259,7 @@ static int sev_cmd_buffer_len(int cmd) case SEV_CMD_SNP_COMMIT: return sizeof(struct sev_data_snp_commit); case SEV_CMD_SNP_FEATURE_INFO: return sizeof(struct sev_data_snp_feature= _info); case SEV_CMD_SNP_VLEK_LOAD: return sizeof(struct sev_user_data_snp_vlek_= load); + case SEV_CMD_SNP_HV_REPORT_REQ: return sizeof(struct sev_data_snp_hv_rep= ort_req); default: return sev_tio_cmd_buffer_len(cmd); } =20 diff --git a/include/linux/psp-sev.h b/include/linux/psp-sev.h index 69ffa4b4d1fa..c651a400d124 100644 --- a/include/linux/psp-sev.h +++ b/include/linux/psp-sev.h @@ -124,6 +124,7 @@ enum sev_cmd { SEV_CMD_SNP_GCTX_CREATE =3D 0x093, SEV_CMD_SNP_GUEST_REQUEST =3D 0x094, SEV_CMD_SNP_ACTIVATE_EX =3D 0x095, + SEV_CMD_SNP_HV_REPORT_REQ =3D 0x096, SEV_CMD_SNP_LAUNCH_START =3D 0x0A0, SEV_CMD_SNP_LAUNCH_UPDATE =3D 0x0A1, SEV_CMD_SNP_LAUNCH_FINISH =3D 0x0A2, @@ -594,6 +595,36 @@ struct sev_data_attestation_report { u32 len; /* In/Out */ } __packed; =20 +/** + * struct sev_data_snp_hv_report_req - SNP_HV_REPORT_REQ command params + * + * @len: length of the command buffer in bytes + * @key_sel: Selects which key to use for generating the signature. + * @gctx_addr: System physical address of guest context page + * @hv_report_paddr: System physical address where MSG_EXPORT_RSP will be = written + */ +struct sev_data_snp_hv_report_req { + u32 len; /* In */ + u32 key_sel :2, /* In */ + rsvd :30; + u64 gctx_addr; /* In */ + u64 hv_report_paddr; /* In */ +} __packed; + +/** + * struct sev_data_snp_msg_export_rsp + * + * @status: Status : 0h: Success. 16h: Invalid parameters. + * @report_size: Size in bytes of the attestation report + * @report: attestation report + */ +struct sev_data_snp_msg_report_rsp { + u32 status; /* Out */ + u32 report_size; /* Out */ + u8 rsvd[24]; + u8 report[]; +} __packed; + /** * struct sev_data_snp_download_firmware - SNP_DOWNLOAD_FIRMWARE command p= arams * --=20 2.52.0