From nobody Mon Sep 15 13:07:11 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8EABC46467 for ; Wed, 11 Jan 2023 19:40:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233923AbjAKTk0 (ORCPT ); Wed, 11 Jan 2023 14:40:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234294AbjAKTkH (ORCPT ); Wed, 11 Jan 2023 14:40:07 -0500 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D578E0A0 for ; Wed, 11 Jan 2023 11:40:06 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id v23-20020aa78097000000b005748c087db1so7287287pff.2 for ; Wed, 11 Jan 2023 11:40:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Fm659R4aHmYp8UY/bKL5DBAg2H3b+nBfeQZtPLqQT3s=; b=VrOQ6IsjrT/z4m7j9ySc7QBAYgPbFPrz/78YbUxYru7NKMXhS6ZOVLzXprbjfJgPF7 gbvp8bdao7rpuXPbXO1NlYZuDZRD5jGNk9GYl3Rr+Xbef9CUig+4v3vJpX68/fTrxeff w1zdx64u41Uhe0YTCRoQoVzJV/m9xktzTtnaBL0QntOWtm8UhdWGY6trQ0ghTRJl0Ojt XrorIDigDdxE6lQZunOJ6qcQYQtfmtL4F7ADkIBLYsu558AeN9dWmlunjxq/goPS3EFm XlrF8a0crL3/qecAdUWNbkB6fe4udrs/rEcVEpW26Um0iXdZ3QIy2wCcC2P4oKWNK6n5 3UrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Fm659R4aHmYp8UY/bKL5DBAg2H3b+nBfeQZtPLqQT3s=; b=nnh5DzRErX8gUUHsb4mbuiDvfAUFGW+khhpnwFU+YydrAsVBPToHuEwUEd5gvncIzM +db3b5XhEZ7YOyPHUV0qY9CXyegjuQEv6vsq8UKaxUrTNbdPyhfgKOfqrSs7cNAeM1Mj hJzRMRSiifv9hNydeuXgf0wtagWv2XeWCDppnUmpPD+yEI5uljxt8N9oOjOm9CTeZLar 2BDHEcH/NeO89qdb1OjPBv1yi/et+CEJqqgLG3wHhmH9XBppPOorW7UokZCM1Nx1StrY gUHAQ8R60LSrWrlqSa+q/F/hw2VjO7hD9/lBiZnBl9vc2xASTpbbQ74+qUYQW7DFVui0 rqTg== X-Gm-Message-State: AFqh2kolpwj4eU3VOvpFDwb9xP1RfzoFaLh8tXenAr1jxn75hlOCvoeA opVoiwp3LmAoPdztzlBRo8AGl5UvYgvPay/GCUK+5b+FMb8QeIqz+I7w53Ag4MblY35lCV83zHr 1CLWzlxZZJ+0rNDHD8axbzs+WjBZ5brF8RktHrokFBOCDdHXUlc358QMTIjPd2GDwAtUQOyCygP S4yfkizbQ= X-Google-Smtp-Source: AMrXdXuXbn44yAFEChu68mSBZB6GSpj6WpZ1aa+Ejodr2J8xvUi0PV/EPOs79B7Gc5LB0rWqGgfCiepgEv5sRGSQYg== X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2ee6]) (user=dionnaglaze job=sendgmr) by 2002:a17:90a:2a4a:b0:220:1f03:129b with SMTP id d10-20020a17090a2a4a00b002201f03129bmr73025pjg.0.1673466004413; Wed, 11 Jan 2023 11:40:04 -0800 (PST) Date: Wed, 11 Jan 2023 19:39:55 +0000 In-Reply-To: <20230111194001.1947849-1-dionnaglaze@google.com> Mime-Version: 1.0 References: <20230111194001.1947849-1-dionnaglaze@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20230111194001.1947849-2-dionnaglaze@google.com> Subject: [PATCH v11 1/7] crypto: ccp - Name -1 return value as SEV_RET_NO_FW_CALL From: Dionna Glaze To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Peter Gonda , Thomas Lendacky , Paolo Bonzini , Joerg Roedel , Ingo Molnar , Andy Lutomirsky , John Allen , Herbert Xu , "David S. Miller" , Borislav Petkov , Dionna Glaze Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Peter Gonda The PSP can return a "firmware error" code of -1 in circumstances where the PSP is not actually called. To make this protocol unambiguous, the value is named SEV_RET_NO_FW_CALL. Cc: Thomas Lendacky Cc: Paolo Bonzini Cc: Joerg Roedel Cc: Ingo Molnar Cc: Andy Lutomirsky Cc: John Allen Cc: Herbert Xu Cc: "David S. Miller" Cc: Borislav Petkov Signed-off-by: Peter Gonda Signed-off-by: Dionna Glaze --- Documentation/virt/coco/sev-guest.rst | 2 +- drivers/crypto/ccp/sev-dev.c | 22 ++++++++++++++-------- include/uapi/linux/psp-sev.h | 7 +++++++ 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/Documentation/virt/coco/sev-guest.rst b/Documentation/virt/coc= o/sev-guest.rst index bf593e88cfd9..e76393e389eb 100644 --- a/Documentation/virt/coco/sev-guest.rst +++ b/Documentation/virt/coco/sev-guest.rst @@ -41,7 +41,7 @@ The guest ioctl should be issued on a file descriptor of = the /dev/sev-guest devi The ioctl accepts struct snp_user_guest_request. The input and output stru= cture is specified through the req_data and resp_data field respectively. If the io= ctl fails to execute due to a firmware error, then fw_err code will be set otherwise= the -fw_err will be set to 0x00000000000000ff. +fw_err will be set to 0x00000000ffffffff, i.e., the lower 32-bits are -1. =20 The firmware checks that the message sequence counter is one greater than the guests message sequence counter. If guest driver fails to increment me= ssage diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index 06fc7156c04f..ac205f78a595 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -440,12 +440,19 @@ static int __sev_init_ex_locked(int *error) return __sev_do_cmd_locked(SEV_CMD_INIT_EX, &data, error); } =20 +static inline int __sev_do_init_locked(int *psp_ret) +{ + if (sev_init_ex_buffer) + return __sev_init_ex_locked(psp_ret); + else + return __sev_init_locked(psp_ret); +} + static int __sev_platform_init_locked(int *error) { struct psp_device *psp =3D psp_master; struct sev_device *sev; - int rc =3D 0, psp_ret =3D -1; - int (*init_function)(int *error); + int rc =3D 0, psp_ret =3D SEV_RET_NO_FW_CALL; =20 if (!psp || !psp->sev_data) return -ENODEV; @@ -456,15 +463,12 @@ static int __sev_platform_init_locked(int *error) return 0; =20 if (sev_init_ex_buffer) { - init_function =3D __sev_init_ex_locked; rc =3D sev_read_init_ex_file(); if (rc) return rc; - } else { - init_function =3D __sev_init_locked; } =20 - rc =3D init_function(&psp_ret); + rc =3D __sev_do_init_locked(&psp_ret); if (rc && psp_ret =3D=3D SEV_RET_SECURE_DATA_INVALID) { /* * Initialization command returned an integrity check failure @@ -473,9 +477,11 @@ static int __sev_platform_init_locked(int *error) * initialization function should succeed by replacing the state * with a reset state. */ - dev_err(sev->dev, "SEV: retrying INIT command because of SECURE_DATA_INV= ALID error. Retrying once to reset PSP SEV state."); - rc =3D init_function(&psp_ret); + dev_err(sev->dev, +"SEV: retrying INIT command because of SECURE_DATA_INVALID error. Retrying= once to reset PSP SEV state."); + rc =3D __sev_do_init_locked(&psp_ret); } + if (error) *error =3D psp_ret; =20 diff --git a/include/uapi/linux/psp-sev.h b/include/uapi/linux/psp-sev.h index 91b4c63d5cbf..e8cfb8bde0d7 100644 --- a/include/uapi/linux/psp-sev.h +++ b/include/uapi/linux/psp-sev.h @@ -36,6 +36,13 @@ enum { * SEV Firmware status code */ typedef enum { + /* + * This error code is not in the SEV spec but is added to convey that + * there was an error that prevented the SEV Firmware from being called. + * The SEV API error codes are 16 bits, so the -1 value will not overlap + * with possible values from the specification. + */ + SEV_RET_NO_FW_CALL =3D -1, SEV_RET_SUCCESS =3D 0, SEV_RET_INVALID_PLATFORM_STATE, SEV_RET_INVALID_GUEST_STATE, --=20 2.39.0.314.g84b9a713c41-goog From nobody Mon Sep 15 13:07:11 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7AC43C46467 for ; Wed, 11 Jan 2023 19:40:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234376AbjAKTkh (ORCPT ); Wed, 11 Jan 2023 14:40:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234496AbjAKTkI (ORCPT ); Wed, 11 Jan 2023 14:40:08 -0500 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D62FA14037 for ; Wed, 11 Jan 2023 11:40:06 -0800 (PST) Received: by mail-pg1-x549.google.com with SMTP id y37-20020a634b25000000b004b1d90ea947so5023497pga.15 for ; Wed, 11 Jan 2023 11:40:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=NgJJjf3XhaPlMIkedvk8DADSWPbDqjPvpDq99Cffqu0=; b=ha/GpuIffF2aT3mhbf29pv+Ym+Was4HCFTAuAmQDlgBVlIamCt+tSl9DvjtGywyInX Xb7HOyujW5KQA0LiKUpE3Iclpq4JrPXm9wUBiPFO/TPrUUhX4CrfaJP5VwSyUK1pT84N 5InKtJrL3tObd50tUyGbOnViU/aPxwawhw2hksh8q3WK+drkIdqAKFXkhYA/MuN4gQV7 nVkVwgklJHLvHdb5x9yEEk2GhG74Kxpbj3w8aaH+mIGY43iaygfq4uEOAswtvZToC59G 4p5wXBypQJ1jxHnkPn81IATCKIH/cFPfUAeJ3Sai/MV73D4BAGIKXyBA+xt7LFN+Fmod oCbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NgJJjf3XhaPlMIkedvk8DADSWPbDqjPvpDq99Cffqu0=; b=FRvEa8vJiySm6WdEjAdXt1O7g3eJxoMrN6zDaI90JGCMyh1/tHTMBK6vJnqohsdspE Y0IIvb5hb0L5qAt2rIfIUS6ibSZG7XtUAAqttozB/xnx+EnRKCQY0W2jyOCwEX7eb7Gy fT+dvyjwf4dzrt4/GySoZHVATvXGl3uJLIagtGOQuziImLXYJqkwq8iMEYdhU6a+FPqY nDRNx5qb3KL9aqSgvorR7sP6sb5SxeaV428mXcTiRlCVQ64ioT9b3HmjUPUT+IrNRMCE WLTMlHTRD0Pi0dTgk78caQv7HRnKNCjHsBe5rzKndOtX2FYmFO0pnQRcGe3Gi7XMHuo/ O1sg== X-Gm-Message-State: AFqh2kp8O9TEKQocILmIMgXZm15Bxdh/ch/FVrTX+luFewscq4ceDyDE QYGyvxWi4F/5O2QA+FM73YT0RgzVMTNi37ijSgG/AoXa3RlqchncPtXmgBbgkWP37jo76VD5K+g XWxr0GYnv+HtcDmGwys6TeZCHv6rgLOtBduwg7XITxF6z8ZRB8O1AGjWCM/GwlK3ZwqwsxMKhif hyWNqyY+0= X-Google-Smtp-Source: AMrXdXuikOzUTMv9Br9/QRekPPGn/a7pAzNRpV2qQ0EkhLBBv4sw5QYcprpz5S6EiWS+MtWsGfqvCec9a18YSlenjw== X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2ee6]) (user=dionnaglaze job=sendgmr) by 2002:a17:90a:8b0b:b0:219:5a12:e1eb with SMTP id y11-20020a17090a8b0b00b002195a12e1ebmr7312208pjn.88.1673466006301; Wed, 11 Jan 2023 11:40:06 -0800 (PST) Date: Wed, 11 Jan 2023 19:39:56 +0000 In-Reply-To: <20230111194001.1947849-1-dionnaglaze@google.com> Mime-Version: 1.0 References: <20230111194001.1947849-1-dionnaglaze@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20230111194001.1947849-3-dionnaglaze@google.com> Subject: [PATCH v11 2/7] x86/sev: Change snp_guest_issue_request's fw_err From: Dionna Glaze To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Dionna Glaze , Tom Lendacky , Paolo Bonzini , Joerg Roedel , Peter Gonda , Thomas Gleixner , Dave Hansen , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Venu Busireddy , Michael Roth , "Kirill A. Shutemov" , Michael Sterritt Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The GHCB specification declares that the firmware error value for a guest request will be stored in the lower 32 bits of EXIT_INFO_2. The upper 32 bits are for the VMM's own error code. The fw_err argument is thus a misnomer, and callers will need access to all 64 bits. The type of unsigned long also causes problems, since sw_exit_info2 is u64 (unsigned long long) vs the argument's unsigned long*. A temporary typedef is introduced for the err argument so it can be changed in a later patch more cleanly. The firmware might not even be called, so the call is bookended with the no firmware call error and clearing the error. Cc: Tom Lendacky Cc: Paolo Bonzini Cc: Joerg Roedel Cc: Peter Gonda Cc: Thomas Gleixner Cc: Dave Hansen Cc: Ingo Molnar Cc: Borislav Petkov Cc: "H. Peter Anvin" Cc: Venu Busireddy Cc: Michael Roth Cc: "Kirill A. Shutemov" Cc: Michael Sterritt Fixes: d5af44dde546 ("x86/sev: Provide support for SNP guest request NAEs") Reviewed-by: Tom Lendacky Reviewed-by: Borislav Petkov Reviewed-by: Peter Gonda Signed-off-by: Dionna Glaze --- arch/x86/include/asm/sev.h | 10 ++++++++-- arch/x86/kernel/sev.c | 10 ++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index ebc271bb6d8e..5b03ba18fee7 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -133,6 +133,12 @@ struct snp_secrets_page_layout { u8 rsvd3[3840]; } __packed; =20 +/* + * Use a type alias temporarily to cleanly change the snp_issue_guest_requ= est + * signature cleanly over multiple patches. + */ +typedef unsigned long sev_guestreq_err_t; + #ifdef CONFIG_AMD_MEM_ENCRYPT extern struct static_key_false sev_es_enable_key; extern void __sev_es_ist_enter(struct pt_regs *regs); @@ -196,7 +202,7 @@ void snp_set_memory_private(unsigned long vaddr, unsign= ed int npages); void snp_set_wakeup_secondary_cpu(void); bool snp_init(struct boot_params *bp); void __init __noreturn snp_abort(void); -int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, uns= igned long *fw_err); +int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, sev= _guestreq_err_t *exitinfo2); #else static inline void sev_es_ist_enter(struct pt_regs *regs) { } static inline void sev_es_ist_exit(void) { } @@ -217,7 +223,7 @@ static inline void snp_set_wakeup_secondary_cpu(void) {= } static inline bool snp_init(struct boot_params *bp) { return false; } static inline void snp_abort(void) { } static inline int snp_issue_guest_request(u64 exit_code, struct snp_req_da= ta *input, - unsigned long *fw_err) + sev_guestreq_err_t *exitinfo2) { return -ENOTTY; } diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index 679026a640ef..d1a6092b1e03 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -22,6 +22,7 @@ #include #include #include +#include =20 #include #include @@ -2175,7 +2176,7 @@ static int __init init_sev_config(char *str) } __setup("sev=3D", init_sev_config); =20 -int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, uns= igned long *fw_err) +int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, sev= _guestreq_err_t *exitinfo2) { struct ghcb_state state; struct es_em_ctxt ctxt; @@ -2186,9 +2187,11 @@ int snp_issue_guest_request(u64 exit_code, struct sn= p_req_data *input, unsigned if (!cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) return -ENODEV; =20 - if (!fw_err) + if (!exitinfo2) return -EINVAL; =20 + *exitinfo2 =3D SEV_RET_NO_FW_CALL; + /* * __sev_get_ghcb() needs to run with IRQs disabled because it is using * a per-CPU GHCB. @@ -2212,14 +2215,13 @@ int snp_issue_guest_request(u64 exit_code, struct s= np_req_data *input, unsigned if (ret) goto e_put; =20 + *exitinfo2 =3D ghcb->save.sw_exit_info_2; if (ghcb->save.sw_exit_info_2) { /* Number of expected pages are returned in RBX */ if (exit_code =3D=3D SVM_VMGEXIT_EXT_GUEST_REQUEST && ghcb->save.sw_exit_info_2 =3D=3D SNP_GUEST_REQ_INVALID_LEN) input->data_npages =3D ghcb_get_rbx(ghcb); =20 - *fw_err =3D ghcb->save.sw_exit_info_2; - ret =3D -EIO; } =20 --=20 2.39.0.314.g84b9a713c41-goog From nobody Mon Sep 15 13:07:11 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 398F3C5479D for ; Wed, 11 Jan 2023 19:40:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235127AbjAKTky (ORCPT ); Wed, 11 Jan 2023 14:40:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234200AbjAKTkK (ORCPT ); Wed, 11 Jan 2023 14:40:10 -0500 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E24C39F96 for ; Wed, 11 Jan 2023 11:40:08 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id b196-20020a621bcd000000b0058a63dc105eso3482114pfb.6 for ; Wed, 11 Jan 2023 11:40:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=t8W4FH7mFIpVRdnY5skujk6nCPAJ4sesqHc9zDdEW0s=; b=IF6bG7y6P+/fyh2juFdCBqZAZykQrxC8/Vm0GE5HmM6OxW12uKLT/dtRZAWDhMxB+d dkiawoVtjIwhjo34pV/6UTuHh0u2ClKSRJnWy1XwXXBJcrHGAIp0OeWebvNjf+1+f+0i 7ILSBx7UCXoHIsBP2UMpqG3sBq7p/t/VdawaoUWPYzAnd0DJIeAS5kmj561hIyiu1Uob I5gM9i5f5bh+uesfHys7f9yRa6RlGAFF1A4PTwCEXb5xzpkV9vWbtWfCv9t6B1+drSBR WG3GNCUByYQBO6Jc9AQvYimY2JAtUvyfWo2IDqPU0bFEDaV78SJQD+g8FtStiP67tMvk Vx/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=t8W4FH7mFIpVRdnY5skujk6nCPAJ4sesqHc9zDdEW0s=; b=IIO9DAjYYmZ9KcoqlWFwlWNWTTOaGZZEOMcxOp4TgKYCwKqwuT4EY1gRlu7Mgggr77 C2oszkHODLRZcL71+MrBp6py3nntPp/FxMo/xbVxwHCt9e0D+wK+bpyh0FV4zL7grjs3 6rOZJN+Ubp7CIsy0gMKGEoNM5Tfi0khDuZpGcu1yZCvijLnMhRclzZHN/1FsTKkU7qUu IRaF5nOLBlLGdGJvVVyWApYp8JchL6d2EpQur6EcGMdZCIiW0G0ewaP9w86rj5vDkwsZ /scuYwlHtEbUp5QZkm/zxA/gWIqzIowQbrwp76P38z0CNRb2+8vqxI170zkGuE6PYCfJ yDyg== X-Gm-Message-State: AFqh2krj+iul/5kte+2MXibgJAIkZJsConTF7n9WuxpfsStxQqVA2dUw 7hRjFRao+Abcrt9cefX/KGAgzWVkJ4I3tkJGll2WAAq3zgNr8IUuTOkdHnHXNLk37r3D6gt9s+L y0vK1H0LvcaETK7oY4TP+zwv/PRVtZn6LwFRIS32OPc0exsMXa6stwfYD0l53wlM6CaLixsE+Hk s02H5ytOk= X-Google-Smtp-Source: AMrXdXullgIk5Od9JoOE6RkbMRJw+bgqLxHKZ1NwCMe5CScZ7ktTdffp1urqcFQ6zinZNL53fnPSTQkPGlsBkNkRxg== X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2ee6]) (user=dionnaglaze job=sendgmr) by 2002:a17:902:7c02:b0:192:fb0a:35aa with SMTP id x2-20020a1709027c0200b00192fb0a35aamr1611751pll.78.1673466007663; Wed, 11 Jan 2023 11:40:07 -0800 (PST) Date: Wed, 11 Jan 2023 19:39:57 +0000 In-Reply-To: <20230111194001.1947849-1-dionnaglaze@google.com> Mime-Version: 1.0 References: <20230111194001.1947849-1-dionnaglaze@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20230111194001.1947849-4-dionnaglaze@google.com> Subject: [PATCH v11 3/7] virt: sev-guest: Remove err in handle_guest_request From: Dionna Glaze To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Dionna Glaze , Tom Lendacky , Paolo Bonzini , Joerg Roedel , Peter Gonda , Thomas Gleixner , Dave Hansen , Borislav Petkov , Haowen Bai , Liam Merwick , Yang Yingliang Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The err variable may not be set in the call to snp_issue_guest_request, yet it is unconditionally written back to fw_err if fw_err is non-null. This is undefined behavior, and currently returns uninitialized kernel stack memory to user space. The fw_err argument is better to just pass through to snp_issue_guest_request, so that's done by passing along the ioctl argument. This removes the need for an argument to handle_guest_request. Instead of using the fw_err field of the argument, which is a bit of a misnomer, instead change to exitinfo2. The exitinfo2 field type is a temporary typedef that will be removed. Cc: Tom Lendacky Cc: Paolo Bonzini Cc: Joerg Roedel Cc: Peter Gonda Cc: Thomas Gleixner Cc: Dave Hansen Cc: Borislav Petkov Cc: Haowen Bai Cc: Liam Merwick Cc: Yang Yingliang Fixes: fce96cf04430 ("virt: Add SEV-SNP guest driver") Reviewed-by: Tom Lendacky Reviewed-by: Borislav Petkov Reviewed-by: Peter Gonda Signed-off-by: Dionna Glaze --- drivers/virt/coco/sev-guest/sev-guest.c | 43 ++++++++++++------------- include/uapi/linux/sev-guest.h | 12 +++++-- 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/se= v-guest/sev-guest.c index 4ec4174e05a3..e2fcb5215630 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -318,11 +318,11 @@ static int enc_payload(struct snp_guest_dev *snp_dev,= u64 seqno, int version, u8 return __enc_payload(snp_dev, req, payload, sz); } =20 -static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_co= de, int msg_ver, +static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_co= de, + struct snp_guest_request_ioctl *arg, u8 type, void *req_buf, size_t req_sz, void *resp_buf, - u32 resp_sz, __u64 *fw_err) + u32 resp_sz) { - unsigned long err; u64 seqno; int rc; =20 @@ -334,7 +334,8 @@ static int handle_guest_request(struct snp_guest_dev *s= np_dev, u64 exit_code, in memset(snp_dev->response, 0, sizeof(struct snp_guest_msg)); =20 /* Encrypt the userspace provided payload */ - rc =3D enc_payload(snp_dev, seqno, msg_ver, type, req_buf, req_sz); + rc =3D enc_payload(snp_dev, seqno, arg->msg_version, type, req_buf, + req_sz); if (rc) return rc; =20 @@ -344,7 +345,8 @@ static int handle_guest_request(struct snp_guest_dev *s= np_dev, u64 exit_code, in * sequence number must be incremented or the VMPCK must be deleted to * prevent reuse of the IV. */ - rc =3D snp_issue_guest_request(exit_code, &snp_dev->input, &err); + rc =3D snp_issue_guest_request(exit_code, &snp_dev->input, + &arg->exitinfo2); =20 /* * If the extended guest request fails due to having too small of a @@ -366,24 +368,22 @@ static int handle_guest_request(struct snp_guest_dev = *snp_dev, u64 exit_code, in * of the VMPCK and the error code being propagated back to the * user as an ioctl() return code. */ - rc =3D snp_issue_guest_request(exit_code, &snp_dev->input, &err); + rc =3D snp_issue_guest_request(exit_code, &snp_dev->input, + &arg->exitinfo2); =20 /* * Override the error to inform callers the given extended * request buffer size was too small and give the caller the * required buffer size. */ - err =3D SNP_GUEST_REQ_INVALID_LEN; + arg->exitinfo2 =3D SNP_GUEST_REQ_INVALID_LEN; snp_dev->input.data_npages =3D certs_npages; } =20 - if (fw_err) - *fw_err =3D err; - if (rc) { dev_alert(snp_dev->dev, - "Detected error from ASP request. rc: %d, fw_err: %llu\n", - rc, *fw_err); + "Detected error from ASP request. rc: %d, exitinfo2: %llu\n", + rc, (u64)arg->exitinfo2); goto disable_vmpck; } =20 @@ -430,9 +430,9 @@ static int get_report(struct snp_guest_dev *snp_dev, st= ruct snp_guest_request_io if (!resp) return -ENOMEM; =20 - rc =3D handle_guest_request(snp_dev, SVM_VMGEXIT_GUEST_REQUEST, arg->msg_= version, + rc =3D handle_guest_request(snp_dev, SVM_VMGEXIT_GUEST_REQUEST, arg, SNP_MSG_REPORT_REQ, &req, sizeof(req), resp->data, - resp_len, &arg->fw_err); + resp_len); if (rc) goto e_free; =20 @@ -470,9 +470,8 @@ static int get_derived_key(struct snp_guest_dev *snp_de= v, struct snp_guest_reque if (copy_from_user(&req, (void __user *)arg->req_data, sizeof(req))) return -EFAULT; =20 - rc =3D handle_guest_request(snp_dev, SVM_VMGEXIT_GUEST_REQUEST, arg->msg_= version, - SNP_MSG_KEY_REQ, &req, sizeof(req), buf, resp_len, - &arg->fw_err); + rc =3D handle_guest_request(snp_dev, SVM_VMGEXIT_GUEST_REQUEST, arg, + SNP_MSG_KEY_REQ, &req, sizeof(req), buf, resp_len); if (rc) return rc; =20 @@ -532,12 +531,12 @@ static int get_ext_report(struct snp_guest_dev *snp_d= ev, struct snp_guest_reques return -ENOMEM; =20 snp_dev->input.data_npages =3D npages; - ret =3D handle_guest_request(snp_dev, SVM_VMGEXIT_EXT_GUEST_REQUEST, arg-= >msg_version, + ret =3D handle_guest_request(snp_dev, SVM_VMGEXIT_EXT_GUEST_REQUEST, arg, SNP_MSG_REPORT_REQ, &req.data, - sizeof(req.data), resp->data, resp_len, &arg->fw_err); + sizeof(req.data), resp->data, resp_len); =20 /* If certs length is invalid then copy the returned length */ - if (arg->fw_err =3D=3D SNP_GUEST_REQ_INVALID_LEN) { + if (arg->exitinfo2 =3D=3D SNP_GUEST_REQ_INVALID_LEN) { req.certs_len =3D snp_dev->input.data_npages << PAGE_SHIFT; =20 if (copy_to_user((void __user *)arg->req_data, &req, sizeof(req))) @@ -572,7 +571,7 @@ static long snp_guest_ioctl(struct file *file, unsigned= int ioctl, unsigned long if (copy_from_user(&input, argp, sizeof(input))) return -EFAULT; =20 - input.fw_err =3D 0xff; + input.exitinfo2 =3D 0xff; =20 /* Message version must be non-zero */ if (!input.msg_version) @@ -603,7 +602,7 @@ static long snp_guest_ioctl(struct file *file, unsigned= int ioctl, unsigned long =20 mutex_unlock(&snp_cmd_mutex); =20 - if (input.fw_err && copy_to_user(argp, &input, sizeof(input))) + if (input.exitinfo2 && copy_to_user(argp, &input, sizeof(input))) return -EFAULT; =20 return ret; diff --git a/include/uapi/linux/sev-guest.h b/include/uapi/linux/sev-guest.h index 256aaeff7e65..52e994b68d90 100644 --- a/include/uapi/linux/sev-guest.h +++ b/include/uapi/linux/sev-guest.h @@ -52,8 +52,16 @@ struct snp_guest_request_ioctl { __u64 req_data; __u64 resp_data; =20 - /* firmware error code on failure (see psp-sev.h) */ - __u64 fw_err; + /* bits[63:32]: VMM error code, bits[31:0] firmware error code (se= e psp-sev.h) */ + + union { + __u64 fw_err; /* Name deprecated in favor of others */ + sev_guestreq_err_t exitinfo2; + struct { + __u32 fw_error; + __u32 vmm_error; + }; + }; }; =20 struct snp_ext_report_req { --=20 2.39.0.314.g84b9a713c41-goog From nobody Mon Sep 15 13:07:11 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 966E0C5479D for ; Wed, 11 Jan 2023 19:41:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235017AbjAKTlH (ORCPT ); Wed, 11 Jan 2023 14:41:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235045AbjAKTkT (ORCPT ); Wed, 11 Jan 2023 14:40:19 -0500 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21B06C21 for ; Wed, 11 Jan 2023 11:40:10 -0800 (PST) Received: by mail-pj1-x104a.google.com with SMTP id lk5-20020a17090b33c500b00228cb369d7aso4147951pjb.5 for ; Wed, 11 Jan 2023 11:40:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=CyDQzH8B4WJdBMW81eQkpbu/YWlEf9SB9vsrKC6q4xQ=; b=qPbA8oIAcRy5vJzj3QtgCHMJPGGHNJVazVkddYaNjg3idQ4ieHDf9OMfXNBTgvEMnZ HZa0pc4hmfv2LmhCdZZvDKBBc5eDvKA1ztKxz40+FElmtEiA1Ki1yEsc7LxSFqTaHzYx yZNtrZnJ4WOeWulIfMmACopQ/VZ4KfkNaHSI0TYs+gpZ5n2od3wXJAOR7ZMoqCG8keyA AJ+TdxZOGCNBpiRsGZUttVALfXVnESnme0WsLJ2ezL8mZJBDncYOnti7bc6tyhvf6O0f bbkF+iSWCMHekaO30et+SUkWfk7YLvEnSsJUCx6fcLvgkn0XPZDQzDLxpRtKyI+NHKd8 imIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=CyDQzH8B4WJdBMW81eQkpbu/YWlEf9SB9vsrKC6q4xQ=; b=NXqOd8PoUOiNuQfmropCGJ3EYu2CXvAwqiIY4aJe3PO1bHtQqDmxGm4yRbAw/abaxU 1sd6ujE9QYAdn6s3guDh8pkU0uPXfX1ZIEZ8i64oBuJ+sFUZT3gsUkeNu88NKS9V7vm1 luOtNDLluN8UiuHSCINX4oZqzn2LrDY5HEJ2z/gpgTNRdOaAVG8B79aZ/Oa+OjSEW823 1lk8eHGVe5sNUvJM7qvK9QhigCxwqtr131p6/cUO1AwkvWsV4YiYZLwXSpuB0HRevBet SChDl4DXPFJLQjqCADCqioTNq2yheatlRj26vwo+OkLXAz/EBpONId3vE6HN8TYZ3rr0 fXuw== X-Gm-Message-State: AFqh2krzA/tqvxTxVRaYzoV6Wd8GbfE0UpYxBuiw6qD7UCow3IYJrsys 1hewMftK9uUGJ41p8tuB66wZlnbqASVGYVF4fodM0TH1wwSV0joSlDn9kwx8VSyTECYrnmUfqog 30d7/PZPEx5Djdk0RznhaXbdZVXF2KpDxU5Fv8mq5EPIBd10svVyhGJWimiuFpfl2Nl0fo4dtzF WiTdUdVxc= X-Google-Smtp-Source: AMrXdXvbY9VNIj2T2E710zA7GJLFvt3spPkxUpEpDdRT1wLK6CNm/+1GPi0rf2FCasQXURZqssqPG2KprH9cqeJXMA== X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2ee6]) (user=dionnaglaze job=sendgmr) by 2002:a62:3081:0:b0:562:86a3:12fc with SMTP id w123-20020a623081000000b0056286a312fcmr5420493pfw.8.1673466009438; Wed, 11 Jan 2023 11:40:09 -0800 (PST) Date: Wed, 11 Jan 2023 19:39:58 +0000 In-Reply-To: <20230111194001.1947849-1-dionnaglaze@google.com> Mime-Version: 1.0 References: <20230111194001.1947849-1-dionnaglaze@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20230111194001.1947849-5-dionnaglaze@google.com> Subject: [PATCH v11 4/7] virt: sev-guest: interpret VMM errors from guest request From: Dionna Glaze To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Dionna Glaze , Tom Lendacky , Peter Gonda , Borislav Petkov , Tom Lendacky , Liam Merwick , Yang Yingliang , Haowen Bai Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The GHCB specification states that the upper 32 bits of exitinfo2 are for the VMM's error codes. The sev-guest ABI has already locked in that the fw_err status of the input will be 64 bits, and that BIT_ULL(32) means that the extended guest request's data buffer was too small. Add BIT_ULL(33) for "host refused the request for throttling reasons". The driver interprets the upper 32 bits of exitinfo2 for the user anyway in case the request gets throttled. For safety, since the encryption algorithm in GHCBv2 is AES_GCM, control must remain in the kernel to complete the request with the current sequence number. Returning without finishing the request allows the the guest to make another request but with different message contents. This is IV reuse, and breaks cryptographic protections. When throttled, the driver will reschedule itself and then try again after sleeping half its ratelimit time to avoid a big wait queue. The ioctl may block indefinitely, but that has always been the case when deferring these requests to the host. Cc: Tom Lendacky Cc: Peter Gonda Cc: Borislav Petkov Cc: Tom Lendacky Cc: Liam Merwick Cc: Yang Yingliang Cc: Haowen Bai Reviewed-by: Tom Lendacky Reviewed-by: Peter Gonda Signed-off-by: Dionna Glaze --- Documentation/virt/coco/sev-guest.rst | 21 +++++++++----- drivers/virt/coco/sev-guest/sev-guest.c | 37 +++++++++++++++++++++++-- include/uapi/linux/sev-guest.h | 7 +++++ 3 files changed, 55 insertions(+), 10 deletions(-) diff --git a/Documentation/virt/coco/sev-guest.rst b/Documentation/virt/coc= o/sev-guest.rst index e76393e389eb..fd8bf833f1cd 100644 --- a/Documentation/virt/coco/sev-guest.rst +++ b/Documentation/virt/coco/sev-guest.rst @@ -37,11 +37,12 @@ along with a description: the return value. General error numbers (-ENOMEM, -EINVAL) are not detailed, but errors with specific meanings are. =20 -The guest ioctl should be issued on a file descriptor of the /dev/sev-gues= t device. -The ioctl accepts struct snp_user_guest_request. The input and output stru= cture is -specified through the req_data and resp_data field respectively. If the io= ctl fails -to execute due to a firmware error, then fw_err code will be set otherwise= the -fw_err will be set to 0x00000000ffffffff, i.e., the lower 32-bits are -1. +The guest ioctl should be issued on a file descriptor of the +/dev/sev-guest device. The ioctl accepts struct +snp_user_guest_request. The input and output structure is specified +through the req_data and resp_data field respectively. If the ioctl +fails to execute due to a firmware error, then the fw_error code will +be set, otherwise fw_error will be set to -1. =20 The firmware checks that the message sequence counter is one greater than the guests message sequence counter. If guest driver fails to increment me= ssage @@ -57,8 +58,14 @@ counter (e.g. counter overflow), then -EIO will be retur= ned. __u64 req_data; __u64 resp_data; =20 - /* firmware error code on failure (see psp-sev.h) */ - __u64 fw_err; + /* bits[63:32]: VMM error code, bits[31:0] firmware error code (see psp-= sev.h) */ + union { + __u64 exitinfo2; + struct { + __u32 fw_error; + __u32 vmm_error; + }; + }; }; =20 2.1 SNP_GET_REPORT diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/se= v-guest/sev-guest.c index e2fcb5215630..04c30e4da642 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -48,12 +49,22 @@ struct snp_guest_dev { struct snp_req_data input; u32 *os_area_msg_seqno; u8 *vmpck; + + struct ratelimit_state rs; }; =20 static u32 vmpck_id; module_param(vmpck_id, uint, 0444); MODULE_PARM_DESC(vmpck_id, "The VMPCK ID to use when communicating with th= e PSP."); =20 +static int rate_s =3D 1; +module_param(rate_s, int, 0444); +MODULE_PARM_DESC(rate_s, "The rate limit interval in seconds to limit requ= ests to."); + +static int rate_burst =3D 2; +module_param(rate_burst, int, 0444); +MODULE_PARM_DESC(rate_burst, "The rate limit burst amount to limit request= s to."); + /* Mutex to serialize the shared buffer access and command handling. */ static DEFINE_MUTEX(snp_cmd_mutex); =20 @@ -339,6 +350,16 @@ static int handle_guest_request(struct snp_guest_dev *= snp_dev, u64 exit_code, if (rc) return rc; =20 +retry: + /* + * Rate limit commands internally since the host can also throttle, and + * the guest shouldn't create a tight request spin that could end up + * getting this VM throttled more heavily. + */ + if (!__ratelimit(&snp_dev->rs)) { + schedule_timeout_interruptible((rate_s * HZ) / 2); + goto retry; + } /* * Call firmware to process the request. In this function the encrypted * message enters shared memory with the host. So after this call the @@ -348,6 +369,14 @@ static int handle_guest_request(struct snp_guest_dev *= snp_dev, u64 exit_code, rc =3D snp_issue_guest_request(exit_code, &snp_dev->input, &arg->exitinfo2); =20 + /* + * The host may return EBUSY if the request has been throttled. + * We retry in the driver to avoid returning and reusing the message + * sequence number on a different message. + */ + if (arg->vmm_error =3D=3D SNP_GUEST_VMM_ERR_BUSY) + goto retry; + /* * If the extended guest request fails due to having too small of a * certificate data buffer, retry the same guest request without the @@ -355,7 +384,7 @@ static int handle_guest_request(struct snp_guest_dev *s= np_dev, u64 exit_code, * and thus avoid IV reuse. */ if (exit_code =3D=3D SVM_VMGEXIT_EXT_GUEST_REQUEST && - err =3D=3D SNP_GUEST_REQ_INVALID_LEN) { + arg->vmm_error =3D=3D SNP_GUEST_VMM_ERR_INVALID_LEN) { const unsigned int certs_npages =3D snp_dev->input.data_npages; =20 exit_code =3D SVM_VMGEXIT_GUEST_REQUEST; @@ -376,7 +405,7 @@ static int handle_guest_request(struct snp_guest_dev *s= np_dev, u64 exit_code, * request buffer size was too small and give the caller the * required buffer size. */ - arg->exitinfo2 =3D SNP_GUEST_REQ_INVALID_LEN; + arg->vmm_error =3D SNP_GUEST_VMM_ERR_INVALID_LEN; snp_dev->input.data_npages =3D certs_npages; } =20 @@ -536,7 +565,7 @@ static int get_ext_report(struct snp_guest_dev *snp_dev= , struct snp_guest_reques sizeof(req.data), resp->data, resp_len); =20 /* If certs length is invalid then copy the returned length */ - if (arg->exitinfo2 =3D=3D SNP_GUEST_REQ_INVALID_LEN) { + if (arg->vmm_error =3D=3D SNP_GUEST_VMM_ERR_INVALID_LEN) { req.certs_len =3D snp_dev->input.data_npages << PAGE_SHIFT; =20 if (copy_to_user((void __user *)arg->req_data, &req, sizeof(req))) @@ -752,6 +781,8 @@ static int __init sev_guest_probe(struct platform_devic= e *pdev) if (ret) goto e_free_cert_data; =20 + ratelimit_state_init(&snp_dev->rs, rate_s * HZ, rate_burst); + dev_info(dev, "Initialized SEV guest driver (using vmpck_id %d)\n", vmpck= _id); return 0; =20 diff --git a/include/uapi/linux/sev-guest.h b/include/uapi/linux/sev-guest.h index 52e994b68d90..49fc4341ac93 100644 --- a/include/uapi/linux/sev-guest.h +++ b/include/uapi/linux/sev-guest.h @@ -85,4 +85,11 @@ struct snp_ext_report_req { /* Get SNP extended report as defined in the GHCB specification version 2.= */ #define SNP_GET_EXT_REPORT _IOWR(SNP_GUEST_REQ_IOC_TYPE, 0x2, struct snp_g= uest_request_ioctl) =20 +/* Guest message request EXIT_INFO_2 constants */ +#define SNP_GUEST_FW_ERR_MASK GENMASK_ULL(31, 0) +#define SNP_GUEST_VMM_ERR_SHIFT 32 + +#define SNP_GUEST_VMM_ERR_INVALID_LEN 1 +#define SNP_GUEST_VMM_ERR_BUSY 2 + #endif /* __UAPI_LINUX_SEV_GUEST_H_ */ --=20 2.39.0.314.g84b9a713c41-goog From nobody Mon Sep 15 13:07:11 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1B053C5479D for ; Wed, 11 Jan 2023 19:41:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235632AbjAKTlM (ORCPT ); Wed, 11 Jan 2023 14:41:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234993AbjAKTkR (ORCPT ); Wed, 11 Jan 2023 14:40:17 -0500 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F34D739F81 for ; Wed, 11 Jan 2023 11:40:11 -0800 (PST) Received: by mail-pg1-x549.google.com with SMTP id 69-20020a630148000000b00478118684c4so7166711pgb.20 for ; Wed, 11 Jan 2023 11:40:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=jAwKXq7cYddg0U2Li5LgdX400am5U2qQ139d3hoxgps=; b=fcv4l67oQghu07W08EOfE2q55pi/AAElyGc/+YUBryrv1ZpXqqG3duinf/ZQdRRysl cIOUUzl+ZhbFPLzT6cN1pIG1vDRzqCYg6GlwujdoYpsheXOt0rF3htOpxRvVHNnPD3E+ IlmsafzS0cmE06N0ye2e8x/gwqzELQn2lP743UKrm2jfglkG6u89tUHod5a21/9AacGz ub3LOFs706BupAiCg0qTBK5OqKRk1vteM3z5DlOUCbzJ1v14nimy6GuRqfz1jZeHWQmd BjsKrsD991JPcG9ydjWMOeWnX1ofU0KOtnESa0NwFSgmbOJNevovv4WnTFIPp9Cd7sd9 C7bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jAwKXq7cYddg0U2Li5LgdX400am5U2qQ139d3hoxgps=; b=Ewe/Wcp1bmfec2VemG0xJdArsi9BxY3agEq0UcEmPn9gWx6q4BIP7mLTLS5XYHEPqW jJPgih6zzAygiUdl+rYuRHAO1KZe1rVr1vTk61CN7Dnqx4MuT4VB8RVfA11FcKA4op4p JqFei3FjXeDmp04bChZkNXBZiUDbeZVA1e9hQQAP+6SUxqmV2AXEqmnlO1S3BsSt3JGG rCGH7I3r0B/5SlmCnV7ux98YdUkZDpWyj6jOnNk1bqk6mRdchiHg0jXXbZotOHAEkV4L Gr0vd4bKIXGm0jMT0C+xB57qXlxnVp+3+xFm6IfRk/3ALFnMD/DTYa9Io6u1nvUahN4X QLmw== X-Gm-Message-State: AFqh2koUOv1u7WuUdRMgtQ2F0YenbPy377Oz6JJrmCmpqPAbUXInYzgI Rl3KiCXklAMBTQ1SimZP2NHqBS5pqR5DNynISoYQHDf6BuTXxESYc1mPREHq/1kSUHoZh3g30zg bN2C76s7RMZc6WoxtOkSMq73aasfTpFC1lADKzM9N3geynLA4Zkkx/2JJdIXI1AHCMz2acbGGEl SBrYZx+/M= X-Google-Smtp-Source: AMrXdXvNvpVzfSaRaNYlqeW5e6YuBS7ISmwdDLoeKAbkIi6xZcJk2BmbW2jmOFN5/JWEmPRA1c0QjO/79AxLHEgEKQ== X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2ee6]) (user=dionnaglaze job=sendgmr) by 2002:a17:902:d550:b0:192:94cc:e39e with SMTP id z16-20020a170902d55000b0019294cce39emr4809880plf.155.1673466011165; Wed, 11 Jan 2023 11:40:11 -0800 (PST) Date: Wed, 11 Jan 2023 19:39:59 +0000 In-Reply-To: <20230111194001.1947849-1-dionnaglaze@google.com> Mime-Version: 1.0 References: <20230111194001.1947849-1-dionnaglaze@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20230111194001.1947849-6-dionnaglaze@google.com> Subject: [PATCH v11 5/7] x86/sev: Change sev_guestreq_err_t to u64 From: Dionna Glaze To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Dionna Glaze , Borislav Petkov , Peter Gonda , Thomas Lendacky Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" As part of changing the signature across modules, this step ensures the new type will continue to compile before the typedef is removed. Cc: Borislav Petkov Cc: Peter Gonda Cc: Thomas Lendacky Signed-off-by: Dionna Glaze --- arch/x86/include/asm/sev.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 5b03ba18fee7..301e3b69f477 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -137,7 +137,7 @@ struct snp_secrets_page_layout { * Use a type alias temporarily to cleanly change the snp_issue_guest_requ= est * signature cleanly over multiple patches. */ -typedef unsigned long sev_guestreq_err_t; +typedef u64 sev_guestreq_err_t; =20 #ifdef CONFIG_AMD_MEM_ENCRYPT extern struct static_key_false sev_es_enable_key; --=20 2.39.0.314.g84b9a713c41-goog From nobody Mon Sep 15 13:07:11 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7535DC46467 for ; Wed, 11 Jan 2023 19:41:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235623AbjAKTlY (ORCPT ); Wed, 11 Jan 2023 14:41:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235212AbjAKTkT (ORCPT ); Wed, 11 Jan 2023 14:40:19 -0500 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52FA93AA9A for ; Wed, 11 Jan 2023 11:40:13 -0800 (PST) Received: by mail-pl1-x64a.google.com with SMTP id p15-20020a170902a40f00b00192b2bbb7f8so11244926plq.14 for ; Wed, 11 Jan 2023 11:40:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=5bviZdBeZVWu9z0ohPbm1w0zXLBgxhA6laMUN/MloW8=; b=WFBqNjkRooygX82Vm48gtU1+bW7i42SR/l0eJYBDRVMkegtq6Ye2zEQ2RAhyUuUCns r8CqG/RZnRHeaqTMOshgIh8TozG22ziD8660wAbuAgwF2YdUJpjMDlvXyZ3PotedMlJs Iq8wQ8D75023d2DHDwfKgpprRCqh2MXuH8EhbX7LesW1zcETx/907VgnJ74o53BBfQjK OatrOHNkheVMS16ah+A0DdpD7djnm8EuuiEbojQo/k0JdHCAamkiH9pbUksaq+Pp9p8+ OhAP/b6aZCA3+RgYS3rU4Fm/W0S2Ok663QvEWtiefZe+/xsVBzr5ucT3LSEq6lrBVh+A t/yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5bviZdBeZVWu9z0ohPbm1w0zXLBgxhA6laMUN/MloW8=; b=yi+uoRrqO9vGUvZ2AvlWWicECkVRKi4lYRXeo6b24f6AZTrai2gbnmrlKiczKUfHM2 28RTaLf9nY+XccUDK/i0yG0KT5NHfl4ZUBqnpqmfVIZbupoFbGVXfGgZDRshWMiV5Ous OxlqkH01h8phJcFM8TMBXmDZagCLf22IooXodsH77VLgRwAyntAjh2o1LK7+0elNMjTc 4596EPRKrdulkKjlxn5bdQC/ivM9FqBcgMp0/txJnIcaaMJ4AVNiTf58TELiC+YvomQg FjG8/zXSXFlX2QjGdwR+/BkPI3BxZ7jAHH3TNclzjowTe/itFcGH5wxap3rnjdUtFGGQ WqBA== X-Gm-Message-State: AFqh2kpdnRIfPFvVeL3eNvNRY4ffAv7PKdj9WtdUxl1ZtiRrbv0jQGfn qre5MRJ4gIbJ2w1sRo8m9Sy0lWAF5SvTwk+PJCWYGP2+jbkCvZN0ldNR4M8GhytjJE5/yiiuhnq 1KbX19Kwh00BzZRfLy5a6hmg7SW4OOELuaANe3sjr9MKIRlcWkw9SDGwsd3xzAgBpaKz3TMBBDN 41ELM1IpM= X-Google-Smtp-Source: AMrXdXtk/BvFnceHRaJuw+iwbGdIY0UI/lHlAazeNkuD+QchdNYrfK9omQdZ7IZOolQbjLoCrJsvVFRdtemQ663SUQ== X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2ee6]) (user=dionnaglaze job=sendgmr) by 2002:a17:902:be16:b0:194:53f1:3912 with SMTP id r22-20020a170902be1600b0019453f13912mr113446pls.98.1673466012763; Wed, 11 Jan 2023 11:40:12 -0800 (PST) Date: Wed, 11 Jan 2023 19:40:00 +0000 In-Reply-To: <20230111194001.1947849-1-dionnaglaze@google.com> Mime-Version: 1.0 References: <20230111194001.1947849-1-dionnaglaze@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20230111194001.1947849-7-dionnaglaze@google.com> Subject: [PATCH v11 6/7] virt/coco/sev-guest: Remove dependence on sev_guestreq_t From: Dionna Glaze To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Dionna Glaze , Borislav Petkov , Peter Gonda , Thomas Lendacky Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Next step in changing the cross-module signature change is to remove this dependency in sev-guest in favor of the concrete type, u64. Cc: Borislav Petkov Cc: Peter Gonda Cc: Thomas Lendacky Signed-off-by: Dionna Glaze --- drivers/virt/coco/sev-guest/sev-guest.c | 2 +- include/uapi/linux/sev-guest.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/se= v-guest/sev-guest.c index 04c30e4da642..1204939d4f2b 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -412,7 +412,7 @@ static int handle_guest_request(struct snp_guest_dev *s= np_dev, u64 exit_code, if (rc) { dev_alert(snp_dev->dev, "Detected error from ASP request. rc: %d, exitinfo2: %llu\n", - rc, (u64)arg->exitinfo2); + rc, arg->exitinfo2); goto disable_vmpck; } =20 diff --git a/include/uapi/linux/sev-guest.h b/include/uapi/linux/sev-guest.h index 49fc4341ac93..ef910e605ef0 100644 --- a/include/uapi/linux/sev-guest.h +++ b/include/uapi/linux/sev-guest.h @@ -56,7 +56,7 @@ struct snp_guest_request_ioctl { =20 union { __u64 fw_err; /* Name deprecated in favor of others */ - sev_guestreq_err_t exitinfo2; + __u64 exitinfo2; struct { __u32 fw_error; __u32 vmm_error; --=20 2.39.0.314.g84b9a713c41-goog From nobody Mon Sep 15 13:07:11 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72CE5C5479D for ; Wed, 11 Jan 2023 19:41:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235682AbjAKTlh (ORCPT ); Wed, 11 Jan 2023 14:41:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233779AbjAKTk3 (ORCPT ); Wed, 11 Jan 2023 14:40:29 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 647FA3AB08 for ; Wed, 11 Jan 2023 11:40:15 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id w9-20020a05690210c900b007b20e8d0c99so17056753ybu.0 for ; Wed, 11 Jan 2023 11:40:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=jROFcMIOfREA4pvBEWsXvm2O06wrZcKQPogWOWVjrB0=; b=D1MUSWv+xcYp+8e8Z93OPrpXvAir7Vsy73rFaZnOnoCTIrqkRpOChaQSjhD/yjeua9 +IAYEJHPIv1/YczH/BFC+yEEpDzSs21d93HLLE39mdFDiIc45V4OBQQ8hvDJNQJvbVkp 5g9eaq0cQITh9qq7seexRWvL+yWohet9ZckS2zebI7/hKYi1d2IHju9ERumA6+KqhPby LwxUdbf4vj3GpSf9oc2JbViesADCGEWh6rYwKnNad+luQKFl5bZLbBgKTy4s9zS1rHaF CbVbjN2V4mJcjNqBy4SHsJOZJ88//N2OxsNWsGEccWmvK71CHSjq0F6aOZFQ3y/quuXU S5qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jROFcMIOfREA4pvBEWsXvm2O06wrZcKQPogWOWVjrB0=; b=T7fx1cxhrPcHord0EF+g9IAok/OL5QSpLvnmcjorN9WmLm89Ihw+frhgI9fAYXczm8 uLv7o0OKUfq0XQYBI75j/avmPkvj+dd/ychBdBFuaMsWFcLkXYO06FzOFg6N3bprnPCI mxlrg/AWoeuLKeqHB7nIn8MMpMswGIYM5UBWgemxgjIAOmxgD7GWBzTvYeMu2xWBed0X O5K08MHm/6wqz9/dZAOJwsBT9+I2sTNPaHUG7+o1vYNRbxBchZG6i5+0KdKcJg4Iq5yP yXsqapnq0UOq0aayi0KhHNF07YGQRdbHjXuh+NoyEzRrPnAqv0fJJPu5UUbj08dIHav6 8idg== X-Gm-Message-State: AFqh2krGIdvbFLpoJxwcQcSdjbS8HYSK5MWrZkK7hJSmz1OGEFqRsUSX 6mDVEInZ9429tzS58VUDvp859YLnO/4Blt1xmvD/ZKPfL+UNmXXHqIzjVD/3Jw/Z/XgRxOvZQ2G ztDL+FlHmS3z0eY5B+72B4P3ULpnS/Vrf73Us5Ciay/2naRtf9dRSDVI7QDzHgKfBnRRkgwALEN kSNtacZbM= X-Google-Smtp-Source: AMrXdXvkfBHdMJmj+IxdpeRTnzrsi0sV/DAsHHhqwy47u7Iv+f7pKLZaetm63WfSMKybAxSdEe1qLT1ZuR7gQljR5w== X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2ee6]) (user=dionnaglaze job=sendgmr) by 2002:a25:7694:0:b0:7bf:45f0:3ebb with SMTP id r142-20020a257694000000b007bf45f03ebbmr1096041ybc.599.1673466014555; Wed, 11 Jan 2023 11:40:14 -0800 (PST) Date: Wed, 11 Jan 2023 19:40:01 +0000 In-Reply-To: <20230111194001.1947849-1-dionnaglaze@google.com> Mime-Version: 1.0 References: <20230111194001.1947849-1-dionnaglaze@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20230111194001.1947849-8-dionnaglaze@google.com> Subject: [PATCH v11 7/7] x86/sev: Remove temporary typedef From: Dionna Glaze To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Dionna Glaze , Borislav Petkov , Peter Gonda , Thomas Lendacky Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The sev_guestreq_err_t typedef has served its purpose for cleanly changing the sev_issue_guest_request signature, so it's no longer needed. Cc: Borislav Petkov Cc: Peter Gonda Cc: Thomas Lendacky Signed-off-by: Dionna Glaze --- arch/x86/include/asm/sev.h | 10 ++-------- arch/x86/kernel/sev.c | 2 +- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 301e3b69f477..05de34d10d89 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -133,12 +133,6 @@ struct snp_secrets_page_layout { u8 rsvd3[3840]; } __packed; =20 -/* - * Use a type alias temporarily to cleanly change the snp_issue_guest_requ= est - * signature cleanly over multiple patches. - */ -typedef u64 sev_guestreq_err_t; - #ifdef CONFIG_AMD_MEM_ENCRYPT extern struct static_key_false sev_es_enable_key; extern void __sev_es_ist_enter(struct pt_regs *regs); @@ -202,7 +196,7 @@ void snp_set_memory_private(unsigned long vaddr, unsign= ed int npages); void snp_set_wakeup_secondary_cpu(void); bool snp_init(struct boot_params *bp); void __init __noreturn snp_abort(void); -int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, sev= _guestreq_err_t *exitinfo2); +int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, u64= *exitinfo2); #else static inline void sev_es_ist_enter(struct pt_regs *regs) { } static inline void sev_es_ist_exit(void) { } @@ -223,7 +217,7 @@ static inline void snp_set_wakeup_secondary_cpu(void) {= } static inline bool snp_init(struct boot_params *bp) { return false; } static inline void snp_abort(void) { } static inline int snp_issue_guest_request(u64 exit_code, struct snp_req_da= ta *input, - sev_guestreq_err_t *exitinfo2) + u64 *exitinfo2) { return -ENOTTY; } diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index d1a6092b1e03..70b4cbd33c45 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -2176,7 +2176,7 @@ static int __init init_sev_config(char *str) } __setup("sev=3D", init_sev_config); =20 -int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, sev= _guestreq_err_t *exitinfo2) +int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, u64= *exitinfo2) { struct ghcb_state state; struct es_em_ctxt ctxt; --=20 2.39.0.314.g84b9a713c41-goog