From nobody Thu Sep 11 21:24:41 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 EA49BC636CC for ; Thu, 16 Feb 2023 12:41:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229926AbjBPMli (ORCPT ); Thu, 16 Feb 2023 07:41:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229667AbjBPMle (ORCPT ); Thu, 16 Feb 2023 07:41:34 -0500 Received: from mail.skyhub.de (mail.skyhub.de [5.9.137.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A0902111 for ; Thu, 16 Feb 2023 04:41:32 -0800 (PST) Received: from zn.tnic (p5de8e9fe.dip0.t-ipconnect.de [93.232.233.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 27B8B1EC0936; Thu, 16 Feb 2023 13:41:31 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1676551291; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xAFRY6UWQLF1FP7olpHuR0CBZw+9W4Mq3Tn1rtwpBJM=; b=aqIHPJNl4/e/9kkpLBfxVFts8J7z2/qJHEBnzjD5JBynXihm5D81Rg9MtDyveFFz7zINlJ 7co4z6rO4kSDJaVFnDiwl4cQiNnwVKL8XPVD9Nvnv+h0iaBz5jBE6qM8wD8DaKpj0zcIGH SU3V1zBqPtrTB10+qvyAoK706Ff2pRQ= From: Borislav Petkov To: LKML Cc: stable@kernel.org, Dionna Glaze , Joerg Roedel , Michael Roth , Nikunj A Dadhania , Peter Gonda , Tom Lendacky , linux-coco@lists.linux.dev, x86@kernel.org Subject: [PATCH 01/11] crypto: ccp - Name -1 return value as SEV_RET_NO_FW_CALL Date: Thu, 16 Feb 2023 13:41:10 +0100 Message-Id: <20230216124120.26578-2-bp@alien8.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230216124120.26578-1-bp@alien8.de> References: <20230216124120.26578-1-bp@alien8.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 has not actually been called. To make this protocol unambiguous, name the value SEV_RET_NO_FW_CALL. [ bp: Massage a bit. ] Signed-off-by: Peter Gonda Signed-off-by: Dionna Glaze Signed-off-by: Borislav Petkov (AMD) Cc: Link: https://lore.kernel.org/r/20221207010210.2563293-2-dionnaglaze@google= .com --- Documentation/virt/coco/sev-guest.rst | 4 ++-- drivers/crypto/ccp/sev-dev.c | 8 +++++--- include/uapi/linux/psp-sev.h | 7 +++++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Documentation/virt/coco/sev-guest.rst b/Documentation/virt/coc= o/sev-guest.rst index bf593e88cfd9..aa3e4c6a1f90 100644 --- a/Documentation/virt/coco/sev-guest.rst +++ b/Documentation/virt/coco/sev-guest.rst @@ -40,8 +40,8 @@ along with a description: 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 0x00000000000000ff. +to execute due to a firmware error, then fw_err code will be set. Otherwis= e, 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..f60bb73edfda 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -442,10 +442,10 @@ static int __sev_init_ex_locked(int *error) =20 static int __sev_platform_init_locked(int *error) { + int rc =3D 0, psp_ret =3D SEV_RET_NO_FW_CALL; struct psp_device *psp =3D psp_master; - struct sev_device *sev; - int rc =3D 0, psp_ret =3D -1; int (*init_function)(int *error); + struct sev_device *sev; =20 if (!psp || !psp->sev_data) return -ENODEV; @@ -473,9 +473,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."); + dev_err(sev->dev, +"SEV: retrying INIT command because of SECURE_DATA_INVALID error. Retrying= once to reset PSP SEV state."); rc =3D init_function(&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..1c9da485318f 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. Its purpose is 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.35.1