Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3714649pxb; Mon, 24 Jan 2022 16:08:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJzJrm3+shz1achmWuJO9SR+bHqqrtOoZKvTJg7iQr9q5P6ZkK+oVsFIbmyFvjBVYOnptlH/ X-Received: by 2002:a17:90b:1bc7:: with SMTP id oa7mr671600pjb.149.1643069287548; Mon, 24 Jan 2022 16:08:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643069287; cv=none; d=google.com; s=arc-20160816; b=pah6plarvQtWepMpdjqicyAWtuxvc27rzMFcUbJoKdoRjvQs0YrCcXlw7Krj1Jf2f+ dnQZaqbaSfpgkJxSfQBfXxj0chGTCSFkjJLQlaq7Iw4AcivnHtpfLwWaGJrkFq6bwiNx csXOKH3XtXoGoG0CjJAToED5aOpEooeeYDCz5w/50akeEbZzuK/xDMkDahD3q9cT1b9B GcTj7pP9IrvAcjJRmOvDXkO9MCB4aDOw42FgIgESXYW2yGnQbkpyruvgEu6QUAaINKH1 jIhLTo5ZpQ8aRxtzAFT5NBN+cXvuTymhUYzsqN9YE9TV7T9z87EzUBFL0Fky+GyD6XJx 290g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wwUTc8ZLj/JMXaOhimoE5AkW+OijOqcna/Y77jhRUSU=; b=jKkEjgcAD7pR8j7tfMbXlEYN93C6kTNpkwXX7aJd9rhHaaFg78uIhwpjFZGEqSxONy 4wgN984HRrZ/IztFMbotreK6OcJhQp+SWu7UdUNS0qWpH3/sj59UFxTYEbwT0q3ecf4q Ky7gj58NHRb5c7TtJB3sAkXxMVgJ3AoSQkUHClRkOGUOzm4gfcX6Og67iHIplUthxi0t BN0a31qwnwQMHP8vjMIq0Poe6cpzj+EePT4JCW4k8W3BwbkYF+jyYhmmRbRP3CFRzTHh 0s8aRZj07VVTV235AyeC20gntxhGpIIvMTVbpMvuN+xwoV/hnn7pt3bDNfAgUwjiJ1b6 +Xcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LGVpllKp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r134si6982229pfc.167.2022.01.24.16.07.55; Mon, 24 Jan 2022 16:08:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LGVpllKp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2369122AbiAYABA (ORCPT + 99 others); Mon, 24 Jan 2022 19:01:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1847032AbiAXXSV (ORCPT ); Mon, 24 Jan 2022 18:18:21 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7F51C06F8D4; Mon, 24 Jan 2022 13:26:19 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6BBA2B8122A; Mon, 24 Jan 2022 21:26:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9A444C340E4; Mon, 24 Jan 2022 21:26:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643059578; bh=gN8e4n+344COSfz2qoEkyox0kd95ormBrbUV3mZwg6g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LGVpllKp7HJa1tcMMgYopNBb78GztmssoSTZxeDBrsQpIGTTq2SV/AIOY6o8LDoXw rEyp8c3MtSEEbqcvY03ahbgDVIuMGefRvZ48/7ZEamIW/kFAq00QbTQ1OCYT4d3QP9 mcndbU2bBNQUkQCLl3vfPzkyIe3gHG3E6xcCUpC4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Peter Gonda , Marc Orr , David Rientjes , Tom Lendacky , Brijesh Singh , Joerg Roedel , Herbert Xu , John Allen , "David S. Miller" , Paolo Bonzini , linux-crypto@vger.kernel.org, Sasha Levin Subject: [PATCH 5.16 0663/1039] crypto: ccp - Move SEV_INIT retry for corrupted data Date: Mon, 24 Jan 2022 19:40:52 +0100 Message-Id: <20220124184147.658020922@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Gonda [ Upstream commit e423b9d75e779d921e6adf5ac3d0b59400d6ba7e ] Move the data corrupted retry of SEV_INIT into the __sev_platform_init_locked() function. This is for upcoming INIT_EX support as well as helping direct callers of __sev_platform_init_locked() which currently do not support the retry. Signed-off-by: Peter Gonda Reviewed-by: Marc Orr Acked-by: David Rientjes Acked-by: Tom Lendacky Acked-by: Brijesh Singh Cc: Tom Lendacky Cc: Brijesh Singh Cc: Marc Orr Cc: Joerg Roedel Cc: Herbert Xu Cc: David Rientjes Cc: John Allen Cc: "David S. Miller" Cc: Paolo Bonzini Cc: linux-crypto@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- drivers/crypto/ccp/sev-dev.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index e09925d86bf36..581a1b13d5c3d 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -241,7 +241,7 @@ static int __sev_platform_init_locked(int *error) struct psp_device *psp = psp_master; struct sev_data_init data; struct sev_device *sev; - int rc = 0; + int psp_ret, rc = 0; if (!psp || !psp->sev_data) return -ENODEV; @@ -266,7 +266,21 @@ static int __sev_platform_init_locked(int *error) data.tmr_len = SEV_ES_TMR_SIZE; } - rc = __sev_do_cmd_locked(SEV_CMD_INIT, &data, error); + rc = __sev_do_cmd_locked(SEV_CMD_INIT, &data, &psp_ret); + if (rc && psp_ret == SEV_RET_SECURE_DATA_INVALID) { + /* + * Initialization command returned an integrity check failure + * status code, meaning that firmware load and validation of SEV + * related persistent data has failed. Retrying the + * initialization function should succeed by replacing the state + * with a reset state. + */ + dev_dbg(sev->dev, "SEV: retrying INIT command"); + rc = __sev_do_cmd_locked(SEV_CMD_INIT, &data, &psp_ret); + } + if (error) + *error = psp_ret; + if (rc) return rc; @@ -1091,18 +1105,6 @@ void sev_pci_init(void) /* Initialize the platform */ rc = sev_platform_init(&error); - if (rc && (error == SEV_RET_SECURE_DATA_INVALID)) { - /* - * INIT command returned an integrity check failure - * status code, meaning that firmware load and - * validation of SEV related persistent data has - * failed and persistent state has been erased. - * Retrying INIT command here should succeed. - */ - dev_dbg(sev->dev, "SEV: retrying INIT command"); - rc = sev_platform_init(&error); - } - if (rc) { dev_err(sev->dev, "SEV: failed to INIT error %#x\n", error); return; -- 2.34.1