From patchwork Fri Nov 4 23:00:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dionna Amalie Glaze X-Patchwork-Id: 15855 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp687699wru; Fri, 4 Nov 2022 16:03:58 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4D+rObnrda32m8KtU8hGr50MC3ZnmT+odiaE0SQ/uhkZh1+4W49M5ZSCWksWZvHPIKeyuB X-Received: by 2002:a05:6402:1bda:b0:464:4eb2:8c25 with SMTP id ch26-20020a0564021bda00b004644eb28c25mr8594093edb.278.1667603038045; Fri, 04 Nov 2022 16:03:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667603038; cv=none; d=google.com; s=arc-20160816; b=zPM67wjZKsTYVAD5K/JO5MYfriWgLGWKjBIr66yLd8ArXh8GaeRjyMA1JbdJdE5pXP oT5onzNbrpDAcpI2AxmeXcTnT4Slx0P+lJxObO3Y9V6rkcu8wMRxL6ZR+Wl6fMKzgM3K lZxMxlwdDOu9WB6Vi6RGiwhfiyYhDqux7n47Tiz+rOMBJKMVQe8/CbWxDzbeYkL+1/om 37Oj+IQrz1RezQVVv6O8zkzzI0de4JJftVgzfFiBJ4rm3k7j3zADs2FBELEgtVPp22op TPEv0uuqhYGJZChqt7R5Wxet17nMLNFDSYiH6EPLa6jqkp2Si+DWLiPQpQ7Puumi9IKR LwqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=vzksqxZzngSMnVq4LNIxjbY1eQuHqjVmZsqNyLkHpLQ=; b=p4wbSJshCbJrfNvjN3ntg3iPqFFUWM9DvdlXW/pNFZ9TC1YDIxy8f5bMTKrhXs5/Xm spFvbA38AdBFiUkCUGuhhi7LdpJtaAn0ulfYu3tdLTwPaTghGjp77XEhNqFi2/eUaK5C NtkyjQmxcgxiK1GoKzkvcp/REXsTe2gKi2zVOAWdFV5duP9HY9xzNr1LlyloFJ9Opesk IS4niKdi83JpyUfEzgbZVA14R7T0a+SaTDWAS9GG65+T44PLjHvP0EBCgzX6hSjbXoav SDC3bKP0MYsRDnbeu7TSVlGwX8IYOhPsMvCqOBdErUU2BbvOJcw/i6Ji01gGYV4Ns6BV D61A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=BIBsVrxM; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bb6-20020a1709070a0600b007acbaeed9besi403874ejc.398.2022.11.04.16.03.31; Fri, 04 Nov 2022 16:03:58 -0700 (PDT) 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=@google.com header.s=20210112 header.b=BIBsVrxM; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229650AbiKDXBP (ORCPT + 99 others); Fri, 4 Nov 2022 19:01:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229637AbiKDXBH (ORCPT ); Fri, 4 Nov 2022 19:01:07 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 985482FC1B for ; Fri, 4 Nov 2022 16:01:06 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id i8-20020a170902c94800b0018712ccd6bbso4447202pla.1 for ; Fri, 04 Nov 2022 16:01:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=vzksqxZzngSMnVq4LNIxjbY1eQuHqjVmZsqNyLkHpLQ=; b=BIBsVrxM73h3e1apgZ8GqU8UNyKW2HQO0OE44bbRUUT2OwpePR3ksSeoLDIF2AAppi UIvjXfIZw49dRr5/3v10oZ8lc5T4uPjeV/3CGwjrqgx0buubBD8+N4gLUeuJaN0NYmOG OecG9IMwFWLDFm0hRdU8UOZmOh0C6d++yXgxgfV3JZmREWL5YSlUHX+ExpsRQ1FG2Hug fgm3pE7U7RMfGNdDVyG/8tzKc+SHK18KiVIT6HKOW0XsOvxQa3LGQ9HctRR9Pq3gdd/6 7M5H5aK29XyvTmiBstvkHci0qjyG4M91NxCGr+1PprGcPrD0XVSzWCnoKLmhACWt/u6y zJsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=vzksqxZzngSMnVq4LNIxjbY1eQuHqjVmZsqNyLkHpLQ=; b=Or6dpAX2rrQNBsDSS+xyqMFUQZKH29tjlS+BndrKgdaaG2x5p9U8sPQCSknm2btlrm /1YWdpUh2hCzc0H2UM2ZM7J3mZc2RArJo+Npw4NefcHh++P9/0HzD2sVZHa8rPKpi9Vs TQ316UkNPkiAQa8o/EK1RRuwdshBG/SF2GTnIbuQkP2lGLlKPvTKcEi11olKT1E5SC1l zB9Pdtwg4ad/BMeqAss2530JKLFUbvVOGby40mM9jLSbkZPssqRFoZTK46iCpZ3YzI96 D1zTSihHBeQF06qSKDKKQjf955JsYHFqIBBEVIHCw1X0XRhs9Ds5k48/Bh43jR6OymqH FT6w== X-Gm-Message-State: ACrzQf2rN7Ci4n3kjNN2pTzS/ReIqEX6F8Hd1sPexfabgVWb6jwwGDfS FkPX32Ls85p+tmTHBlB15I5osT0iI3JLip8xmDwr6R4L04JD0j3358EnufvUQBFZ7MYzo6TteTm X/FgGgCcHDaOS+0625xlii111eiVlCNGvn7Ah1V6wbw0n2dOwhhsnu26UnAiee7u8KdPg/+WJKO RJ+uSm+yo= X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2ee6]) (user=dionnaglaze job=sendgmr) by 2002:a17:902:a383:b0:187:34f6:439d with SMTP id x3-20020a170902a38300b0018734f6439dmr22005841pla.35.1667602866059; Fri, 04 Nov 2022 16:01:06 -0700 (PDT) Date: Fri, 4 Nov 2022 23:00:37 +0000 In-Reply-To: <20221104230040.2346862-1-dionnaglaze@google.com> Mime-Version: 1.0 References: <20221104230040.2346862-1-dionnaglaze@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221104230040.2346862-2-dionnaglaze@google.com> Subject: [PATCH v8 1/4] crypto: ccp - Name -1 return value as SEV_RET_NO_FW_CALL From: Dionna Glaze To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Peter Gonda , Thomas Lendacky , Paolo Bonzini , Joerg Roedel , Ingo Molnar , Andy Lutomirsky , John Allen , Herbert Xu , "David S. Miller" , Dionna Glaze X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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?1748608523305130687?= X-GMAIL-MSGID: =?utf-8?q?1748608523305130687?= From: Peter Gonda The PSP can return a "firmware error" code of -1 in circumstances where the PSP is not actually called. To make this protocol unambiguous, we add a constant naming the return value. Cc: Thomas Lendacky Cc: Paolo Bonzini Cc: Joerg Roedel Cc: Ingo Molnar Cc: Andy Lutomirsky Cc: John Allen Cc: Herbert Xu Cc: "David S. Miller" Signed-off-by: Peter Gonda Signed-off-by: Dionna Glaze Reviewed-by: Tom Lendacky --- drivers/crypto/ccp/sev-dev.c | 2 +- include/uapi/linux/psp-sev.h | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index 06fc7156c04f..97eb3544ab36 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -444,7 +444,7 @@ static int __sev_platform_init_locked(int *error) { struct psp_device *psp = psp_master; struct sev_device *sev; - int rc = 0, psp_ret = -1; + int rc = 0, psp_ret = SEV_RET_NO_FW_CALL; int (*init_function)(int *error); if (!psp || !psp->sev_data) diff --git a/include/uapi/linux/psp-sev.h b/include/uapi/linux/psp-sev.h index 91b4c63d5cbf..1ad7f0a7e328 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 but is added to convey that + * there was an error that prevented the SEV Firmware from being called. + * This is (u32)-1 since the firmware error code is represented as a + * 32-bit integer. + */ + SEV_RET_NO_FW_CALL = 0xffffffff, SEV_RET_SUCCESS = 0, SEV_RET_INVALID_PLATFORM_STATE, SEV_RET_INVALID_GUEST_STATE, From patchwork Fri Nov 4 23:00:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dionna Amalie Glaze X-Patchwork-Id: 15854 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp687677wru; Fri, 4 Nov 2022 16:03:53 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7ZB/psZnOrfiSC5SvXna3gVucGcEkEbyMQFpcgGUg/7MfcOvfLvYYZDQcOryUR7Cz4bG1V X-Received: by 2002:a17:90b:4c8c:b0:214:9a:1fd0 with SMTP id my12-20020a17090b4c8c00b00214009a1fd0mr24287957pjb.219.1667603032947; Fri, 04 Nov 2022 16:03:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667603032; cv=none; d=google.com; s=arc-20160816; b=WJ1KxHKID1ROq4D/J3Pz7BF27ALtZ7Fb2wifP7GZ2NlESqbWT0d+I4TFDOdcNAYMIK d0V7jZjoWnAQ9DZ3zLdTN7/PzvGk/ELT6aVkcewLd6QL/iplZsMC021CMMAPwFyMWrEV xj4ZNxCBtLyUAaeCLeqw8LD8vaCSnw8owekkcjxUKYHJBAIUP0aNoGtPLfHvZdiKM/qg kGmUHtU4cV4s7pIj1Eu/7uDS3bymetkPYNIdOl5hr/MPkEUknM3lEgjc/QEB82kgLiyp uCZy5jy7LpDOyi4FDG+xAX+mnHd/DFNHotkpVKRKiORxdCPanfAwhkX5lkMc35JmkH/D YKmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=Kw7Ul5f27jSNcm6KBKc7sXnYAWm8yJrh7zk3qUYUCYY=; b=A2irDyzyQHtYhusVj/9ROL3ZvPqfvlAsSAKejCBWiHvJhJraw8I8amzztDxs7ThdBY HeYkX1RfQHBOxqkP005wChLMb+U/zd6AOQLLOwaTvZW7xpeo/8NoZjUCLFqF7yWVQTt4 YYFVxpgjUKCGeLdKbytS8V3T+PdVK1gLvaebPWAUXNehu7w3xVTYAsXrhjrvZjxx6Fom mzk9Tl2Sqnzw0vQPhHPdBxlvARMH/qUihvt2BpEj3/228Z1Bm11TKjrBxFUXgqVFHZe3 39BmQMfGmur/EJ48+XJgPaFkXtr+6AeTLcqSunOF55O36G32f2NU/wSg0BI3wnKON15c 4A3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=NlPGhgvF; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id li4-20020a17090b48c400b00212d2bf21b1si925395pjb.85.2022.11.04.16.03.38; Fri, 04 Nov 2022 16:03:52 -0700 (PDT) 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=@google.com header.s=20210112 header.b=NlPGhgvF; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229750AbiKDXB0 (ORCPT + 99 others); Fri, 4 Nov 2022 19:01:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229648AbiKDXBK (ORCPT ); Fri, 4 Nov 2022 19:01:10 -0400 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 A7C6C3E0BA for ; Fri, 4 Nov 2022 16:01:08 -0700 (PDT) Received: by mail-pf1-x449.google.com with SMTP id c207-20020a624ed8000000b0056e3714b62cso3114609pfb.23 for ; Fri, 04 Nov 2022 16:01:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Kw7Ul5f27jSNcm6KBKc7sXnYAWm8yJrh7zk3qUYUCYY=; b=NlPGhgvFhgizmyfECX4w9dH+W71TLd53j/SkWsyH79fK6UXxTOSVKD60MyicENNua+ fanr9U2tuMz5tIrVWxSdV1MuPA+JAbYFYTvTNWM7UGCoNf3/dYM4yUxmIQYV7cDz6qzJ j3icOp356QVqhXzDGqxk5EOKJEJjbg8COlRDHtmH20R7+F2/DijxBAeEe0pbT0yjxyGN /GJ95mu7VmO5SUWpXSXx80JMaQGEnBxAZRtp/14RUYQPUiEUvzl3mjzsd+InVHe/eYHh oTZUarN2+x+hqXOtd+A/d7OPb4mwNr2XOXwlsh3VLDQ7Yy/D5h6sMuBYji9pLj1v3svU spog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Kw7Ul5f27jSNcm6KBKc7sXnYAWm8yJrh7zk3qUYUCYY=; b=hy0DPyJ+X3dLRndYS+IDO0i0YBDIRsTfM5Ua0wx9pTDMrG53IhMpPC4Md9WNlbZ0To hA/kcf5aq0dPbe6sPAK1xcoL99xSTzK6CU86aZ3sJYmRZwn3kCbdZIEy+gntyqe4OHBf YJFp4YkS0aKkHiLDaYzIaciU6Rv6Kx3lZa2v2zAYtal96f6sPfyM6Ijfj9Eoa1PWsa2Q mYBbq6FAjNUgSTjh5rKmhryaTq7mGylFE7klidA2F5QuLHdYgg5TxL14JJany6NUFIvu SyklE2/Otvfut77nkulinB+O6GEaFqX7AmmnznYWlMCqo4mUQD7HkZXR8S0L0eIi6y9B 4vzA== X-Gm-Message-State: ACrzQf0gloTTGjfuXMAhFe8fTlGBzk1cyGEVO9cXy+RsMPzFDf1n8wqg XefaCigztvK3XfC3yKnq2SmBV1QJ3nbgQXp1Z93xrr1JpBdg21LcSwU46tN+l3FPnWUYzA05mEk iQobrH9Uq63s5SwZsHJ/cuPYTdiduXEZ6vSTgE5jyxSg7fbMf5sDJv6iD+260cvJlVqYoFlltje JqHoevh3M= X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2ee6]) (user=dionnaglaze job=sendgmr) by 2002:a17:90a:4745:b0:214:100a:65c8 with SMTP id y5-20020a17090a474500b00214100a65c8mr22020175pjg.105.1667602868066; Fri, 04 Nov 2022 16:01:08 -0700 (PDT) Date: Fri, 4 Nov 2022 23:00:38 +0000 In-Reply-To: <20221104230040.2346862-1-dionnaglaze@google.com> Mime-Version: 1.0 References: <20221104230040.2346862-1-dionnaglaze@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221104230040.2346862-3-dionnaglaze@google.com> Subject: [PATCH v8 2/4] x86/sev: Change snp_guest_issue_request's fw_err From: Dionna Glaze To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Dionna Glaze , Tom Lendacky , Paolo Bonzini , Joerg Roedel , Peter Gonda , Thomas Gleixner , Dave Hansen , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Venu Busireddy , Michael Roth , "Kirill A. Shutemov" , Michael Sterritt X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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?1748608517592747340?= X-GMAIL-MSGID: =?utf-8?q?1748608517592747340?= The GHCB specification declares that the firmware error value for a guest request will be stored in the lower 32 bits of EXIT_INFO_2. The upper 32 bits are for the VMM's own error code. The fw_err argument is thus a misnomer, and callers will need access to all 64 bits. The type of unsigned long also causes problems, since sw_exit_info2 is u64 (unsigned long long) vs the argument's previous unsigned long*. The signature change requires the follow-up change to drivers/virt/coco/sev-guest to use the new expected type in order to compile. The firmware might not even be called, so we bookend the call with the no firmware call error and clearing the error. Cc: Tom Lendacky Cc: Paolo Bonzini Cc: Joerg Roedel Cc: Peter Gonda Cc: Thomas Gleixner Cc: Dave Hansen Cc: Ingo Molnar Cc: Borislav Petkov Cc: "H. Peter Anvin" Cc: Venu Busireddy Cc: Michael Roth Cc: "Kirill A. Shutemov" Cc: Michael Sterritt Fixes: d5af44dde546 ("x86/sev: Provide support for SNP guest request NAEs") Signed-off-by: Dionna Glaze Reviewed-by: Peter Gonda --- arch/x86/include/asm/sev.h | 4 ++-- arch/x86/kernel/sev.c | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index ebc271bb6d8e..05de34d10d89 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -196,7 +196,7 @@ void snp_set_memory_private(unsigned long vaddr, unsigned int npages); void snp_set_wakeup_secondary_cpu(void); bool snp_init(struct boot_params *bp); void __init __noreturn snp_abort(void); -int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, unsigned long *fw_err); +int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, u64 *exitinfo2); #else static inline void sev_es_ist_enter(struct pt_regs *regs) { } static inline void sev_es_ist_exit(void) { } @@ -217,7 +217,7 @@ static inline void snp_set_wakeup_secondary_cpu(void) { } static inline bool snp_init(struct boot_params *bp) { return false; } static inline void snp_abort(void) { } static inline int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, - unsigned long *fw_err) + u64 *exitinfo2) { return -ENOTTY; } diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index a428c62330d3..148f17cb07b5 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -2175,7 +2176,7 @@ static int __init init_sev_config(char *str) } __setup("sev=", init_sev_config); -int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, unsigned long *fw_err) +int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, u64 *exitinfo2) { struct ghcb_state state; struct es_em_ctxt ctxt; @@ -2186,9 +2187,11 @@ int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, unsigned if (!cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) return -ENODEV; - if (!fw_err) + if (!exitinfo2) return -EINVAL; + *exitinfo2 = SEV_RET_NO_FW_CALL; + /* * __sev_get_ghcb() needs to run with IRQs disabled because it is using * a per-CPU GHCB. @@ -2212,14 +2215,13 @@ int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, unsigned if (ret) goto e_put; + *exitinfo2 = ghcb->save.sw_exit_info_2; if (ghcb->save.sw_exit_info_2) { /* Number of expected pages are returned in RBX */ if (exit_code == SVM_VMGEXIT_EXT_GUEST_REQUEST && ghcb->save.sw_exit_info_2 == SNP_GUEST_REQ_INVALID_LEN) input->data_npages = ghcb_get_rbx(ghcb); - *fw_err = ghcb->save.sw_exit_info_2; - ret = -EIO; } From patchwork Fri Nov 4 23:00:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dionna Amalie Glaze X-Patchwork-Id: 15856 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp688140wru; Fri, 4 Nov 2022 16:05:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5y3p56TS7DI0MWTsjLr3Unyzo+tgpidOScJ+VpdHmhUJh7NpK7Iza8gmfAJG/YQt4LxCbK X-Received: by 2002:aa7:da84:0:b0:463:7873:119a with SMTP id q4-20020aa7da84000000b004637873119amr26815536eds.329.1667603102394; Fri, 04 Nov 2022 16:05:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667603102; cv=none; d=google.com; s=arc-20160816; b=sfqwmLq6R6NP7j0v+Q1EK/Nzauw0tXGVZvI4Bn8dg7AL15jSjap8Nef9wPmTC4GlJv VXoLMFlm0FVSgFqkN94f8gG6gZOHmLPH2Z7QpTW78C/Yfs4Mzgr3ZmMsYbBud+SOVELB vu57OJGUlFaNZI+DiO+OJ5xN3F53/7AuauEMKK5Qmam7Vt20GmneGDxdluMwubLoUSv/ j+gm8Ko4lqm8dBtjWFegLsx8Xyhm+K2/mrZV5ysGLnQjUgaNRgfLkk+V5/5jchuY/edF 7MqYfUb39Wi5LY7MT7TrxuBOAJ7Hlg6F1K9djBlUf0d5R02iNVzTykaJKtfvAu/KuK79 FrxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=cdK/VRyCPwKThqqRcg2usy4G2FHLW3I2lPiI0d9S9hA=; b=NSvDgJ9vBEkvh1H+nd9C2UpT6Aw24wCT00d2QvpwTh0NdHdj68O2Ba0azDmvEIc3RO 9HvHF+Wx95EFxfmZLUEtW+cVr3vCDPm1BXSk4wG9PRDiiQ8pEF4KvyA6pISf6VB5U81r D0qkuZSSORJEu02lx7XWrKMI8QqqI5OmZ8a6cWGTx9DFw7wr0j1yIieXdIFAWZnCoHPX OvsWMuqE2bjYzeePpJW25igM50FFymR4KUYDOp6V1NlKiqAXR6NV82hEgxvIyf3C5KXd gkCeCPsFgpp2z0ri3iE9VVRQoLkc82FvFmIetFsQQmJadUrVXC2oBl45h3KT62mp4r7j IfmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=C7B2GiAC; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u18-20020a170906b11200b00780f0b45416si264624ejy.622.2022.11.04.16.04.38; Fri, 04 Nov 2022 16:05:02 -0700 (PDT) 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=@google.com header.s=20210112 header.b=C7B2GiAC; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229662AbiKDXB3 (ORCPT + 99 others); Fri, 4 Nov 2022 19:01:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229523AbiKDXBM (ORCPT ); Fri, 4 Nov 2022 19:01:12 -0400 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D589142F6A for ; Fri, 4 Nov 2022 16:01:10 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id t3-20020a170902e84300b00186ab03043dso4504759plg.20 for ; Fri, 04 Nov 2022 16:01:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=cdK/VRyCPwKThqqRcg2usy4G2FHLW3I2lPiI0d9S9hA=; b=C7B2GiACclUr4bSg9eCOuhvdwXQYkHErdquyDfYepWM9YWiqvNxBWnp29ohwvvLYN4 GnDjmvJX5GD3n177DQptp7GYjzQGqISK8F8yU4xsUd6iy1ZGj6NqGpebAGtNt4RFPK4T IE+V7+os77Wmpj6D91LoVxk5YMR3Y2p5d1/WWEUo7glcCyu66lPXC3r5o0LW3+IAsmDg nWh0zX9F1uzSo0YmRLBjGB6e7YoRxPB4FeH4lheU7UbCfRTDwws40b9ax/2P5LCCVBLX sXJq81RnQjUEaF9nSzceSAXsNNUQ+G7bOnIXJ4broNDCJEzpfGZJGFeYkBVSri4SSF35 BcCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cdK/VRyCPwKThqqRcg2usy4G2FHLW3I2lPiI0d9S9hA=; b=MW2Yl6cXZNNH8RFX8OJH+IP+zxm+kJVdrtW7+tZoM7YZLctE+3cf/Xu36RVAQrILus QzK9aAt8/QK0/3ru0Ks5VQO3O9U0aVZUXG2t2zcoJFqiRQ3JtR+fq2r7TzCZdTTB77tW WzzaWG0ONhv6pwekfgSXtVu3JjwU7toshlfSopBl8pZ/s4keV2jNO7yFIOy1YucWNlYv +KlgEQ5VoYqUlQREiSeToTFdjK9Fbd+Ndxb1G8ZnXAsNYhD4PRy7It1zQXCyCgTavY26 JPbE36rySvBYR1okWJcu7u1kkIyuUzxN5/tiFqRv7lFD9SbmyIR0zckKyTGBS1nl5uG1 oBwg== X-Gm-Message-State: ACrzQf3tgJS8SanrNWaFgyOjoHg89yTdhouHy6xWZA8u7u+17gQTvzoB rBDuKpxzHoRPuarjIzKS0qk9CqpOA36XRC2KpF9bRN/gke3bO2SKe1wJCywvxFvTcqJVjVQd8pR R/o6TmoDBo26N5hdNODuC7f4bssHWz786goaBqoITcZX1yR2KNHE2xep/bHHU0wH91HWEBdXWrD 6DipELZA4= X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2ee6]) (user=dionnaglaze job=sendgmr) by 2002:a17:90b:1881:b0:213:1f29:2d0a with SMTP id mn1-20020a17090b188100b002131f292d0amr396847pjb.154.1667602869918; Fri, 04 Nov 2022 16:01:09 -0700 (PDT) Date: Fri, 4 Nov 2022 23:00:39 +0000 In-Reply-To: <20221104230040.2346862-1-dionnaglaze@google.com> Mime-Version: 1.0 References: <20221104230040.2346862-1-dionnaglaze@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221104230040.2346862-4-dionnaglaze@google.com> Subject: [PATCH v8 3/4] virt: sev-guest: Remove err in handle_guest_request From: Dionna Glaze To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Dionna Glaze , Tom Lendacky , Paolo Bonzini , Joerg Roedel , Peter Gonda , Thomas Gleixner , Dave Hansen , Borislav Petkov , Haowen Bai , Liam Merwick , Yang Yingliang X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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?1748608590633127700?= X-GMAIL-MSGID: =?utf-8?q?1748608590633127700?= The err variable may not be set in the call to snp_issue_guest_request, yet it is unconditionally written back to fw_err if fw_err is non-null. This is undefined behavior, and currently returns uninitialized kernel stack memory to user space. The fw_err argument is better to just pass through to snp_issue_guest_request, so we do that by passing along the ioctl argument. This removes the need for an argument to handle_guest_request. Cc: Tom Lendacky Cc: Paolo Bonzini Cc: Joerg Roedel Cc: Peter Gonda Cc: Thomas Gleixner Cc: Dave Hansen Cc: Borislav Petkov Cc: Haowen Bai Cc: Liam Merwick Cc: Yang Yingliang Fixes: fce96cf04430 ("virt: Add SEV-SNP guest driver") Signed-off-by: Dionna Glaze Reviewed-by: Peter Gonda Reviewed-by: Tom Lendacky --- drivers/virt/coco/sev-guest/sev-guest.c | 37 ++++++++++++------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/sev-guest/sev-guest.c index d08ff87c2dac..5615d349b378 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -320,11 +320,11 @@ static int enc_payload(struct snp_guest_dev *snp_dev, u64 seqno, int version, u8 return __enc_payload(snp_dev, req, payload, sz); } -static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, int msg_ver, +static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, + struct snp_guest_request_ioctl *arg, u8 type, void *req_buf, size_t req_sz, void *resp_buf, - u32 resp_sz, __u64 *fw_err) + u32 resp_sz) { - unsigned long err; u64 seqno; int rc; @@ -336,12 +336,14 @@ static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, in memset(snp_dev->response, 0, sizeof(struct snp_guest_msg)); /* Encrypt the userspace provided payload */ - rc = enc_payload(snp_dev, seqno, msg_ver, type, req_buf, req_sz); + rc = enc_payload(snp_dev, seqno, arg->msg_version, type, req_buf, + req_sz); if (rc) return rc; /* Call firmware to process the request */ - rc = snp_issue_guest_request(exit_code, &snp_dev->input, &err); + rc = snp_issue_guest_request(exit_code, &snp_dev->input, + &arg->fw_err); /* * If the extended guest request fails due to having to small of a @@ -349,23 +351,21 @@ static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, in * extended data request. */ if (exit_code == SVM_VMGEXIT_EXT_GUEST_REQUEST && - err == SNP_GUEST_REQ_INVALID_LEN) { + arg->fw_err == SNP_GUEST_REQ_INVALID_LEN) { const unsigned int certs_npages = snp_dev->input.data_npages; exit_code = SVM_VMGEXIT_GUEST_REQUEST; - rc = snp_issue_guest_request(exit_code, &snp_dev->input, &err); + rc = snp_issue_guest_request(exit_code, &snp_dev->input, + &arg->fw_err); - err = SNP_GUEST_REQ_INVALID_LEN; + arg->fw_err = SNP_GUEST_REQ_INVALID_LEN; snp_dev->input.data_npages = certs_npages; } - if (fw_err) - *fw_err = err; - if (rc) { dev_alert(snp_dev->dev, "Detected error from ASP request. rc: %d, fw_err: %llu\n", - rc, *fw_err); + rc, arg->fw_err); goto disable_vmpck; } @@ -412,9 +412,9 @@ static int get_report(struct snp_guest_dev *snp_dev, struct snp_guest_request_io if (!resp) return -ENOMEM; - rc = handle_guest_request(snp_dev, SVM_VMGEXIT_GUEST_REQUEST, arg->msg_version, + rc = handle_guest_request(snp_dev, SVM_VMGEXIT_GUEST_REQUEST, arg, SNP_MSG_REPORT_REQ, &req, sizeof(req), resp->data, - resp_len, &arg->fw_err); + resp_len); if (rc) goto e_free; @@ -452,9 +452,8 @@ static int get_derived_key(struct snp_guest_dev *snp_dev, struct snp_guest_reque if (copy_from_user(&req, (void __user *)arg->req_data, sizeof(req))) return -EFAULT; - rc = handle_guest_request(snp_dev, SVM_VMGEXIT_GUEST_REQUEST, arg->msg_version, - SNP_MSG_KEY_REQ, &req, sizeof(req), buf, resp_len, - &arg->fw_err); + rc = handle_guest_request(snp_dev, SVM_VMGEXIT_GUEST_REQUEST, arg, + SNP_MSG_KEY_REQ, &req, sizeof(req), buf, resp_len); if (rc) return rc; @@ -514,9 +513,9 @@ static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_reques return -ENOMEM; snp_dev->input.data_npages = npages; - ret = handle_guest_request(snp_dev, SVM_VMGEXIT_EXT_GUEST_REQUEST, arg->msg_version, + ret = handle_guest_request(snp_dev, SVM_VMGEXIT_EXT_GUEST_REQUEST, arg, SNP_MSG_REPORT_REQ, &req.data, - sizeof(req.data), resp->data, resp_len, &arg->fw_err); + sizeof(req.data), resp->data, resp_len); /* If certs length is invalid then copy the returned length */ if (arg->fw_err == SNP_GUEST_REQ_INVALID_LEN) { From patchwork Fri Nov 4 23:00:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dionna Amalie Glaze X-Patchwork-Id: 15857 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp688529wru; Fri, 4 Nov 2022 16:05:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6SohuOndd6IvXRg9yG+aIdDw4cWuKgyShg8P0ihW8wGZfgK7KeFmJjuQFWgoE2Fri4TGyY X-Received: by 2002:a17:902:f605:b0:186:6feb:7eb4 with SMTP id n5-20020a170902f60500b001866feb7eb4mr37528613plg.134.1667603139606; Fri, 04 Nov 2022 16:05:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667603139; cv=none; d=google.com; s=arc-20160816; b=AzKgBawJ8ozHpY+VhvK7jxW1L8OglufaufrhXlHcDw6UtoFL79Was59vj/zYkbLstz 9OrW5XQjoWRD6Fy3uhmyJZOmcH0mJuOUThp2FyFT32X+cX92iam14a9TPlcbVR+/805f gPmFvOUAokOJvJWdqOcHUdPuUOVtpU+j0kr75uHCOli+W7Y6lQ1lUjztcM/vUKQyqlqp N/0C1pL9wkHjST6yyo8v9CBNTMxdPLohhq7GlG3xuW2/n3ZErm4xZcuKTpWmC5T4Dxah YEjjG3UKOwXcfdzCwRbKTxM+OQkAoacNX4tDfygTmWVNknlkoF2K5GE2hJxGuwnvx8+b +TzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=U1B6bg0/4gt5SV65d/ktqlMru3581z5R83TjA3sPr58=; b=OgKI0Qiwc6masA4ZwEA32hxpzAQbWPADN0FrNBURGuaSpelEPMJRfPlndsmJZutIAA sN8sF1oq6tSq3PC6BZrXbsr7rqD9ptXp29i2dU488UCbuwd7QTBaKlvm4AmkLiVHLl43 Ju55bcpQD5BpftVDJXz7TUaNZaXEz6tqH+BwcCR/lSKRbEUXq/2fHCQFEVqt7NaybFXY CKwDv32vI3bW2uuiSSNLqjxcUoBpyGe2UpgNkfBagnQxL2vtI/tF4BtDM52pcMjRjc+W M1uuq/7WnQgrrcE0yCCkU/xLzOQEFGAAr8KrU52fIl+bB29uNJcQ7eqEwQPvlBxS8HhT 3Dzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=RjgBpaTz; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id li4-20020a17090b48c400b00212d2bf21b1si925395pjb.85.2022.11.04.16.05.24; Fri, 04 Nov 2022 16:05:39 -0700 (PDT) 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=@google.com header.s=20210112 header.b=RjgBpaTz; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229608AbiKDXBd (ORCPT + 99 others); Fri, 4 Nov 2022 19:01:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229642AbiKDXBP (ORCPT ); Fri, 4 Nov 2022 19:01:15 -0400 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 88F534090F for ; Fri, 4 Nov 2022 16:01:13 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id my9-20020a17090b4c8900b002130d29fd7cso6282919pjb.7 for ; Fri, 04 Nov 2022 16:01:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=U1B6bg0/4gt5SV65d/ktqlMru3581z5R83TjA3sPr58=; b=RjgBpaTzWWE7Wem4Ad1h+0w0yWytdCt0H+nmLMsNbpNoDv83vWEDTwTRH7BE/lMNu6 YR/R2SYKF4NsTtGAhrJFvryv5WBOaNnth8PJD4jtPt0D8omx0df2m74V7T/8ifKO8UpP jA5WNSvRNCelax8WJIoNXExY69oEchfmAXrDrP27HhajLcmUZhEoKzIgP92GEYn2/QbD HPptYFWI2xRGTlHpkmRTXzNKplV5TOxuQf8AQ1XQW1SGiaSUTtu8kYIW1u3Wa1tT8qFO sji+u6CJUR/FWblJqpFF9AS2Kk6RrZJW0yJ7JtBWI+29h+CuGz4zPAMwNy+USyLGVmb4 Eh3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=U1B6bg0/4gt5SV65d/ktqlMru3581z5R83TjA3sPr58=; b=F4vC81XNhglcBWecDZs1jcL7wQ2vUT5Y6hNmOCQ4OoRv6ISAoVXW8H/Dk+1niNY4PW pE49ZHaNOqFpRFPijF4Zh5tOuuuikoJKUrhowRSoB3xE3hwwmJiKYGEA2jBlkevH8kSq eqgJzpzJyQrCzNO3NasoTj9JjyMh4LZw+LwKqrdqrWW+lTed2s+19p25DS/AGah7leBV kVUc0bcr28mcFSPCG2f19UvZU3xa2Dy3LoaqIoCFm/LIQccy82i2691HJTbyztUYBJRh eTxfSXCOMWYHTLmQXMswVVqp4hjHeHtY7zAWBbjquQSXiBgfnZKfjx5+4nO5/EVgdTuD jAfA== X-Gm-Message-State: ANoB5pkXHQeAKBHmG3bf9T/3mT6LYMAM0rnrvA3wbIpCtj8vJ8/EhwX4 4tSVcc9jNmMNbY9/KeNkEwxzitniwf6EXbESN6+CkFEhynsRvt4jtPHYaZTpgMNzqKsgbBth0B1 auvCr436sDsrD/AaXa80KFzVB7PaMsZqget79uLJvi34g469Yc5bOFgrgkl3x3ESfIYKPTcW+nw UXSHBpbfQ= X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2ee6]) (user=dionnaglaze job=sendgmr) by 2002:a17:90b:1081:b0:20a:fee1:8f69 with SMTP id gj1-20020a17090b108100b0020afee18f69mr187016pjb.0.1667602871519; Fri, 04 Nov 2022 16:01:11 -0700 (PDT) Date: Fri, 4 Nov 2022 23:00:40 +0000 In-Reply-To: <20221104230040.2346862-1-dionnaglaze@google.com> Mime-Version: 1.0 References: <20221104230040.2346862-1-dionnaglaze@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221104230040.2346862-5-dionnaglaze@google.com> Subject: [PATCH v8 4/4] virt: sev-guest: interpret VMM errors from guest request From: Dionna Glaze To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Dionna Glaze , Tom Lendacky , Peter Gonda , Borislav Petkov , Tom Lendacky , Liam Merwick , Yang Yingliang , Haowen Bai X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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?1748608630077239386?= X-GMAIL-MSGID: =?utf-8?q?1748608630077239386?= The GHCB specification states that the upper 32 bits of exitinfo2 are for the VMM's error codes. The sev-guest ABI has already locked in that the fw_err status of the input will be 64 bits, and that BIT_ULL(32) means that the extended guest request's data buffer was too small, so we have to keep that ABI. We can still interpret the upper 32 bits of exitinfo2 for the user anyway in case the request gets throttled. For safety, since the encryption algorithm in GHCBv2 is AES_GCM, we cannot return to user space without having completed the request with the current sequence number. If we were to return and the guest were to make another request but with different message contents, then that would be IV reuse. When throttled, the driver will reschedule itself and then try again after sleeping half its ratelimit time to avoid a big wait queue. The ioctl may block indefinitely, but that has always been the case when deferring these requests to the host. Cc: Tom Lendacky Cc: Peter Gonda Cc: Borislav Petkov Cc: Tom Lendacky Cc: Liam Merwick Cc: Yang Yingliang Cc: Haowen Bai Signed-off-by: Dionna Glaze Reviewed-by: Peter Gonda Tested-by: Peter Gonda Reviewed-by: Tom Lendacky --- drivers/virt/coco/sev-guest/sev-guest.c | 49 ++++++++++++++++++++----- include/uapi/linux/sev-guest.h | 18 ++++++++- 2 files changed, 56 insertions(+), 11 deletions(-) diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/sev-guest/sev-guest.c index 5615d349b378..e8a9c07ea897 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -48,12 +49,22 @@ struct snp_guest_dev { struct snp_req_data input; u32 *os_area_msg_seqno; u8 *vmpck; + + struct ratelimit_state rs; }; static u32 vmpck_id; module_param(vmpck_id, uint, 0444); MODULE_PARM_DESC(vmpck_id, "The VMPCK ID to use when communicating with the PSP."); +static int rate_s = 1; +module_param(rate_s, int, 0444); +MODULE_PARM_DESC(rate_s, "The rate limit interval in seconds to limit requests to."); + +static int rate_burst = 2; +module_param(rate_burst, int, 0444); +MODULE_PARM_DESC(rate_burst, "The rate limit burst amount to limit requests to."); + /* Mutex to serialize the shared buffer access and command handling. */ static DEFINE_MUTEX(snp_cmd_mutex); @@ -341,9 +352,27 @@ static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, if (rc) return rc; +retry: + /* + * Rate limit commands internally since the host can also throttle, and + * we don't want to create a tight request spin that could end up + * getting this VM throttled more heavily. + */ + if (!__ratelimit(&snp_dev->rs)) { + schedule_timeout_interruptible((rate_s * HZ) / 2); + goto retry; + } /* Call firmware to process the request */ rc = snp_issue_guest_request(exit_code, &snp_dev->input, - &arg->fw_err); + &arg->exitinfo2); + + /* + * The host may return EBUSY if the request has been throttled. + * We retry in the driver to avoid returning and reusing the message + * sequence number on a different message. + */ + if (arg->vmm_error == SNP_GUEST_VMM_ERR_BUSY) + goto retry; /* * If the extended guest request fails due to having to small of a @@ -351,21 +380,21 @@ static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, * extended data request. */ if (exit_code == SVM_VMGEXIT_EXT_GUEST_REQUEST && - arg->fw_err == SNP_GUEST_REQ_INVALID_LEN) { + arg->vmm_error == SNP_GUEST_VMM_ERR_INVALID_LEN) { const unsigned int certs_npages = snp_dev->input.data_npages; exit_code = SVM_VMGEXIT_GUEST_REQUEST; rc = snp_issue_guest_request(exit_code, &snp_dev->input, - &arg->fw_err); + &arg->exitinfo2); - arg->fw_err = SNP_GUEST_REQ_INVALID_LEN; + arg->vmm_error = SNP_GUEST_VMM_ERR_INVALID_LEN; snp_dev->input.data_npages = certs_npages; } if (rc) { dev_alert(snp_dev->dev, - "Detected error from ASP request. rc: %d, fw_err: %llu\n", - rc, arg->fw_err); + "Detected error from ASP request. rc: %d, exitinfo2: %llu\n", + rc, arg->exitinfo2); goto disable_vmpck; } @@ -518,7 +547,7 @@ static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_reques sizeof(req.data), resp->data, resp_len); /* If certs length is invalid then copy the returned length */ - if (arg->fw_err == SNP_GUEST_REQ_INVALID_LEN) { + if (arg->vmm_error == SNP_GUEST_VMM_ERR_INVALID_LEN) { req.certs_len = snp_dev->input.data_npages << PAGE_SHIFT; if (copy_to_user((void __user *)arg->req_data, &req, sizeof(req))) @@ -553,7 +582,7 @@ static long snp_guest_ioctl(struct file *file, unsigned int ioctl, unsigned long if (copy_from_user(&input, argp, sizeof(input))) return -EFAULT; - input.fw_err = 0xff; + input.exitinfo2 = SEV_RET_NO_FW_CALL; /* Message version must be non-zero */ if (!input.msg_version) @@ -584,7 +613,7 @@ static long snp_guest_ioctl(struct file *file, unsigned int ioctl, unsigned long mutex_unlock(&snp_cmd_mutex); - if (input.fw_err && copy_to_user(argp, &input, sizeof(input))) + if (input.exitinfo2 && copy_to_user(argp, &input, sizeof(input))) return -EFAULT; return ret; @@ -734,6 +763,8 @@ static int __init sev_guest_probe(struct platform_device *pdev) if (ret) goto e_free_cert_data; + ratelimit_state_init(&snp_dev->rs, rate_s * HZ, rate_burst); + dev_info(dev, "Initialized SEV guest driver (using vmpck_id %d)\n", vmpck_id); return 0; diff --git a/include/uapi/linux/sev-guest.h b/include/uapi/linux/sev-guest.h index 256aaeff7e65..8e4144aa78c9 100644 --- a/include/uapi/linux/sev-guest.h +++ b/include/uapi/linux/sev-guest.h @@ -52,8 +52,15 @@ struct snp_guest_request_ioctl { __u64 req_data; __u64 resp_data; - /* firmware error code on failure (see psp-sev.h) */ - __u64 fw_err; + /* bits[63:32]: VMM error code, bits[31:0] firmware error code (see psp-sev.h) */ + union { + __u64 exitinfo2; + __u64 fw_err; /* Name deprecated in favor of others */ + struct { + __u32 fw_error; + __u32 vmm_error; + }; + }; }; struct snp_ext_report_req { @@ -77,4 +84,11 @@ struct snp_ext_report_req { /* Get SNP extended report as defined in the GHCB specification version 2. */ #define SNP_GET_EXT_REPORT _IOWR(SNP_GUEST_REQ_IOC_TYPE, 0x2, struct snp_guest_request_ioctl) +/* Guest message request EXIT_INFO_2 constants */ +#define SNP_GUEST_FW_ERR_MASK GENMASK_ULL(31, 0) +#define SNP_GUEST_VMM_ERR_SHIFT 32 + +#define SNP_GUEST_VMM_ERR_INVALID_LEN 1 +#define SNP_GUEST_VMM_ERR_BUSY 2 + #endif /* __UAPI_LINUX_SEV_GUEST_H_ */