Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp6454162rwb; Tue, 9 Aug 2022 16:01:08 -0700 (PDT) X-Google-Smtp-Source: AA6agR6z5ZayZdKJAzatSYQHAMg36mjW0GteOD8VJsH+oecX6tjc4galnb9Jrk2a6LiFjojHlY58 X-Received: by 2002:a05:6402:27cf:b0:43f:f6a:3286 with SMTP id c15-20020a05640227cf00b0043f0f6a3286mr21246143ede.1.1660086068173; Tue, 09 Aug 2022 16:01:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660086068; cv=none; d=google.com; s=arc-20160816; b=IL29LqPvHriLtgibH/SKofF2K//jEbmlIEVVTBpNoPWxEc9JQz2DR73u57MP70zadI b+rXDzFf3tZtkYvlct8RDrDedqLlWNDdtnf41UM8h5WN49lgBLMmp/6imBMRdiBlaGoi w/6ns5vDRiqJPmJeq+/z4M0iPFknWXlyodov3aneOm8SpHa7jEEalKuSwLW126TfxSDO THe705Ien1Suj8BSXLCslVRPnwGkbhaGazkmdeF8nTswSTEkQvuB18v5L5dQcSm6wnlo F2kHtVCRnAKZdhJzS2yutgJTxS5vzgHeec+H+r9d5YPBdLByIdoBnumjdiIsQYRyyqtV k5AA== 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=hrP1AkmoOs5MTiPFpV1FQ2UgBFcrNQLjNRB2TxaAHa4=; b=zzACPzu6clrElUAG4w5s3uMOCGRZmZyevZ9Su4SBNyBfcuo7sTPhU0bTpk/1aYQoKO xvOSta32vCJtafB0KZp7Ag96pd7QfCKgxRSm4NgrZ9wgtEKFP0/pwiS76jdXHTDjXGbd K4S07uXmEQ3CPt+TTBTDwuUbg655qgLTQ3Bi03PnmHo+dxN8YMdy5gZr2r807sVoX2Cy ccSWdUG1AMVwttfpiKiemgAKC63l6XAcPqkbWd94ZAVJriUv09ugUZlrccbid3j8To/X 84DFrwLzXQqVNpM5Kq6QjCsinLgT3P3S7j/9W6qR6jokT7k2vv9GZ4zSO2u9EfzZ44xW ILfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QRl+7reU; 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 qf31-20020a1709077f1f00b0073056870528si3197944ejc.888.2022.08.09.16.00.33; Tue, 09 Aug 2022 16:01:08 -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=QRl+7reU; 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 S229450AbiHIWtc (ORCPT + 99 others); Tue, 9 Aug 2022 18:49:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229436AbiHIWtb (ORCPT ); Tue, 9 Aug 2022 18:49:31 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F49165828; Tue, 9 Aug 2022 15:49:30 -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 B8053B81912; Tue, 9 Aug 2022 22:49:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF84BC433D6; Tue, 9 Aug 2022 22:49:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660085367; bh=uPhKhKjz4nLP7Bfa+GXJs+PEOTPR67p/T4XukYbqA4o=; h=From:To:Cc:Subject:Date:From; b=QRl+7reUPLya7J6GhrTYQqv9fhHRfcuM4mzrpHvWuSEjiEx8Vxyhf+Wm/SbZvHnEt ecFi76RZXfgX1U6ynNeWnba3i79KvWpVipkw/jCbLWE1bylTYIWdjLsfTQ2z/mrfpx U/7e0y1QDSXaw4iW/VrAqbHduMDS3AEl9PnQoLCXH4rIhymotXajdcHUcTw+p7kbIv JIYnj+M1wtDIzVcacCzj4SAo119Bu4bh0MvlI3cLPm8FK7QAEVJK07/h315LWd3GFG kMPeQoDQWfFSROc5uoJEhbHr7PpfOJTlHL4GoKBsPIZxUa5o0OwO5+Rc0iC6TQqfJ7 V55gPksXkWaQQ== 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 v2] crypto: ccp: Add a quirk to firmware update Date: Wed, 10 Aug 2022 01:49:15 +0300 Message-Id: <20220809224915.92111-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 a firmware version earlier than 1.50. This is a known issue, and the documented workaround is to load the firmware twice. Currently, this issue 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 --- v2: - Updated the commit message and comments. https://lore.kernel.org/all/0a3a790d-989f-2f76-f636-62fbd925a776@amd.com/ 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..f27f8bc966b1 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.50. + */ + 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