Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp4179739rwb; Sun, 7 Aug 2022 17:17:21 -0700 (PDT) X-Google-Smtp-Source: AA6agR7Iw9rK63cxrlFJEOEx7lWib3AFV4OmGHdxHNwppjE21IJ0GHbvapvj0RWdZr6rX74ca8kC X-Received: by 2002:aa7:9390:0:b0:52d:8816:a906 with SMTP id t16-20020aa79390000000b0052d8816a906mr16214055pfe.63.1659917841683; Sun, 07 Aug 2022 17:17:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659917841; cv=none; d=google.com; s=arc-20160816; b=SPfwWxUPjlJel1Y1a2uUtcpYxmXCivJe8DzAQA+oKsIPJmHuw8madqgL0qwTtJKDrZ be5sKGck/BZJlz/Ft3S7lVgHITAdJeLErtjTiqxC/bFkEtjh+7+R/NeSfrTgkq5uByIx bWnJ5GjYP6n7l02hK8FHTcWXQR8gi6ozjgUE2lwNQWQbuvFiTSwT/8JYcjok8YE/kFLL VWnFyZVvgvoQXUrbuququssNPVryjutTVmsgKtSlHzB7XaDXWvpua5gxnz5cM7JckjQ4 EaoLETRU8vDqUVSNwmTor9xxf8utWCVSvzTtJcoYdy/ecj9/hJkl0TfSP2XklFQDKGtK f2Ag== 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=czK68HkNUPXDNT/SZK+LA3mRKNwW9u8OgPbhe0VfYIQ=; b=xDGoEd6EsfGIM4cF6R4VATv1MPipnkmE5F63zgalzX/CmFVune/++YdRI5rQd0qXz6 ckQ3VTwu5G3WUE/nBKBsWzp+qXRWzl/8YeZLWRBxBeySeIQhp9+Da2v0Cib9ZKLj0HhP XHa7C2+CTAUl9AqcONTvHPKqZWO42GmDuCWOS0tjwpJzS/hXbv0VfTlSo4UbubcuwqMM rANAKlj9tZ5beEIhPAFsEwAvsezJbvPdz6U+Im9UUjBsMpqny9fK55TGS1U5SXunOZaQ vboxu5G78R8V3HmPGlEuuNc0odvCueKNVjA7CEq4fosH9V9D6AlCY2DOv29msEDnYzM4 zeTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Y5x9TDm+; 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 i62-20020a638741000000b0041d89b01992si1514668pge.532.2022.08.07.17.16.52; Sun, 07 Aug 2022 17:17:21 -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=Y5x9TDm+; 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 S229787AbiHHAPy (ORCPT + 99 others); Sun, 7 Aug 2022 20:15:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229845AbiHHAPx (ORCPT ); Sun, 7 Aug 2022 20:15:53 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9184D6354; Sun, 7 Aug 2022 17:15:49 -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 ams.source.kernel.org (Postfix) with ESMTPS id 3688FB80DD7; Mon, 8 Aug 2022 00:15:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6BA4AC433D6; Mon, 8 Aug 2022 00:15:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659917746; bh=3IYKf9Y1/2t5807EFG4T9FnXkEiD9rmOH2bt8Xr/fB8=; h=From:To:Cc:Subject:Date:From; b=Y5x9TDm+mTFxTwlxOr93RLVmgmvoiOZYvoxFP+78DF7it8BWlB2xKnWhcQ2BUUHSp xvj9dKBac+OrMMZyg4A8/F5l2TmKJfm/WIr8YAv6ZjGu4NyDi7PhhU1Whg2Btq6bHQ wLQ+ua/jqJb6BpCLQXnKlz4XY9pRd+xaVfUTdB0mGdQf8115kOMO3Ci48JOQdRh6oo u26c+1SSrRntFfhTWEeAjLyYe5oX1TLq3gA9/7+ewuOpT/Xn1Y5x3GS7NVKGxQGrwb /7UL2VkFpYhvadVLJi912kLbLJp5Gj3bMfshx++m43651encj3MIz+1Zqe6b+0z4a8 lDMFsD1e9ASPQ== From: Jarkko Sakkinen To: Paolo Bonzini Cc: Tom Lendacky , Jarkko Sakkinen , Harald Hoyer , Brijesh Singh , 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: Add a quirk to firmware update Date: Mon, 8 Aug 2022 03:15:37 +0300 Message-Id: <20220808001537.6479-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,T_SCC_BODY_TEXT_LINE 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 A quirk for fixing the committed TCB version, when upgrading from earlier firmware version than 1.33.01. This is a known issue, and the documented workaround is to load the firmware twice. The issue realizes in a machine where the upgrade is done from firmware reporting having SEV API version 1.49, and requires the following workaround: sudo modprobe -r kvm_amd sudo modprobe -r ccp sudo modprobe ccp sudo modprobe kvm_amd Implement this workaround inside kernel by checking whether the API version is less than 1.50, and if so, download the firmware twice. This addresses the TCB version issue. Link: https://lore.kernel.org/all/de02389f-249d-f565-1136-4af3655fab2a@profian.com/ Reported-by: Harald Hoyer Signed-off-by: Jarkko Sakkinen --- drivers/crypto/ccp/sev-dev.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index 799b476fc3e8..8ae26c5c64f6 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -742,6 +742,11 @@ static int sev_update_firmware(struct device *dev) struct page *p; u64 data_size; + if (!sev_version_greater_or_equal(0, 15)) { + dev_dbg(dev, "DOWNLOAD_FIRMWARE not supported\n"); + return -1; + } + if (sev_get_firmware(dev, &firmware) == -ENOENT) { dev_dbg(dev, "No SEV firmware file present\n"); return -1; @@ -774,6 +779,14 @@ static int sev_update_firmware(struct device *dev) data->len = firmware->size; ret = sev_do_cmd(SEV_CMD_DOWNLOAD_FIRMWARE, data, &error); + + /* + * A quirk for fixing the committed TCB version, when upgrading from + * earlier firmware version than 1.33.01. + */ + if (!ret && !sev_version_greater_or_equal(1, 50)) + ret = sev_do_cmd(SEV_CMD_DOWNLOAD_FIRMWARE, data, &error); + if (ret) dev_dbg(dev, "Failed to update SEV firmware: %#x\n", error); else @@ -1283,8 +1296,7 @@ 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) + 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 -- 2.37.1