From patchwork Tue Dec 7 23:33:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Gonda X-Patchwork-Id: 12662923 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24D4CC433FE for ; Tue, 7 Dec 2021 23:33:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242593AbhLGXgp (ORCPT ); Tue, 7 Dec 2021 18:36:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242588AbhLGXgp (ORCPT ); Tue, 7 Dec 2021 18:36:45 -0500 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F455C061746 for ; Tue, 7 Dec 2021 15:33:14 -0800 (PST) Received: by mail-pg1-x549.google.com with SMTP id s18-20020a63ff52000000b00320f169c0aaso259149pgk.18 for ; Tue, 07 Dec 2021 15:33:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=S9HhHEaCqq8juujlhIoNSDxxgNKBtqtxQU5YxI2svaw=; b=buSpmo6M3pApRVi2NMxwXaGteg1Oc/DvWa79jtkAI+ISl8TMCW35+eMMUUoyoK1QcC UNqEVoxRdO14/y7jxx3fFTNE/w03VlqjR5XRmzAjoaOo1cA5i/L16zjXiP1lJetwqWaW BaJGKQsoPMOZKtEVCEYj6C2Gvv2q1Qs6kzwiTSzyaSVtSZT5rxfRo3zEFhl0giCg8wCi D2tx/VgNUgAiLa+EXrAZltK+ZxoM05XdFIitPQ4pU11Wn46OdyarwbMXktqnTEpQDqWp SdUtliVCq5zCL1Ir3WMMMZQFNgz2Q0mLMQYgQur4KZ0oOgPibVDbZaOMEZXg1WxSl9d1 q7sQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=S9HhHEaCqq8juujlhIoNSDxxgNKBtqtxQU5YxI2svaw=; b=SeSG0ai5Vzh6JsgltcyqCaAxLOe3XwQQqfiS243NT+cYpMHXQZ/KOmVXgiW1SIwq0b ZraLUcD3ak/lsw0Ji15UubQYvSU/7l900geudRsW/hyjpch117moZEVb1y8KFOudyQK5 CLLCpGaAJiap09qx8KpupJf5rwrdjHBwmzFYmWpoIxBBzQXKo5il4kcB+baKjdCGtwPT FfVj7bDjCG0bsZRq3n10m88mOoMGOKaVHA0HJK9i+1DIR8E9+MJZ6MKf2CIIobAvfio7 TwGx/9LEz4S/RtGnnRfpcjesylIc5Odl7aJihSrEtFAQVYqFU0HnqqKwx1MxJrzHXygK tnzQ== X-Gm-Message-State: AOAM533CDP5e8kUJq/ekF+YKL7cm+0WNTWosNoMbWHOpCzpm5cgp4qga TwQZln5A/LqEuW6lWAGi5U/qhRvLSAw= X-Google-Smtp-Source: ABdhPJzik9hif76tFQLVlE/NgW3Vi0SZTTbgEMWcCDandafb499HCVkP0qAqheDHdbNZvEjUyQek2sCGZOI= X-Received: from pgonda1.kir.corp.google.com ([2620:15c:29:203:46ed:9c47:8229:475d]) (user=pgonda job=sendgmr) by 2002:a17:902:c20d:b0:142:21e:b1e8 with SMTP id 13-20020a170902c20d00b00142021eb1e8mr54167478pll.27.1638919994074; Tue, 07 Dec 2021 15:33:14 -0800 (PST) Date: Tue, 7 Dec 2021 15:33:02 -0800 In-Reply-To: <20211207233306.2200118-1-pgonda@google.com> Message-Id: <20211207233306.2200118-2-pgonda@google.com> Mime-Version: 1.0 References: <20211207233306.2200118-1-pgonda@google.com> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog Subject: [PATCH V6 1/5] crypto: ccp - Add SEV_INIT rc error logging on init From: Peter Gonda To: thomas.lendacky@amd.com Cc: Peter Gonda , Marc Orr , David Rientjes , Brijesh Singh , Joerg Roedel , Herbert Xu , John Allen , "David S. Miller" , Paolo Bonzini , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Currently only the firmware error code is printed. This is incomplete and also incorrect as error cases exists where the firmware is never called and therefore does not set an error code. 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 --- drivers/crypto/ccp/sev-dev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index e09925d86bf3..f527e5f9ed1f 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -1104,7 +1104,8 @@ void sev_pci_init(void) } if (rc) { - dev_err(sev->dev, "SEV: failed to INIT error %#x\n", error); + dev_err(sev->dev, "SEV: failed to INIT error %#x, rc %d\n", + error, rc); return; } From patchwork Tue Dec 7 23:33:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Gonda X-Patchwork-Id: 12662925 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39D40C433F5 for ; Tue, 7 Dec 2021 23:33:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242601AbhLGXgt (ORCPT ); Tue, 7 Dec 2021 18:36:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242606AbhLGXgr (ORCPT ); Tue, 7 Dec 2021 18:36:47 -0500 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DCCBC061574 for ; Tue, 7 Dec 2021 15:33:16 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id t7-20020a17090a5d8700b001a7604b85f5so494375pji.8 for ; Tue, 07 Dec 2021 15:33:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=NyP8sL/WxxBH7JUR2jE6+QS2DZJi6iBbnJsRRfn1ObM=; b=U7fvRAj6L3zYcu5y0Fz/ZCwr8xpf3hNHvev8A7QdvuEuIzGPmbEo++Tis3La8ai/oB HOxyA2IM3Z5xVkiLk8W8cBy5HHOrwv/9zuI121Fz3dKg0BmBi5rlWKwmSd/rokfrI5wb DeXaFIga8ilQ8DEiIYLTUYRRxNJyI+7fJgXYOl2uScg4MH/Z/6gImLw+yf/EwULMAqsb vSGVWk8lDHCyZhpvTpriaImWvBao8dDgppzh1Zf2U2zb/w2qRzKb53rPm+VMyzqHf0wn MVLVWdNK0N7SDSeqa6xOhVrjcjXFhHwdcoUJtrv0WBgtdvstsh6EkM8rQ5Icb8u3soki pDww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=NyP8sL/WxxBH7JUR2jE6+QS2DZJi6iBbnJsRRfn1ObM=; b=fmIF6RXea0esehJBZnq1/+w6EJEKCG323Cgm4zXZu3kOlC7InI8rNaQtjttu23i7ZW 2g5hX1ERolsRTTfWOaDcJmS0dUA40BFDGvA5AJUpuot6ktLYgbri2MVfShXTQHVDjNg2 e3SKDvzJ1t2FpxHhtzIcKafk60EcUpi1EcDNMQ8sNIULDm/JFk72kk+XK8GmcqLEO19w 9Is1G1tAZdUGuV3dbKLAHfPMHD9UtKUXTbCMvFSHL/K/MBdhwaVYVy3Sl9kMmgePydJp U+vheuvh8RLRj5K2Gbh0ECZ7ar/wDCfNH18BTi5pjvDpqH1HLBWE6PCh/GtpcTdSdrkq NRYA== X-Gm-Message-State: AOAM531mKAoimWiQyNhbbmRis040ZRtiRgYg/HUHTvUDQB/1eSmJwvCG /9GtErq9XbJgl5ySOiyxubAvs7BruCM= X-Google-Smtp-Source: ABdhPJx3NSvXc2AFJTTKB8653/2hxn63jAmQWpPvyztLFzfgc3/fRXpZtGiBTtQErQZQKkTQ7WKCWiSXsus= X-Received: from pgonda1.kir.corp.google.com ([2620:15c:29:203:46ed:9c47:8229:475d]) (user=pgonda job=sendgmr) by 2002:a05:6a00:24c7:b0:4a0:41b:38f9 with SMTP id d7-20020a056a0024c700b004a0041b38f9mr2364617pfv.54.1638919996068; Tue, 07 Dec 2021 15:33:16 -0800 (PST) Date: Tue, 7 Dec 2021 15:33:03 -0800 In-Reply-To: <20211207233306.2200118-1-pgonda@google.com> Message-Id: <20211207233306.2200118-3-pgonda@google.com> Mime-Version: 1.0 References: <20211207233306.2200118-1-pgonda@google.com> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog Subject: [PATCH V6 2/5] crypto: ccp - Move SEV_INIT retry for corrupted data From: Peter Gonda To: thomas.lendacky@amd.com Cc: Peter Gonda , Marc Orr , David Rientjes , Brijesh Singh , Joerg Roedel , Herbert Xu , John Allen , "David S. Miller" , Paolo Bonzini , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org 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 --- 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 f527e5f9ed1f..ef7e8b4c6e02 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, rc %d\n", error, rc); From patchwork Tue Dec 7 23:33:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Gonda X-Patchwork-Id: 12662927 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A20AC433FE for ; Tue, 7 Dec 2021 23:33:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242621AbhLGXgu (ORCPT ); Tue, 7 Dec 2021 18:36:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242614AbhLGXgt (ORCPT ); Tue, 7 Dec 2021 18:36:49 -0500 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70FE2C061746 for ; Tue, 7 Dec 2021 15:33:18 -0800 (PST) Received: by mail-pg1-x549.google.com with SMTP id i12-20020a63584c000000b00330ec6e2c37so281202pgm.7 for ; Tue, 07 Dec 2021 15:33:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=ekOV9da4eWSrPoL63ChA67xsZs2WyoWSKbx3HEcftwg=; b=l3kk4SnixWXF3tsv+8v1l4PbSejH8gJCJykpVyS6vkQvCnmub/r5nqHlySnBYEnJ3R NR4ESPRwI6Rgf4coACYSAVfkb8btWBUsg0w9bA8Ip8NE6IWBWSiJt3ehxqo3ict286d5 wj1lp1D7qhiN8rClhEH2sV0b0q6s4kqOUdTRlpw/SPTB5Rrrs581tmUfSTE5E8cLDWkG wm8rDrt+KdK3pgpVAHmXp0wSohvArd2dJMUCAmbYBOt/CltCS7m5VKUZTwC3iUe5U5DT GfPZmLr0vPdw714idQxMClczLIVbGoRvd3z0284BjqqWA41ua7s8InQTeaoVB03QyXgo n5rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=ekOV9da4eWSrPoL63ChA67xsZs2WyoWSKbx3HEcftwg=; b=pBFL3zsu/OCapqqQPygAtMWtrLUJT0GEu17jNrKzk21pvXqP7elBlTOsRafHdh7a4h vN++bPVnYDs2JB4xg3FCtSiO4grK0cHJnfq0ZRQFaHuFALptdkSgqad0JhU349JyaTnU 9bx5PjsEWFAIjCTq17nabMfY41gz/WLKmjGRItqxIwO10vj7V9jJlUzQZf0aPmnZwkqH nSc3gl7lfyXHMnbud2xubwbiR++noxI70C9bHZC3Vv56G2pvLu/J4ODHNd3vaBiAEZMS SkqIZ2du40xvteoFrQ/NRil1IW/aWc5hexZuaPJgtBkvxYl+hkbQetFnVf8IBui2avcX 9v0A== X-Gm-Message-State: AOAM530BRTC5k8k3e+D85tlNi6iWlbCd1JeWdhA4+lIbwtvU2LLIbERS flpmvl0elpZg6/YPn3hufjgcavcYjrU= X-Google-Smtp-Source: ABdhPJzuKzhttUxwRDHCLWpasUIlmUcvPliCCRNSdYKkfltOWOcn8RtTEBhof61Y9WOWhgY/FjJ8hItvmH0= X-Received: from pgonda1.kir.corp.google.com ([2620:15c:29:203:46ed:9c47:8229:475d]) (user=pgonda job=sendgmr) by 2002:a17:90a:a786:: with SMTP id f6mr2842553pjq.158.1638919997919; Tue, 07 Dec 2021 15:33:17 -0800 (PST) Date: Tue, 7 Dec 2021 15:33:04 -0800 In-Reply-To: <20211207233306.2200118-1-pgonda@google.com> Message-Id: <20211207233306.2200118-4-pgonda@google.com> Mime-Version: 1.0 References: <20211207233306.2200118-1-pgonda@google.com> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog Subject: [PATCH V6 3/5] crypto: ccp - Refactor out sev_fw_alloc() From: Peter Gonda To: thomas.lendacky@amd.com Cc: Peter Gonda , Marc Orr , David Rientjes , Brijesh Singh , Joerg Roedel , Herbert Xu , John Allen , "David S. Miller" , Paolo Bonzini , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Create a helper function sev_fw_alloc() which can be used to allocate aligned memory regions for use by the PSP firmware. Currently only used for the SEV-ES TMR region but will be used for the SEV_INIT_EX NV memory region. Signed-off-by: Peter Gonda Reviewed-by: Marc Orr Acked-by: David Rientjes 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 --- drivers/crypto/ccp/sev-dev.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index ef7e8b4c6e02..8ea362ac014f 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -141,6 +141,17 @@ static int sev_cmd_buffer_len(int cmd) return 0; } +static void *sev_fw_alloc(unsigned long len) +{ + struct page *page; + + page = alloc_pages(GFP_KERNEL, get_order(len)); + if (!page) + return NULL; + + return page_address(page); +} + static int __sev_do_cmd_locked(int cmd, void *data, int *psp_ret) { struct psp_device *psp = psp_master; @@ -1078,7 +1089,6 @@ EXPORT_SYMBOL_GPL(sev_issue_cmd_external_user); void sev_pci_init(void) { struct sev_device *sev = psp_master->sev_data; - struct page *tmr_page; int error, rc; if (!sev) @@ -1094,14 +1104,10 @@ void sev_pci_init(void) sev_get_api_version(); /* Obtain the TMR memory area for SEV-ES use */ - tmr_page = alloc_pages(GFP_KERNEL, get_order(SEV_ES_TMR_SIZE)); - if (tmr_page) { - sev_es_tmr = page_address(tmr_page); - } else { - sev_es_tmr = NULL; + sev_es_tmr = sev_fw_alloc(SEV_ES_TMR_SIZE); + if (!sev_es_tmr) dev_warn(sev->dev, "SEV: TMR allocation failed, SEV-ES support unavailable\n"); - } /* Initialize the platform */ rc = sev_platform_init(&error); From patchwork Tue Dec 7 23:33:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Gonda X-Patchwork-Id: 12662929 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED45CC433EF for ; Tue, 7 Dec 2021 23:33:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242626AbhLGXg4 (ORCPT ); Tue, 7 Dec 2021 18:36:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242615AbhLGXgv (ORCPT ); Tue, 7 Dec 2021 18:36:51 -0500 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23DD3C061574 for ; Tue, 7 Dec 2021 15:33:20 -0800 (PST) Received: by mail-pg1-x549.google.com with SMTP id 66-20020a630545000000b0032e4e898d24so275134pgf.10 for ; Tue, 07 Dec 2021 15:33:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=46XSeEjo5H2NL/5/c9ldxW11TL6ltb9jVbtcCkM7Ayg=; b=Xgj8LvxT9/2jKZhK9jYnbUqDqVoXR/eQ5CH40LJNbyuFjJh6r+NeXM5uBby5wKHKJT QlXfRKBp/eDhbAS8mBIyvc+VlPtJGZqMiPQILjdGK/2FQQKV/KkSp2hWQYYtQTO2Jf34 q4oVotoRGdWoH93ipYuUuJbgpPueWDRA2pppegsUxoPQQYtGEdG5is1YFvYazMi21O1p GlcU/42940PRMM980tPEBQwxxBhJ6OSUESXXZ3VWjXqDjHt5UKibdtMzfpv5PqtKbScO zCblgAC8G7fd7gJEhA9IyvDdzRNH6bn/H+nJYUoAB8mUEoORXTqQmT47AQZJDB5r0SDV zLJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=46XSeEjo5H2NL/5/c9ldxW11TL6ltb9jVbtcCkM7Ayg=; b=vYs34XzvVnLPcKEeIi486uX8ofgtJCF3KrKaWaRguoxNy1wSuS2e4vyBd0tfq+RRQN /72FnSBlh8L4jceCwMboqkPR9ZAjYPZ99hWIc/mhOBUO+JTun+OedGkPXoMYyOhiWb+I ioafrCBkBBrnPQn30wqcaE0qd5JtsyMKqW8PvW/sh3HgI5W5ikFt1WuprL3hjsQG54nO +31yLDSCtkiTxS38sMIpkZbANJ6nY7RlVLSGUbzkPTy4DNi5Exg0CH046yYjgu1adUNk 0/fzi19bFgHTKAI+y6mug1rSDddYbuF836uH6pQJ34JoxW9jcFAygywYVQAJvPvAXw17 LGww== X-Gm-Message-State: AOAM531yE3pfic0tOOvemPzlipAs9BRof6YDtoujYTs9HsJCBdvLghIb 6ctmQDmCgaxrW8fRnFROny5ifxJEi/c= X-Google-Smtp-Source: ABdhPJy43pt5HEP3ID2ehicyXt/5AFj2Zd9cXGLqHXChM+79yHqoTBRRjrQTVB/szPpTIJj/HSuNFGtAVbM= X-Received: from pgonda1.kir.corp.google.com ([2620:15c:29:203:46ed:9c47:8229:475d]) (user=pgonda job=sendgmr) by 2002:a63:41c5:: with SMTP id o188mr26755932pga.206.1638919999631; Tue, 07 Dec 2021 15:33:19 -0800 (PST) Date: Tue, 7 Dec 2021 15:33:05 -0800 In-Reply-To: <20211207233306.2200118-1-pgonda@google.com> Message-Id: <20211207233306.2200118-5-pgonda@google.com> Mime-Version: 1.0 References: <20211207233306.2200118-1-pgonda@google.com> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog Subject: [PATCH V6 4/5] crypto: ccp - Add psp_init_on_probe module parameter From: Peter Gonda To: thomas.lendacky@amd.com Cc: Peter Gonda , Brijesh Singh , Marc Orr , Joerg Roedel , Herbert Xu , David Rientjes , John Allen , "David S. Miller" , Paolo Bonzini , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Add psp_init_on_probe module parameter that allows for skipping the PSP's SEV platform initialization during module init. User may decouple module init from PSP init due to use of the INIT_EX support in upcoming patch which allows for users to save PSP's internal state to file. The file may be unavailable at module init. Also moves the PSP ABI version log message to after successful PSP init instead of module init in case this new parameter is used. Signed-off-by: Peter Gonda 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 --- drivers/crypto/ccp/sev-dev.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index 8ea362ac014f..686b16e69de7 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -43,6 +43,10 @@ static int psp_probe_timeout = 5; module_param(psp_probe_timeout, int, 0644); MODULE_PARM_DESC(psp_probe_timeout, " default timeout value, in seconds, during PSP device probe"); +static bool psp_init_on_probe = true; +module_param(psp_init_on_probe, bool, 0444); +MODULE_PARM_DESC(psp_init_on_probe, " if true, the PSP will be initialized on module init. Else the PSP will be initialized on the first command requiring it"); + MODULE_FIRMWARE("amd/amd_sev_fam17h_model0xh.sbin"); /* 1st gen EPYC */ MODULE_FIRMWARE("amd/amd_sev_fam17h_model3xh.sbin"); /* 2nd gen EPYC */ MODULE_FIRMWARE("amd/amd_sev_fam19h_model0xh.sbin"); /* 3rd gen EPYC */ @@ -305,7 +309,10 @@ static int __sev_platform_init_locked(int *error) dev_dbg(sev->dev, "SEV firmware initialized\n"); - return rc; + dev_info(sev->dev, "SEV API:%d.%d build:%d\n", sev->api_major, + sev->api_minor, sev->build); + + return 0; } int sev_platform_init(int *error) @@ -1109,16 +1116,14 @@ void sev_pci_init(void) dev_warn(sev->dev, "SEV: TMR allocation failed, SEV-ES support unavailable\n"); + if (!psp_init_on_probe) + return; + /* Initialize the platform */ rc = sev_platform_init(&error); - if (rc) { + if (rc) dev_err(sev->dev, "SEV: failed to INIT error %#x, rc %d\n", error, rc); - return; - } - - dev_info(sev->dev, "SEV API:%d.%d build:%d\n", sev->api_major, - sev->api_minor, sev->build); return; From patchwork Tue Dec 7 23:33:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Gonda X-Patchwork-Id: 12662931 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 52C82C433F5 for ; Tue, 7 Dec 2021 23:33:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242615AbhLGXg4 (ORCPT ); Tue, 7 Dec 2021 18:36:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242630AbhLGXgw (ORCPT ); Tue, 7 Dec 2021 18:36:52 -0500 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0437CC0617A2 for ; Tue, 7 Dec 2021 15:33:22 -0800 (PST) Received: by mail-pf1-x449.google.com with SMTP id c131-20020a621c89000000b004a343484969so526500pfc.3 for ; Tue, 07 Dec 2021 15:33:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=YIj1cidfuFKi9+VTkRnK1kssvs8JEEsHVfevz0HcqHw=; b=lmls6H6UEOTGDi4KFaMoCghNFIqRJDdn9IwpXTI63xF4owZob4k6u2tYkaH7jO7Eq2 MN1bI1vx5UWl/Z+SNpq78AbOzd6nvOMSdckqIz6P12vZKu0kVTvK+m/RO7JtNG6sTkKy EdTn8VEMGPPBocxfBEnlLkgVtebrhSka1otiU12rE7ZK4l6D4kBbQD+tAm1c3hrDirjF N4X5lYO/MBgA702sJuBzDSw7LDI/+6P9/SVVD1SOSnivwUUj+PS9kJGQPvfFCKHQZd2v 5a4MM4+l2SXMmyHctiQ9J7t1nPpZCLaFVGqRRGsY1fRWbtIHJH5ohhdQzc5SCPcxbtPN g3IQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=YIj1cidfuFKi9+VTkRnK1kssvs8JEEsHVfevz0HcqHw=; b=bbx9S9FZp65n9WT1QkUmI8k4yRknnETr/wwub0XO/S+UQ8756CyvDD58M19yO34eQ5 i1zvqtXtKKxYBOTQm9aFWIDiT0l8hI7EGVaIxLFRR6REdLcwwi6weJ0CpHH3N+KufWoA JIF7opCFEvlq5dA96v/pF63JLDFO1W7mU63t32l3cDTF5npmRlTuP13/gTkh3FrwXh2E Fp1/vnJwPzzH5Jeykack6iuZZ2zlHvAahJd3JD82AX3tUPfg9dXzQbW7/BwH8ydLZHeC 1uSTKlI88SUemszFN2yfacQIRdQ5O8FnmvYAbKBtwtyrJfsNW9TwaKqsGxOPfxpCqcMv eDeA== X-Gm-Message-State: AOAM532Ch0O2qH6G2mCVRN4w/uyM1rUzOgmabqA5lXsEZJVx4IikXcEW ed7+GrpMIgENIbuWLerIw0N31rtlqYA= X-Google-Smtp-Source: ABdhPJyCztZjwm+aKSJFyiK5PUpWL3iW4VLmzYEuQpRykV0srOQFpiyqS7SZUSkNOJGCYffG9u3WlqiIIvQ= X-Received: from pgonda1.kir.corp.google.com ([2620:15c:29:203:46ed:9c47:8229:475d]) (user=pgonda job=sendgmr) by 2002:a05:6a00:10cf:b0:4a3:124d:bb81 with SMTP id d15-20020a056a0010cf00b004a3124dbb81mr2324774pfu.75.1638920001450; Tue, 07 Dec 2021 15:33:21 -0800 (PST) Date: Tue, 7 Dec 2021 15:33:06 -0800 In-Reply-To: <20211207233306.2200118-1-pgonda@google.com> Message-Id: <20211207233306.2200118-6-pgonda@google.com> Mime-Version: 1.0 References: <20211207233306.2200118-1-pgonda@google.com> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog Subject: [PATCH V6 5/5] crypto: ccp - Add SEV_INIT_EX support From: Peter Gonda To: thomas.lendacky@amd.com Cc: David Rientjes , Peter Gonda , Marc Orr , kernel test robot , Brijesh Singh , Joerg Roedel , Herbert Xu , John Allen , "David S. Miller" , Paolo Bonzini , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: David Rientjes Add new module parameter to allow users to use SEV_INIT_EX instead of SEV_INIT. This helps users who lock their SPI bus to use the PSP for SEV functionality. The 'init_ex_path' parameter defaults to NULL which means the kernel will use SEV_INIT, if a path is specified SEV_INIT_EX will be used with the data found at the path. On certain PSP commands this file is written to as the PSP updates the NV memory region. Depending on file system initialization this file open may fail during module init but the CCP driver for SEV already has sufficient retries for platform initialization. During normal operation of PSP system and SEV commands if the PSP has not been initialized it is at run time. If the file at 'init_ex_path' does not exist the PSP will not be initialized. The user must create the file prior to use with 32Kb of 0xFFs per spec. Signed-off-by: David Rientjes Co-developed-by: Peter Gonda Signed-off-by: Peter Gonda Reviewed-by: Marc Orr Reported-by: kernel test robot 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 --- .../virt/kvm/amd-memory-encryption.rst | 6 + drivers/crypto/ccp/sev-dev.c | 193 ++++++++++++++++-- include/linux/psp-sev.h | 21 ++ 3 files changed, 205 insertions(+), 15 deletions(-) diff --git a/Documentation/virt/kvm/amd-memory-encryption.rst b/Documentation/virt/kvm/amd-memory-encryption.rst index 5c081c8c7164..1c6847fff304 100644 --- a/Documentation/virt/kvm/amd-memory-encryption.rst +++ b/Documentation/virt/kvm/amd-memory-encryption.rst @@ -85,6 +85,12 @@ guests, such as launching, running, snapshotting, migrating and decommissioning. The KVM_SEV_INIT command is used by the hypervisor to initialize the SEV platform context. In a typical workflow, this command should be the first command issued. +The firmware can be initialized either by using its own non-volatile storage or +the OS can manage the NV storage for the firmware using the module parameter +``init_ex_path``. The file specified by ``init_ex_path`` must exist. To create +a new NV storage file allocate the file with 32KB bytes of 0xFF as required by +the SEV spec. + Returns: 0 on success, -negative on error 2. KVM_SEV_LAUNCH_START diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index 686b16e69de7..991cc5aaaa0f 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -22,6 +22,7 @@ #include #include #include +#include #include @@ -43,6 +44,10 @@ static int psp_probe_timeout = 5; module_param(psp_probe_timeout, int, 0644); MODULE_PARM_DESC(psp_probe_timeout, " default timeout value, in seconds, during PSP device probe"); +static char *init_ex_path; +module_param(init_ex_path, charp, 0444); +MODULE_PARM_DESC(init_ex_path, " Path for INIT_EX data; if set try INIT_EX"); + static bool psp_init_on_probe = true; module_param(psp_init_on_probe, bool, 0444); MODULE_PARM_DESC(psp_init_on_probe, " if true, the PSP will be initialized on module init. Else the PSP will be initialized on the first command requiring it"); @@ -62,6 +67,14 @@ static int psp_timeout; #define SEV_ES_TMR_SIZE (1024 * 1024) static void *sev_es_tmr; +/* INIT_EX NV Storage: + * The NV Storage is a 32Kb area and must be 4Kb page aligned. Use the page + * allocator to allocate the memory, which will return aligned memory for the + * specified allocation order. + */ +#define NV_LENGTH (32 * 1024) +static void *sev_init_ex_buffer; + static inline bool sev_version_greater_or_equal(u8 maj, u8 min) { struct sev_device *sev = psp_master->sev_data; @@ -111,6 +124,7 @@ static int sev_cmd_buffer_len(int cmd) { switch (cmd) { case SEV_CMD_INIT: return sizeof(struct sev_data_init); + case SEV_CMD_INIT_EX: return sizeof(struct sev_data_init_ex); case SEV_CMD_PLATFORM_STATUS: return sizeof(struct sev_user_data_status); case SEV_CMD_PEK_CSR: return sizeof(struct sev_data_pek_csr); case SEV_CMD_PEK_CERT_IMPORT: return sizeof(struct sev_data_pek_cert_import); @@ -156,6 +170,101 @@ static void *sev_fw_alloc(unsigned long len) return page_address(page); } +static int sev_read_init_ex_file(void) +{ + struct sev_device *sev = psp_master->sev_data; + struct file *fp; + ssize_t nread; + + lockdep_assert_held(&sev_cmd_mutex); + + if (!sev_init_ex_buffer) + return -EOPNOTSUPP; + + fp = filp_open(init_ex_path, O_RDONLY, 0); + if (IS_ERR(fp)) { + int ret = PTR_ERR(fp); + + dev_err(sev->dev, + "SEV: could not open %s for read, error %d\n", + init_ex_path, ret); + return ret; + } + + nread = kernel_read(fp, sev_init_ex_buffer, NV_LENGTH, NULL); + if (nread != NV_LENGTH) { + dev_err(sev->dev, + "SEV: failed to read %u bytes to non volatile memory area, ret %ld\n", + NV_LENGTH, nread); + return -EIO; + } + + dev_dbg(sev->dev, "SEV: read %ld bytes from NV file\n", nread); + filp_close(fp, NULL); + + return 0; +} + +static void sev_write_init_ex_file(void) +{ + struct sev_device *sev = psp_master->sev_data; + struct file *fp; + loff_t offset = 0; + ssize_t nwrite; + + lockdep_assert_held(&sev_cmd_mutex); + + if (!sev_init_ex_buffer) + return; + + fp = filp_open(init_ex_path, O_CREAT | O_WRONLY, 0600); + if (IS_ERR(fp)) { + dev_err(sev->dev, + "SEV: could not open file for write, error %ld\n", + PTR_ERR(fp)); + return; + } + + nwrite = kernel_write(fp, sev_init_ex_buffer, NV_LENGTH, &offset); + vfs_fsync(fp, 0); + filp_close(fp, NULL); + + if (nwrite != NV_LENGTH) { + dev_err(sev->dev, + "SEV: failed to write %u bytes to non volatile memory area, ret %ld\n", + NV_LENGTH, nwrite); + return; + } + + dev_dbg(sev->dev, "SEV: write successful to NV file\n"); +} + +static void sev_write_init_ex_file_if_required(int cmd_id) +{ + lockdep_assert_held(&sev_cmd_mutex); + + if (!sev_init_ex_buffer) + return; + + /* + * Only a few platform commands modify the SPI/NV area, but none of the + * non-platform commands do. Only INIT(_EX), PLATFORM_RESET, PEK_GEN, + * PEK_CERT_IMPORT, and PDH_GEN do. + */ + switch (cmd_id) { + case SEV_CMD_FACTORY_RESET: + case SEV_CMD_INIT_EX: + case SEV_CMD_PDH_GEN: + case SEV_CMD_PEK_CERT_IMPORT: + case SEV_CMD_PEK_GEN: + break; + default: + return; + }; + + sev_write_init_ex_file(); +} + static int __sev_do_cmd_locked(int cmd, void *data, int *psp_ret) { struct psp_device *psp = psp_master; @@ -225,6 +334,8 @@ static int __sev_do_cmd_locked(int cmd, void *data, int *psp_ret) dev_dbg(sev->dev, "sev command %#x failed (%#010x)\n", cmd, reg & PSP_CMDRESP_ERR_MASK); ret = -EIO; + } else { + sev_write_init_ex_file_if_required(cmd); } print_hex_dump_debug("(out): ", DUMP_PREFIX_OFFSET, 16, 2, data, @@ -251,37 +362,71 @@ static int sev_do_cmd(int cmd, void *data, int *psp_ret) return rc; } -static int __sev_platform_init_locked(int *error) +static int __sev_init_locked(int *error) { - struct psp_device *psp = psp_master; struct sev_data_init data; - struct sev_device *sev; - int psp_ret, rc = 0; - if (!psp || !psp->sev_data) - return -ENODEV; + memset(&data, 0, sizeof(data)); + if (sev_es_tmr) { + /* + * Do not include the encryption mask on the physical + * address of the TMR (firmware should clear it anyway). + */ + data.tmr_address = __pa(sev_es_tmr); - sev = psp->sev_data; + data.flags |= SEV_INIT_FLAGS_SEV_ES; + data.tmr_len = SEV_ES_TMR_SIZE; + } - if (sev->state == SEV_STATE_INIT) - return 0; + return __sev_do_cmd_locked(SEV_CMD_INIT, &data, error); +} + +static int __sev_init_ex_locked(int *error) +{ + struct sev_data_init_ex data; + int ret; memset(&data, 0, sizeof(data)); - if (sev_es_tmr) { - u64 tmr_pa; + data.length = sizeof(data); + data.nv_address = __psp_pa(sev_init_ex_buffer); + data.nv_len = NV_LENGTH; + + ret = sev_read_init_ex_file(); + if (ret) + return ret; + if (sev_es_tmr) { /* * Do not include the encryption mask on the physical * address of the TMR (firmware should clear it anyway). */ - tmr_pa = __pa(sev_es_tmr); + data.tmr_address = __pa(sev_es_tmr); data.flags |= SEV_INIT_FLAGS_SEV_ES; - data.tmr_address = tmr_pa; data.tmr_len = SEV_ES_TMR_SIZE; } - rc = __sev_do_cmd_locked(SEV_CMD_INIT, &data, &psp_ret); + return __sev_do_cmd_locked(SEV_CMD_INIT_EX, &data, error); +} + +static int __sev_platform_init_locked(int *error) +{ + struct psp_device *psp = psp_master; + struct sev_device *sev; + int rc, psp_ret; + int (*init_function)(int *error); + + if (!psp || !psp->sev_data) + return -ENODEV; + + sev = psp->sev_data; + + if (sev->state == SEV_STATE_INIT) + return 0; + + init_function = sev_init_ex_buffer ? __sev_init_ex_locked : + __sev_init_locked; + rc = init_function(&psp_ret); if (rc && psp_ret == SEV_RET_SECURE_DATA_INVALID) { /* * Initialization command returned an integrity check failure @@ -291,7 +436,7 @@ static int __sev_platform_init_locked(int *error) * with a reset state. */ dev_dbg(sev->dev, "SEV: retrying INIT command"); - rc = __sev_do_cmd_locked(SEV_CMD_INIT, &data, &psp_ret); + rc = init_function(&psp_ret); } if (error) *error = psp_ret; @@ -1066,6 +1211,12 @@ static void sev_firmware_shutdown(struct sev_device *sev) get_order(SEV_ES_TMR_SIZE)); sev_es_tmr = NULL; } + + if (sev_init_ex_buffer) { + free_pages((unsigned long)sev_init_ex_buffer, + get_order(NV_LENGTH)); + sev_init_ex_buffer = NULL; + } } void sev_dev_destroy(struct psp_device *psp) @@ -1110,6 +1261,18 @@ void sev_pci_init(void) 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. + */ + if (init_ex_path) { + sev_init_ex_buffer = sev_fw_alloc(NV_LENGTH); + if (!sev_init_ex_buffer) { + dev_err(sev->dev, + "SEV: INIT_EX NV memory allocation failed\n"); + goto err; + } + } + /* Obtain the TMR memory area for SEV-ES use */ sev_es_tmr = sev_fw_alloc(SEV_ES_TMR_SIZE); if (!sev_es_tmr) diff --git a/include/linux/psp-sev.h b/include/linux/psp-sev.h index d48a7192e881..1595088c428b 100644 --- a/include/linux/psp-sev.h +++ b/include/linux/psp-sev.h @@ -52,6 +52,7 @@ enum sev_cmd { SEV_CMD_DF_FLUSH = 0x00A, SEV_CMD_DOWNLOAD_FIRMWARE = 0x00B, SEV_CMD_GET_ID = 0x00C, + SEV_CMD_INIT_EX = 0x00D, /* Guest commands */ SEV_CMD_DECOMMISSION = 0x020, @@ -102,6 +103,26 @@ struct sev_data_init { u32 tmr_len; /* In */ } __packed; +/** + * struct sev_data_init_ex - INIT_EX command parameters + * + * @length: len of the command buffer read by the PSP + * @flags: processing flags + * @tmr_address: system physical address used for SEV-ES + * @tmr_len: len of tmr_address + * @nv_address: system physical address used for PSP NV storage + * @nv_len: len of nv_address + */ +struct sev_data_init_ex { + u32 length; /* In */ + u32 flags; /* In */ + u64 tmr_address; /* In */ + u32 tmr_len; /* In */ + u32 reserved; /* In */ + u64 nv_address; /* In/Out */ + u32 nv_len; /* In */ +} __packed; + #define SEV_INIT_FLAGS_SEV_ES 0x01 /**