Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp28282imn; Wed, 3 Aug 2022 18:08:27 -0700 (PDT) X-Google-Smtp-Source: AA6agR6nL5Hvs11cy7n5AsbQW89r+PEzhLjecWAU+K+zeHIhR643QgctOaaI4XcwTpHluwvDV8tf X-Received: by 2002:a17:906:8a45:b0:730:9715:369d with SMTP id gx5-20020a1709068a4500b007309715369dmr10584612ejc.105.1659575307775; Wed, 03 Aug 2022 18:08:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659575307; cv=none; d=google.com; s=arc-20160816; b=kdgl40TTwnWrXhT29iUIJkJJXXUzh4afLf/lLb9UG5XbekLm+ML9tWHPsmtL4TCiaT MYs+C81ldHwmTQSDOusq2tVyq5pt9iHVldrXIOTtKTrZV4plxsk8GnLOxK/6K/aFJmId Gb7K9GwNHUFUk+DE/4yhdTh2Jhj8zIO14JkRdfUXIFy/VsUMrQ3FM/ud/vQNOlyc1hIT TRSywZTb0hNj+xyYZb+Gu9yMzZaYlwVuybES3v9pJgg5LTrL7tpwfqfAXu2CMprT++4j GsyQRt8KnkCKzaJ/BNhX5HG50OKafELhbZuTLOcdhLa0U81PGQTk1RKuS8VsDmMU+cee qdYA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=w8VHUoS6QiPWJ15/4Hwre880xJNYmewzNGgpQsSdTlc=; b=PsrJs6wX1DFn5qaCjH9Kl4gjulp/tZAGv5WWnRXYkRLZr9t7IRA5I02LckAsmRnVSs gl7PWDTEeYqzIpkw83edEeh2lWXoKdYMv9c4R4DnB19nMZzF4OlioLdM4BgsqEf4Qm4L wHdz6XAcNH7T4wy+bbSLVJj2iqum+vcA0TuMa1UHJ22Uz6qPLlF+EWfR8ZAoDm5ujF6K ZFbNGZndt7MBiodjlC2vWIpUmYDrxB86KuPXfH+g5a29eScGQxziZDZTf24gHsBFfXxC 7Lj5tNpkV0tZkHFsLxmsss4CdR7dnMAOLUC6aD1vietk4agIqqCx1Y/c+wjkPJUikcT+ mWKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DPRfoCrv; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id he11-20020a1709073d8b00b0072ee57126e9si20264616ejc.166.2022.08.03.18.07.48; Wed, 03 Aug 2022 18:08:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-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=@kernel.org header.s=k20201202 header.b=DPRfoCrv; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236533AbiHDBCg (ORCPT + 99 others); Wed, 3 Aug 2022 21:02:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229986AbiHDBCf (ORCPT ); Wed, 3 Aug 2022 21:02:35 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEEBF18E1C; Wed, 3 Aug 2022 18:02:34 -0700 (PDT) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 5A47F6172C; Thu, 4 Aug 2022 01:02:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 57664C433D6; Thu, 4 Aug 2022 01:02:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659574953; bh=ojOGwVmUtAwEibZBXIJloUOWkBRws1ynoRVHan4EmDQ=; h=From:To:Cc:Subject:Date:From; b=DPRfoCrv0r98FNMwDUmPEWXziQjIJmZQ9o76KB0ty0LVoBGVNvbyHPrcbLkROmGBk hbVqhkkxw1MJaIU2MnB2XNR6e8JmgbFPDxkhZZEqq2RfyEuAmx3ypoHLDA4PIal0XD hRkU8Rrdi6FqJBHmnSN7JOGIr9tg5fdVunDWSh5cBXLOgoE0qi8DbJVoYAplXeEGrU Ri5fNC2b2J6v4GFTx34uwFFrbdTAWd/59Ww7+GpdU8529dcFs6/oydrGUz4NqUfLVz F7a3lLY4Xx29fCP1iSTrvJYngmT0ojQne5fltnzraWkOKIHTheVoJIzvyipmfqYs4T WRRaVs5+xsxCA== From: Jarkko Sakkinen To: Paolo Bonzini Cc: Jarkko Sakkinen , Harald Hoyer , Brijesh Singh , Tom Lendacky , John Allen , Herbert Xu , "David S. Miller" , linux-crypto@vger.kernel.org (open list:AMD CRYPTOGRAPHIC COPROCESSOR (CCP) DRIVER - SE...), linux-kernel@vger.kernel.org (open list) Subject: [PATCH] crypto: ccp: Load the firmware twice when SEV API version < 1.43 Date: Thu, 4 Aug 2022 04:02:23 +0300 Message-Id: <20220804010223.3619-1-jarkko@kernel.org> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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-crypto@vger.kernel.org From: Jarkko Sakkinen SEV-SNP does not initialize to a legit state, unless the firmware is loaded twice, when SEP API version < 1.43, and the firmware is updated to a later version. Because of this user space needs to work around this with "rmmod && modprobe" combo. Fix this by implementing the workaround to the driver. Reported-by: Harald Hoyer Signed-off-by: Jarkko Sakkinen --- drivers/crypto/ccp/sev-dev.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index 799b476fc3e8..f2abb7439dde 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -76,6 +76,9 @@ static void *sev_es_tmr; #define NV_LENGTH (32 * 1024) static void *sev_init_ex_buffer; +/* + * SEV API version >= maj.min? + */ static inline bool sev_version_greater_or_equal(u8 maj, u8 min) { struct sev_device *sev = psp_master->sev_data; @@ -89,6 +92,14 @@ static inline bool sev_version_greater_or_equal(u8 maj, u8 min) return false; } +/* + * SEV API version < maj.min? + */ +static inline bool sev_version_less(u8 maj, u8 min) +{ + return !sev_version_greater_or_equal(maj, min); +} + static void sev_irq_handler(int irq, void *data, unsigned int status) { struct sev_device *sev = data; @@ -1274,6 +1285,7 @@ void sev_pci_init(void) { struct sev_device *sev = psp_master->sev_data; int error, rc; + int i; if (!sev) return; @@ -1283,9 +1295,13 @@ void sev_pci_init(void) if (sev_get_api_version()) goto err; - if (sev_version_greater_or_equal(0, 15) && - sev_update_firmware(sev->dev) == 0) - sev_get_api_version(); + /* + * SEV-SNP does not work properly before loading the FW twice in the API + * versions older than SEV 1.43. + */ + for (i = 0; i < sev_version_greater_or_equal(0, 15) + sev_version_less(1, 43); i++) + if (sev_update_firmware(sev->dev) == 0) + sev_get_api_version(); /* If an init_ex_path is provided rely on INIT_EX for PSP initialization * instead of INIT. -- 2.37.1