Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp281310rwj; Thu, 22 Dec 2022 07:41:57 -0800 (PST) X-Google-Smtp-Source: AMrXdXsgsnkqoU9p1dCZ/0Ejp6eB5D8E0Beu8loqeSE2FH3k47i/ezNmz9cR9hv6KI8hLg3KbkUs X-Received: by 2002:a05:6402:6c9:b0:46c:2c94:d30b with SMTP id n9-20020a05640206c900b0046c2c94d30bmr6294604edy.33.1671723717571; Thu, 22 Dec 2022 07:41:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671723717; cv=none; d=google.com; s=arc-20160816; b=gJs3AhcGfTHXmh2hNmlaXl1gEeLWbhI4oa3XE5J/7k+BXAb+CpZlToyItt8Yu2JQDp /BqBTSfm33QykunDH0Lbo/54sTrxZatQRhO0Rd3/dz99Ysa3d2VZB+c12mA2kQ5+csmB L+CCChnChy/ka+7rDN59s6PSHPU4Ds8hXvluOqtmY0L/LqaLZIXvn6EK9JtIPxGPQ99Y FaSqq/WvnvnuUosMp9qMXFtIIPN8qeydKC7TEGWy3YN6XLJD89Ndp1mb+DRDydSr1rc9 IihH6jl1PkTPe6s1PT6kkRz5pUU5+cR+0aevKTxYccZPPxHV/QFYGOkw0wn/v9aE//Xj 3lqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=2utF4R0Wvw1po8wU0dweMX9z4IlC4iVofg3q4hEttwk=; b=bxQHgsMYqX4PUfj6rmOvRe/uM32MTU8yCKdnCmjRr5F7SNwkCZ2+cxJiZnMKuHlk2e GBYYVf72eCFHHepF3B4R9SYUoaoy5pTExMzzaiJlWXFeU4ong9JuJRsGdnO3ctK8hU25 MI6qEXGlNGAttRUgL+sAPMbm4xm03tHzoeZCUf4Zcyz0zrCfw07NxUer4pYk4ryKFw2d MTq+mKaKJXCcKdnBy2r3bxIvsL0EIKT31UHOgmjXioVMmtTTZ5NH8ZMPRGoHPpCssMEX NW9aM0KdoJ63EU4Dy9Xos/li4cW+tuizJH0M7jrbQ+cIWLh+Dw30kzeHSO12ihu7Ora4 HVHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=H0Od5HSv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dt9-20020a170907728900b0073ce34d1a13si685221ejc.499.2022.12.22.07.41.42; Thu, 22 Dec 2022 07:41:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=H0Od5HSv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229740AbiLVPb1 (ORCPT + 68 others); Thu, 22 Dec 2022 10:31:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229680AbiLVPbZ (ORCPT ); Thu, 22 Dec 2022 10:31:25 -0500 Received: from mail.skyhub.de (mail.skyhub.de [IPv6:2a01:4f8:190:11c2::b:1457]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59939140C3 for ; Thu, 22 Dec 2022 07:31:23 -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 6CFFA1EC0531; Thu, 22 Dec 2022 16:31:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1671723081; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=2utF4R0Wvw1po8wU0dweMX9z4IlC4iVofg3q4hEttwk=; b=H0Od5HSvnHxbRD1G7uaZH9VrqMXAoyrqyeaiCAgfC5w/PsPFTUk0w3YyQa6/Hcyt+Upfms NU+Y/1i9jC3oTmiAi+qJlkv7xc/5wJpdRuTR8Zw6LXbI00MEoBJrLjNN1VvlSQOvuSxegx LL/g6yeIDEyyAdbqCH94KKIbf+obqUI= Date: Thu, 22 Dec 2022 16:31:16 +0100 From: Borislav Petkov To: Dionna Glaze , Thomas Lendacky , Herbert Xu Cc: linux-kernel@vger.kernel.org, x86@kernel.org, Peter Gonda , Paolo Bonzini , Joerg Roedel , Ingo Molnar , Andy Lutomirsky , John Allen , "David S. Miller" Subject: Re: [PATCH v9 1/4] crypto: ccp - Name -1 return value as SEV_RET_NO_FW_CALL Message-ID: References: <20221207010210.2563293-1-dionnaglaze@google.com> <20221207010210.2563293-2-dionnaglaze@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20221207010210.2563293-2-dionnaglaze@google.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Dec 07, 2022 at 01:02:07AM +0000, Dionna Glaze wrote: > 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(-) Looks good, did some minor touch ups ontop, see below. @Tom: Ack/Rev-by? @Herbert: ok to carry this through tip? Thx. --- From: Peter Gonda Date: Wed, 7 Dec 2022 01:02:07 +0000 Subject: [PATCH] crypto: ccp - Name -1 return value as SEV_RET_NO_FW_CALL 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, the name the value SEV_RET_NO_FW_CALL. [ bp: Massage a bit, get rid of the funky ->init_function local function pointer. ] Signed-off-by: Peter Gonda Signed-off-by: Dionna Glaze Signed-off-by: Borislav Petkov (AMD) 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 | 22 ++++++++++++++-------- include/uapi/linux/psp-sev.h | 7 +++++++ 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/Documentation/virt/coco/sev-guest.rst b/Documentation/virt/coco/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-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 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. Otherwise, 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..f44514653f5f 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.35.1 -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette