From nobody Sun Sep 14 14:57:33 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 B9A10C05027 for ; Fri, 20 Jan 2023 21:52:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229750AbjATVwL (ORCPT ); Fri, 20 Jan 2023 16:52:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229711AbjATVwJ (ORCPT ); Fri, 20 Jan 2023 16:52:09 -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 1119380BB1 for ; Fri, 20 Jan 2023 13:52:08 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id f22-20020a056a00239600b0058d956679f5so2979194pfc.5 for ; Fri, 20 Jan 2023 13:52: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=kSxrMzG1Hv7pdQ1Ytw036hc1FJB6QyL44T06ZBbgDu4=; b=DGNmPG5xe76kN+gBDq5mU0YsgJej+WFDU/Tvr3GYRdJ5GgTvQ+csWUH6fEI6DSEp7T rT7NXuhVTAUCsGI5hm6oy8KY3yBz3Qyx0R3PtD08QCfq6iBmHRqhPPj8Ly4jfV8j7gZp 2hlnw1qCkBdZDlMYRHXcaDmlQy+PX9wGTSKrM7F+l+DP62zubLRIDXVMGlmGhXggtOPT YbXWRp+CKmbd0glr2I9mleU9HE0JuQPVts+BWfaLhQw3oxFpjM2XdiprknUIJK296KFt sytBP0DCk+F+yp98jBnfto7x1qF3yuxWQ1Fj2bvxLilOJ4FzHCS5C2Z0LreUpipW+o/b /IAA== 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=kSxrMzG1Hv7pdQ1Ytw036hc1FJB6QyL44T06ZBbgDu4=; b=R2NKs4O/Bqj9UfArbESpSEA2A27V93yZEMfofL/2JMPgRXyyGL4t/jyF0pYZOX3DmW 88PCIbU+MyJxw7iQZZUKh4eHfFhB2uz1A6zkGfvbiHQvXde3RZSyMHSjryOFiNzKjzq9 RNZsK4xrYtYoolSnIhWs/0HQsSQALmTZHvuxoHiU3CGFG6VG6Fx1Cz352SzZmzC2Q0NN rZZWAMIjzo3UalKxroB0mF61BCw7NeKMg9NKjZllCslMPkqwpRVXoZTWh3xRUhhUZ/Y4 ycjbK7I9ZSv/lvRC+41ryG5Wj91jpZdDo+kfUnujNCEa47e3rr/o0ZMLTY+uw2b8rYEq Yp9A== X-Gm-Message-State: AFqh2kp9Fes8IQnbclQpi6NLb8ZV83OrG+Fmp5OITEAoSizldpTY/YXl Khk9MV2YtUZ2tsKiDZb9mX5EPKVRzvz5TEEFJA== X-Google-Smtp-Source: AMrXdXvRQYSwAtryjO3/9NuhUBXCtmfhNrGdDeWz28VwYmz1ZWFq5gSbOxfizxdka/O+/85ZxAhGpIIv7A0KjtrMHw== X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2ee6]) (user=dionnaglaze job=sendgmr) by 2002:a17:902:8694:b0:189:6889:c30a with SMTP id g20-20020a170902869400b001896889c30amr1672842plo.6.1674251527474; Fri, 20 Jan 2023 13:52:07 -0800 (PST) Date: Fri, 20 Jan 2023 21:48:54 +0000 In-Reply-To: <20230120214857.835931-1-dionnaglaze@google.com> Mime-Version: 1.0 References: <20230120214857.835931-1-dionnaglaze@google.com> X-Mailer: git-send-email 2.39.0.246.g2a6d74b583-goog Message-ID: <20230120214857.835931-2-dionnaglaze@google.com> Subject: [PATCH v12 1/3] crypto: ccp - Name -1 return value as SEV_RET_NO_FW_CALL From: Dionna Glaze To: x86@kernel.org, linux-kernel@vger.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.246.g2a6d74b583-goog