From patchwork Tue Mar 7 19:24:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Borislav Petkov X-Patchwork-Id: 65843 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2644808wrd; Tue, 7 Mar 2023 12:27:50 -0800 (PST) X-Google-Smtp-Source: AK7set/uKjlmDQr/X1Pb67ytCa9/onrfgb5mXfbanDGczJ8nl3XL0b5HregcbtmU2H35+uDubE/n X-Received: by 2002:a17:90b:4c85:b0:237:97fd:e3ac with SMTP id my5-20020a17090b4c8500b0023797fde3acmr15881183pjb.48.1678220870343; Tue, 07 Mar 2023 12:27:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678220870; cv=none; d=google.com; s=arc-20160816; b=qX2mnuUjJkKdkOLPolGZP5HIWNk+CXCJtC+Rw0Dk1Z2uxiSSCG0ARZovj0hc3Yjgf1 22j45jGhmwmMsCJcN+m0rdgqbeTKCTSnG68rbFf3rjryXxXgZFqdbM7xJddWc8HbA+eD 97EYJCMMSoyD0fGsTS4TW1DYVumlgeCohfD6OLwCjBatL90np2q0dxnUBg1jX4KspT+M 3DJom4R6HRTtf0T+qIfOXr0pXHv6F5SMFnKtLcI+gBHdQNmhjCvfFfKreQIdqvpU8Buq nVZpCIq1idGrKWRs/kePt7N7jHIi2pw5uV/lJ3jA2ozuQMC2KQOmb0DTNQpeTbKspaTS fmyw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=FVVFMu6+wmGt1AA1meeE7nEqiToclEEsqfV+E6pOD/g=; b=ZX+VEnrclczHq/hrx9acEBzPAWg/6JqQLpQ6evqrYrjT9UQ51w9ltl1bN3M/fdWvpa YaGET0KEswreXthW3PWWXEb06WsnRoZuRP9T/g+BsrW0emcKoIYJh5aaBB5R6X+HqAhG c9/lSujrzCsYv21gU1UT3e2DMf97uwq3HTWp1S9/45D5RYn0OUgBaG6LSouBpJnIjrK9 19qArC1oD5tP2uU2MzodUHzABhzKG7VWpb9uGeiMVJcnb9gW/+QxU4cG8nEUYIvpSCcd +3/elHyDGrhAB6vAmmiAmW/Z7/jyEwkqMP/mmCVECJ1BCO0D/cypGaKRndV7n/Of7R7C qaww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=A5AccOuC; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s8-20020a63af48000000b005004287592asi13037105pgo.36.2023.03.07.12.27.37; Tue, 07 Mar 2023 12:27:50 -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=A5AccOuC; 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 S234160AbjCGThy (ORCPT + 99 others); Tue, 7 Mar 2023 14:37:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234126AbjCGThg (ORCPT ); Tue, 7 Mar 2023 14:37:36 -0500 Received: from mail.skyhub.de (mail.skyhub.de [IPv6:2a01:4f8:190:11c2::b:1457]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0EBDB8571 for ; Tue, 7 Mar 2023 11:24:58 -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 AEB461EC068B; Tue, 7 Mar 2023 20:24:56 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1678217096; 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=FVVFMu6+wmGt1AA1meeE7nEqiToclEEsqfV+E6pOD/g=; b=A5AccOuCi9w/Dy2s5r1TkyqAh9rnbW9EcwJGD/DOIrKudKKZ19F9nTRMsBKcm8CjR0Y2eO 5TxDKCrMWwziKCyu6OKCbhbFed58029nAyVAst6yZVveLPaLR54z00aXVjZHnajiCnFYTx 67Zk5woGZ1acuXX4/qou3Iep/7OcbMc= 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 -v3 01/11] crypto: ccp - Name -1 return value as SEV_RET_NO_FW_CALL Date: Tue, 7 Mar 2023 20:24:39 +0100 Message-Id: <20230307192449.24732-2-bp@alien8.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230307192449.24732-1-bp@alien8.de> References: <20230307192449.24732-1-bp@alien8.de> MIME-Version: 1.0 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, URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759742127390493372?= X-GMAIL-MSGID: =?utf-8?q?1759742127390493372?= 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/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 e2f25926eb51..823c67a43c38 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -444,10 +444,10 @@ static int __sev_init_ex_locked(int *error) static int __sev_platform_init_locked(int *error) { + int rc = 0, psp_ret = SEV_RET_NO_FW_CALL; struct psp_device *psp = psp_master; - struct sev_device *sev; - int rc = 0, psp_ret = -1; int (*init_function)(int *error); + struct sev_device *sev; if (!psp || !psp->sev_data) return -ENODEV; @@ -475,9 +475,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."); + 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); } + if (error) *error = psp_ret; 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 = -1, SEV_RET_SUCCESS = 0, SEV_RET_INVALID_PLATFORM_STATE, SEV_RET_INVALID_GUEST_STATE,