From mboxrd@z Thu Jan 1 00:00:00 1970 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 C04E5C54E94 for ; Tue, 24 Jan 2023 21:16:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234903AbjAXVQB (ORCPT ); Tue, 24 Jan 2023 16:16:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234882AbjAXVPi (ORCPT ); Tue, 24 Jan 2023 16:15:38 -0500 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F1EA4903A for ; Tue, 24 Jan 2023 13:15:23 -0800 (PST) Received: by mail-pf1-x449.google.com with SMTP id a18-20020a62bd12000000b0056e7b61ec78so7285973pff.17 for ; Tue, 24 Jan 2023 13:15:23 -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=nI8g4HK84XEnirb7lePLViKdpyhNA5CP1Cst9JmMi5Y=; b=qIKw7KlhcMtg+UFKVLR/9KFMYZ9rcvDTnnOKXWbscj7BPR6fhxV2gx8g85b1FV27NK n+EGQ1CV2OY0QTHRc+cKsaR1WG13o6ygQ9l57sVS/W0ezXA/ca0m6j5jLSDmBFzayoDb jHo0b8xPwC4d5yRoJpIDDE4lK7BBDvc2T2Ru43p3K9VjR/3dl3DGHL2x6khfULc2p/Xw h9qyhUXVbBqX26FcQyxKMUTCAJdUn1V+l291NTs1vYTP5rLif+XhAc6AWYbKFbD6LgAa 49a23IVGxqJQBAVHtN+VAYfb1Bab/KqdYIxTaRVKOSBAFmziqwhTdcXloQinjZXrigDp kdmA== 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=nI8g4HK84XEnirb7lePLViKdpyhNA5CP1Cst9JmMi5Y=; b=DpaWFEJI1APcjHxwft/eGMHa6ffq174tDmvnEGn1ZJVdj4iDTqApMffhOTqtRa+2sq bINx6ightdR1PWCZ7kFILbRXZqNmlP5PPQvFuUTpb/+xAjUFXG4LZ8aO4Lg5fDYzh4tv MH+pqMCFJgl9Gafy7nNxzCJK6M7uySkHBWbNbqI/rSB0fWw8Y8uLMiXVWUmlXvDIPwSc AUW37J7fDbiKSlw36WhU8IUjmoRGHIvxrctUSOA35ogm3jxeW96o3qIkwIFDHT9ozAm3 7+NoXdRgSKqpZICIb7vQiNQBHiKMDdS1nb1CosWnsxZ4ECccSrgThb+5FJ3rbdMQrDaX SpMQ== X-Gm-Message-State: AO0yUKVut0clIsrjFU29eztBC20vDggW4ngjF396gimhg1jY60pMt1H7 SsAL6RatJ/tLaPHftqYyoF4gHofBS7q7MU3O9Xn7k5ZEt511kNTa8Ffhm9C/KwCMsHDVCnL9h7L ZPzGs8gwku5uqVIJor39vDVhfBVR4Cg6iY4cf5n6R00MpTa/tSc5Q+qWM949KNsVi0hB7eSHDz7 bz7aAdkS8= X-Google-Smtp-Source: AK7set9hAYuLijlZZ/UKUkVmnthi6QP0tHYRF+o2x0weNdcjzHb0WPB6xHGhbNGWQ9B09ym+P7SV7kzXwuPW9JG6+g== X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2ee6]) (user=dionnaglaze job=sendgmr) by 2002:a17:90a:8b8d:b0:225:eaa2:3f5d with SMTP id z13-20020a17090a8b8d00b00225eaa23f5dmr55767pjn.2.1674594921092; Tue, 24 Jan 2023 13:15:21 -0800 (PST) Date: Tue, 24 Jan 2023 21:14:53 +0000 In-Reply-To: <20230124211455.2563674-1-dionnaglaze@google.com> Mime-Version: 1.0 References: <20230124211455.2563674-1-dionnaglaze@google.com> X-Mailer: git-send-email 2.39.1.405.gd4c25cc71f-goog Message-ID: <20230124211455.2563674-3-dionnaglaze@google.com> Subject: [PATCH v13 2/4] 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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/coco/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 structure is specified through the req_data and resp_data field respectively. If the ioctl 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. The firmware checks that the message sequence counter is one greater than the guests message sequence counter. If guest driver fails to increment message 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); } +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 = psp_master; struct sev_device *sev; - int rc = 0, psp_ret = -1; - int (*init_function)(int *error); + int rc = 0, psp_ret = SEV_RET_NO_FW_CALL; if (!psp || !psp->sev_data) return -ENODEV; @@ -456,15 +463,12 @@ static int __sev_platform_init_locked(int *error) return 0; if (sev_init_ex_buffer) { - init_function = __sev_init_ex_locked; rc = sev_read_init_ex_file(); if (rc) return rc; - } else { - init_function = __sev_init_locked; } - rc = init_function(&psp_ret); + rc = __sev_do_init_locked(&psp_ret); if (rc && psp_ret == 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_INVALID error. Retrying once to reset PSP SEV state."); - rc = 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 = __sev_do_init_locked(&psp_ret); } + if (error) *error = psp_ret; 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 = -1, SEV_RET_SUCCESS = 0, SEV_RET_INVALID_PLATFORM_STATE, SEV_RET_INVALID_GUEST_STATE, -- 2.39.1.405.gd4c25cc71f-goog