From patchwork Fri Nov 4 20:16:13 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: 15781 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp618512wru; Fri, 4 Nov 2022 13:19:47 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7K+HTT3xAzOxhMD3EhULW4MehorfsOzVfm+7KaXlvD5Rb5cPHNF5rfxwEWKrJ6YTILnZVO X-Received: by 2002:a17:907:a087:b0:7ae:45f2:bf2d with SMTP id hu7-20020a170907a08700b007ae45f2bf2dmr1014587ejc.456.1667593187194; Fri, 04 Nov 2022 13:19:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667593187; cv=none; d=google.com; s=arc-20160816; b=aN4+BA5pidFEaGf9tDTM6vhoKItYH408DcU9598LznNEk3p4rY3jYzWfVW0SM/k+25 GAZ8rvTz7lWsflVacQhi3vezxpl4jAhh2Bs7jWHs7bH7BdTHuUC9eA/1Cw1OHYrqj/6L ptMoPqHKEok8/6HfRUqCZLcKfIdLqRBYCPA+B4LKWB6QzjtFfOkx26dbR4RV1Ip1rxkO a76sry91CRQrmX8UNleOyO0xXwsUOUd/4aeYSSw8ddo+9qdI6C4pY2y4Eap1yypo+gih 2bvq91MqCiyQcX0Vl+sIQfhzqTJGUwjXBbepFp4t8DgQ98xjyBetnLrmpe53hbGGW3xk VDwQ== 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=MmP4eJ0MM80PCYvy/BR09L1psaJLvpWPD0ZjpQk1nKjAyEFhmwPFiBen3xt4ox2O6h x5AxGExIWzOvGTrdW8LH1GIaJr7q9iUusbIX34I+8TkXn0AslE9tx33eNzKuNLP7ajCp XOdOzI9Dqr3vM9ou5BBvShL4u9Aehk6unHV13sLVXs/AkN4YAG5QOxN/E/JfzrOSMXa2 SbhrmrLr4yObc1ImXY/505guBaFd5AN46pFDUT0zsr+HqBoPHNKdifsZ9stwOFgqPne4 xAh/HiXra4p/6jqBwiNURn+BnHYw91s8hDvOl3MocbHwwkvlxA1G0YvHee8F8NnLr1Bz tYuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=jhPIbPD5; 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 gb15-20020a170907960f00b0073dcb2ec4d2si5311613ejc.889.2022.11.04.13.19.23; Fri, 04 Nov 2022 13:19:47 -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=jhPIbPD5; 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 S229909AbiKDUQc (ORCPT + 99 others); Fri, 4 Nov 2022 16:16:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229866AbiKDUQb (ORCPT ); Fri, 4 Nov 2022 16:16:31 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A14D45ECA for ; Fri, 4 Nov 2022 13:16:30 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-3697bd55974so55304827b3.15 for ; Fri, 04 Nov 2022 13:16:30 -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=jhPIbPD5BQTq81GOSTK237jTlF2fdO6oPYPy+cM2vMFS3sS/w17VHxLXqWaLre2baw Dg7vRG1TECmSbDjloLx5MYR0wTohEYRdFSI6Le9y/hLxMWYStbgHTcS/8BEY0Mye6mQM 5RcisHx3NbfpWxsqiQ73t9SFwtfVCqnRVuNd39fTiWo93R/G3mXGXiaoqMQS7qT7C49Z /RffMJbCcphU6MVtcGMdXHMCWzCx/6NfqoO7JfmYlrdAkYtyB7WlsWnIPM+KAVphsdCM +9Rbm6jEmHJa6iqME4PmT4m0vVBdJGcKfoL+JYMwGtFUikhaeAxiyeEr0rPSJSvn+bNu R+6g== 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=6bx/LiigbMv8R+oAgDzxAPgUAVPtRaf0sSTJD6E/l4GJCh2zEpvR3KHOvnxwAwQiVN qBfdXRV36QH5/NbXaL8ifv9QObe/jlxqluUum0CNkq5q6K/s6MTNCcMl9rwndeMhPsHF 4dFjDMRo7gizRLLDydULrECouafHGCePQCJcvr9twXfnueUxR5yV+szTyPOip/KIG8lD fBLKIdgOGg4xcpe1VK1MZWYhl8rbxvdMUb0lYFYcEzcmDrfHt5DSu0vGjGWXbsTYQs/W KfM07+vNSQu8v1CYkgf0ttEYDQQ3mS54VX6zhY2xjBCikcxoDiH6s6s0r9P96oHJ40sA NQRw== X-Gm-Message-State: ACrzQf1FYV5PiRchYe5NcQWN6UkQumtzOWCXWMMhANjkMashHGasGdem MfgkMHN390RanhculwZFRkPzNlEjCpe+iYYMtCcnk+uyRRUAWQl3Pv0tmwLx8GxQhgd5gqjTrHf 7VM3pBjoTn/yJ4Orc5PtHLIxtzoLn/jIYD2MpRt0OGIDJJ0PNlYd+kM9asWFiakSXBtmH/Xlgpm gl8kgsamg= X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2ee6]) (user=dionnaglaze job=sendgmr) by 2002:a25:9d11:0:b0:66e:4fad:e153 with SMTP id i17-20020a259d11000000b0066e4fade153mr35592854ybp.484.1667592989294; Fri, 04 Nov 2022 13:16:29 -0700 (PDT) Date: Fri, 4 Nov 2022 20:16:13 +0000 In-Reply-To: <20221104201616.2268815-1-dionnaglaze@google.com> Mime-Version: 1.0 References: <20221104201616.2268815-1-dionnaglaze@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221104201616.2268815-2-dionnaglaze@google.com> Subject: [PATCH v7 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?1748598193537928910?= X-GMAIL-MSGID: =?utf-8?q?1748598193537928910?= 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 --- 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 20:16:14 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: 15782 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp618908wru; Fri, 4 Nov 2022 13:20:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Z0HYas2pgFdfHlvGZ8RnfZ6BAfSIuEjB++ZbOZTp+18j9T3yFbKmpANGjXLuDATH6RjkO X-Received: by 2002:a05:6402:1b01:b0:463:a54a:d551 with SMTP id by1-20020a0564021b0100b00463a54ad551mr22879015edb.428.1667593242506; Fri, 04 Nov 2022 13:20:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667593242; cv=none; d=google.com; s=arc-20160816; b=ut6eIXkpgzaYflvwpkJCWSAQP4fWHrEYpX+esZZN7HapeZeomYAvnCvjHc/A0Ucobv 5O/utlgjhCpUxVlSKtBlI8H0r2esC6+5YjmbSrNKSniU/GdC9jXsPXiLF2ChtmVJVlRJ 6HGrMLAwhjqZsi4U0o1AfFgLOwqN/GKYcL3TU9CYbEjl8ZYmzBsXyXPwJt7FvzE+hSDO zNIHjmZrMTfEa8+IqMTlHx6OSHNPhzeBUo7CJhAgaRyzHChV2lyjpKYZFHNE5THw6SMI b947jQ674HwD/OMdW+u0syWSieTbNNNHn4FKXmZL+tBZClbANTwO1wBn2IXqqLi+dAhA 4r+Q== 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=jzCZukj92eZqZvdZYp5Y06AId+ACHlwZTdzH2wsVcRyk+Vo7CGP/lEdocB3+lEXTfV OaSBaDwIzx6xUeoJ5wUOm1P37l722fEwrcgjQvg9iTUIJ0yxJaTnRuLQ6uCyqGeLA0q8 RFt6v/T5PXAP0eHN2bijMuR7xb1FYcDzasu+UY3PxQFVeTi2DsuZuV1XlfMb/rOa8jJR xypcrFDWWvWt/MthVm5G7SUFR7LnhoZ3G7MOxSgcmVDbubniEsTsy2+c/3ewnA10cOsN eslag4MBUOI9TA5JAqfFdS1IubEbEunfLAcCZ3bFUuk+AoiFXBuUNg/C/BshNloOT4/1 LqGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Il1wC+xW; 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 he18-20020a1709073d9200b007acf3aed493si5667795ejc.910.2022.11.04.13.20.18; Fri, 04 Nov 2022 13:20:42 -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=Il1wC+xW; 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 S229936AbiKDUQm (ORCPT + 99 others); Fri, 4 Nov 2022 16:16:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229906AbiKDUQc (ORCPT ); Fri, 4 Nov 2022 16:16:32 -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 CE34045EDE for ; Fri, 4 Nov 2022 13:16:31 -0700 (PDT) Received: by mail-pf1-x449.google.com with SMTP id f189-20020a6238c6000000b0056e3400fdc0so2941197pfa.10 for ; Fri, 04 Nov 2022 13:16:31 -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=Il1wC+xW4V9ldzvEHntjxeveeNBukzQwgnx6gzRlwbIvwfuGMJVlqiruprMfTz88Dd xvy5YV5RGoMrccjmm31d0Qom8iTNLwQpVpZ98/re1X218bG9GO+98pG2U5CPoH4U8Eqy FDoJjtaLe1MXJv3LhC0UumN5tvBzw44DeHfxvRkE7KXEP+LYLXb096fcc5UFs2x8zRkU LBUTP6TCP2mcB4fQEVYnxM6k6iUgpW016AazEVmWLE9D5DqriUS5/LoH3OIBmvSVvp6X A9CF6Jf7YRsPzoXPkhcnwgFrHIwKgc379OqRVqTghG2vfDiAd3661KiYlMyGOpUZ02CI xgNw== 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=sOA/xoa5azVvW0MzICnIn1pT+FKX/ioJbGrM3CnxUubnrM8PGipJl5vHd6D7GQf3gq yJSGH+yqTD/n03CROgr50O/5J6A9GXf/pQhIg8ZNwfVWxjH6vzSRoRApx3wwiol0yRdD m4duMJGLZ56RZ5rtLFjX8q85CyYSgXsNNz3ltbdAWT2abJXC+DgmSwP74EPbA3rB53Lx ttE0PKm1ntU7Mhw0hZX8ijHFpKdFwvvBq9yzF/3SuqwHLPekIxz0FcFLcM82jNJCxMfz CoerRqV41bSN6h1VPrWJfU5esjPfDfptB1U6ULtORDapZeoHrwj6tY9FDpB1tPhAqyQ2 JbTQ== X-Gm-Message-State: ACrzQf3Bh1ik2CCwZg9mgNYAmkw2sfhaE6/+KOSDZVCe9jS5Rm9NiWeM A6/j6PA9t74ONXP86T9SLaG4UI2y/igtHYh6l+cu7bjjXJ/9eQawe4Q/JDoon3KzpomszcL9t3b LDduP9zGJuyKffFZ0IRu9ookTUEzxiqznTp7f2YppjlfD73JhjyH9oJXUQGKGofO4UlOuiiYGjH 0gq8RdLd0= X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2ee6]) (user=dionnaglaze job=sendgmr) by 2002:a17:90a:df8e:b0:213:8283:ac7f with SMTP id p14-20020a17090adf8e00b002138283ac7fmr356850pjv.220.1667592991086; Fri, 04 Nov 2022 13:16:31 -0700 (PDT) Date: Fri, 4 Nov 2022 20:16:14 +0000 In-Reply-To: <20221104201616.2268815-1-dionnaglaze@google.com> Mime-Version: 1.0 References: <20221104201616.2268815-1-dionnaglaze@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221104201616.2268815-3-dionnaglaze@google.com> Subject: [PATCH v7 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?1748598251547815640?= X-GMAIL-MSGID: =?utf-8?q?1748598251547815640?= 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 20:16:15 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: 15783 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp619725wru; Fri, 4 Nov 2022 13:22:31 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7234wiqoEekoU4by5rtf8lv9xV4dICsrj8A0cDRX7zQV/xSJ8gEN/8KADHHuqzhmvH5vk+ X-Received: by 2002:a17:906:cc5b:b0:7a9:e58d:bad9 with SMTP id mm27-20020a170906cc5b00b007a9e58dbad9mr35856418ejb.237.1667593351682; Fri, 04 Nov 2022 13:22:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667593351; cv=none; d=google.com; s=arc-20160816; b=jW8To+CoxAWGEZ67nBNSCxMeK5uMp8AESeUSQ7+ZYvN71kYXcAIoJsQUDJhFUTmSb/ RjpGTjtP9b0siopyvrqqgC0K5eFKyMi1/Q1b+ndnxmeMbq7jKqGiR2mgsCWabIa0ouBo 2BM3Ib1lw22iqC1a7rk64aPwMiA5KZ0PMEm3x92cspVHJj2Oxu17uFP+UXg3219RVX72 QYTHjojYH3FGIg6mjYeVL6TUeiAWOz1rhTO/ejFLEyANcwwBexw3qxJVzeGte5DUe5JF L2UNV+z7n5AA2SHesP4TQV+1URzWt3b4ONN5TiRt0EIX2+QrdYIiqKB6xqSM6CapT6SZ 7w7g== 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=nK/94Sb1beqtM8XT82Q9haSgN6Gg90IfYFCDs+/l04Q=; b=tdpmyp475dYEFKCoWlj/KKgUAoUd0dg/1pKJMqCIFXxUkezNNYt728LV/1JjgOr/cu pBdflp0Pe5AvN6CNKXeK7Wvear9AKNqdYfmiOC4Ao642iD4cj1F9K2AQYaOqRfddHkos U3aKV34QHLSCjF1sJinXJqOczuw8X4yPY09UHF9ywBZM7xJ4tUKgIOVe0Y8gr5O9Gl55 nyhpK1PyT8KN0xMM2zT4R5pVHHFQqEhsl6jgNY1zCaFQ8NNRlNYumFoZMTLkZo4qm8xi WGafXDb6DxF7IqyirsGHVZc4zCm9G1VmyC93g+mBYtGPp6AP87nm/FOgAdLtKpq/VmWN HUDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=gD4uBppb; 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 nd21-20020a170907629500b007ae10525573si7167478ejc.671.2022.11.04.13.22.07; Fri, 04 Nov 2022 13:22:31 -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=gD4uBppb; 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 S229954AbiKDUQo (ORCPT + 99 others); Fri, 4 Nov 2022 16:16:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229925AbiKDUQi (ORCPT ); Fri, 4 Nov 2022 16:16:38 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7AE148762 for ; Fri, 4 Nov 2022 13:16:33 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id q63-20020a632a42000000b0045724b1dfb9so2998118pgq.3 for ; Fri, 04 Nov 2022 13:16:33 -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=nK/94Sb1beqtM8XT82Q9haSgN6Gg90IfYFCDs+/l04Q=; b=gD4uBppbQwFb6mzboPS+LsD9PYZUuN8/clt/XIhPCFu1284keiCeM33V3amJCXDA1p UHh9XdWGEIOK+r/aYqaAgXeqHBvUeUKULrNrsX/v+Tiry9/SWdtgyumpXnyTtoeEONV8 sJ3gxEvkq0VOu7/LX2v1vHO4aS5cZbXk13KJwjgFgSB8D6WXo5e7ElSkaLed1zBBDdhO 45rcW6a+SFoplxfbQ+bazqHmeRqBYxIqYt0rUquGNq4xl2bW0Ap9aghRZgqYG6bxzGiS 7Q7FESTo4Q6FV/RcIZBcNd8cN629rHx0Cz5X3uMtcMtBuTqXRHHtMfyq1amjB6E4dSvp tM+A== 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=nK/94Sb1beqtM8XT82Q9haSgN6Gg90IfYFCDs+/l04Q=; b=TIud7UMXHDuhBuEisSCtuO1SNpslvP3qMjKg/BA7CDX7VvkEmZKR6c6IFr0xceduNJ U95NWBQ7iQ2GoXpr4zKA/Y8efUwgv/lXOhq+1fWVVNGVQnnFCgC+J1BmOYr5dcqwnPJu Q/glCpLWTKZWo/c17ymktyaX2G+GpUnTI7lPaJDKM4Ff5udW6DHm3yXoATWz35/YC+zC JHTvHzYP7kcAjWgs4OpJqx4KbOomIaVDsJ6LcGk01eliu502eXGrI+tGn/KNzbXkTIqs ZktyJIDH9gZrVxsHMUSWsuH4V1bSaPohNaNm81+6nhEyZOQpabP10zuqW3nZMBBVDywx 4kfA== X-Gm-Message-State: ACrzQf1ZFYitz+85hBBpyELxi0F1TyX2zCNQQYpCNADzq1210AeuZpsc hFouBpSEkogcuANRgTWcFkmCQtQJ9IcAXT3i0Mn0v60+QOu/Uca2fHyX21PeRxgozklpn+Jkhep w1yZslwH3gQqJ5ypFTLzr222hT2CUugQPd3GlJFDCazcQoPRyePNvRW1uF5GpR77xMwiwdA46Mx wLiPg3Zd0= X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2ee6]) (user=dionnaglaze job=sendgmr) by 2002:a17:90a:4dce:b0:213:9d22:8870 with SMTP id r14-20020a17090a4dce00b002139d228870mr40202745pjl.7.1667592993039; Fri, 04 Nov 2022 13:16:33 -0700 (PDT) Date: Fri, 4 Nov 2022 20:16:15 +0000 In-Reply-To: <20221104201616.2268815-1-dionnaglaze@google.com> Mime-Version: 1.0 References: <20221104201616.2268815-1-dionnaglaze@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221104201616.2268815-4-dionnaglaze@google.com> Subject: [PATCH v7 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?1748598366216032729?= X-GMAIL-MSGID: =?utf-8?q?1748598366216032729?= 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. Since the issue_request's signature has changed fw_err to exitinfo2, we change the argument name here. 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 --- drivers/virt/coco/sev-guest/sev-guest.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/sev-guest/sev-guest.c index d08ff87c2dac..5ebf87651299 100644 --- a/drivers/virt/coco/sev-guest/sev-guest.c +++ b/drivers/virt/coco/sev-guest/sev-guest.c @@ -322,9 +322,8 @@ static int enc_payload(struct snp_guest_dev *snp_dev, u64 seqno, int version, u8 static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, int msg_ver, u8 type, void *req_buf, size_t req_sz, void *resp_buf, - u32 resp_sz, __u64 *fw_err) + u32 resp_sz, __u64 *exitinfo2) { - unsigned long err; u64 seqno; int rc; @@ -341,7 +340,7 @@ static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, in 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, exitinfo2); /* * If the extended guest request fails due to having to small of a @@ -349,19 +348,16 @@ 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) { + *exitinfo2 == 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, exitinfo2); - err = SNP_GUEST_REQ_INVALID_LEN; + *exitinfo2 = 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", From patchwork Fri Nov 4 20:16:16 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: 15784 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp619736wru; Fri, 4 Nov 2022 13:22:32 -0700 (PDT) X-Google-Smtp-Source: AMsMyM56gFKO330Q4K6hCo0FJaO6hRSRtj2qnp7UxNiSjen+YNNYW5w4ZCarnpxwAQEWOXLBXjX0 X-Received: by 2002:a17:907:720b:b0:78e:c0e:a434 with SMTP id dr11-20020a170907720b00b0078e0c0ea434mr36645274ejc.741.1667593352720; Fri, 04 Nov 2022 13:22:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667593352; cv=none; d=google.com; s=arc-20160816; b=MlagODd15cSosIOgpXVkCbgAj4m66qs2iIu+p7rT/8QyDVudSXfLE5zw4Z5X6E72EP vYCr1QCqwtam8kyfUE2uiG80XnjIrW1g3sGlW3IPnEGNs7smgkunDe80jxGmhnkd8deW FynsC0WD62sOG95NWs1qnl+Y+NV0LMtBIMLt4G/k0GFRn6G6hhkzCAtRr3DC2DPi0/vl XnuoKgT617+s9xx3C55q1bbMMtKuCUw7rf4mrREq3hj6xWNS9JXq3QS17VDY6rCy5Wud s6oa0a+m29yHibJZClru3PZtjXrKGBk31dlfMsXhusoqwjg2PpRMV8VKB3ktRt2zuxjq voCA== 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=NpTNvOAKvMITV2ooJfE8EO+LheKjmaYiLAbcqV/4LPU=; b=tT6nNOVfZTAESeoIDTsu+xov+uzygwnOzDVMDEqwz1uGS342Z7751RwkJI+1kBwLeI RMrG8qy/MPoQgLrg/VtA4cEpF5BqNgzFELwhlWHItGCp80420otcJw5914NKxLzGKhQ2 z/OyZO48snqt5ntsh5j1zYLTMGlIpZf6gaT7THFkI1YzppWUVvkwU/xza0qRuhZqWF9X XB45uh4SJD/bTv8dAH378SUv21WxfBkwsWfil96qCfMXitcx/a3duQQKaCt6aeUnRRPT s8A37AcI1+l/9Y+sFLqUbDZ6QVXFe03HoxKPYiJW55cAekYYRfsMxSTcEFGhTIKE5U+C 3VWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=XHyhZ5fN; 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 rp28-20020a170906d97c00b0078dbd939dacsi4862083ejb.545.2022.11.04.13.22.09; Fri, 04 Nov 2022 13:22:32 -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=XHyhZ5fN; 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 S229995AbiKDUQs (ORCPT + 99 others); Fri, 4 Nov 2022 16:16:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229948AbiKDUQl (ORCPT ); Fri, 4 Nov 2022 16:16:41 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F9D449B7A for ; Fri, 4 Nov 2022 13:16:35 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id y6-20020a25b9c6000000b006c1c6161716so5843636ybj.8 for ; Fri, 04 Nov 2022 13:16:35 -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=NpTNvOAKvMITV2ooJfE8EO+LheKjmaYiLAbcqV/4LPU=; b=XHyhZ5fN3nHm3SwWdcMmoSVqANSskYo2rtyOrO+JILxrF+COGrKUd4vJgU08yROoLm hlFrAa+Li3vm4+pVV75Px+LdDt3u6NUsYvPPW9nxzSLYbNaeC64yIcc2dwN5hoyibUn2 VCO0L7GGTRqejjE79xumUF37xD79F6K8kGISKM+m+YcVYh5A+SGNpUZo3rY9UGM2Amhv NuZAqyH6j8lAILPN2DqeUnFAHlRgEQVq4V0CRZPgo0mN3jaZ1g6E5a6YAZizZYPZLB11 Im3wZQ6pqBYTfSpWzx9J8aMiRkrQXoYcDs6KQWjB+BVFxlniZXMymhZwdXQ5afdf6eyW SW4Q== 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=NpTNvOAKvMITV2ooJfE8EO+LheKjmaYiLAbcqV/4LPU=; b=wiABPehPHAWir9S6IbIkLqWhamZER77q7CIY+4NpR6NN2jC/OP9g4yxryIe9o7pmyS oSqu6os+ryqQUnbyYxjDGMQKsYFO+AgFNL87r6fadTooFyHjXzu9HFW+6Mfg42BfH+GV 5/qzjweykn5AS8isf494YDErC5ewt63CG5E+km6bEsSV//HsJNZ1HKVKuJOzD+8W0zsw ZMwENUIeGuN7eEffMH/3OjBIfSLQn3lUBK2yiNlrSCDsqgszuDTyHjDrMcRB0qjRogac iWNoGU/g0XuTzMWyNeOkEOO/e6AoEdC9aTTZS9L7uIJh2UEpHhbr08f/lWF1T+3mkhE7 Xo6A== X-Gm-Message-State: ACrzQf1qkp3W1Lb+1QHPGazAUZRI1sVeOhYDXbYW0abd74KKCfaQxDdM mw18OM0C9gePryQixI5qREfDPuxNk9WYC3oRHs2tlmHy+F8WomqdOMqqsafAojB9KciM+C+ZeJy JsSkFkueeDPKzWAzDpu72jpj8nBBqG3kR067tJH09gtoUCQ/DRmsuhh9jMQWwll4U8Czynle29g oU1esmqE0= X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2ee6]) (user=dionnaglaze job=sendgmr) by 2002:a81:6f88:0:b0:35f:df0e:3a7a with SMTP id k130-20020a816f88000000b0035fdf0e3a7amr36532680ywc.416.1667592994735; Fri, 04 Nov 2022 13:16:34 -0700 (PDT) Date: Fri, 4 Nov 2022 20:16:16 +0000 In-Reply-To: <20221104201616.2268815-1-dionnaglaze@google.com> Mime-Version: 1.0 References: <20221104201616.2268815-1-dionnaglaze@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221104201616.2268815-5-dionnaglaze@google.com> Subject: [PATCH v7 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?1748598367626460037?= X-GMAIL-MSGID: =?utf-8?q?1748598367626460037?= 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 --- drivers/virt/coco/sev-guest/sev-guest.c | 51 ++++++++++++++++++++----- include/uapi/linux/sev-guest.h | 18 ++++++++- 2 files changed, 58 insertions(+), 11 deletions(-) diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/sev-guest/sev-guest.c index 5ebf87651299..9c49f38aba44 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); @@ -324,6 +335,7 @@ static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, in u8 type, void *req_buf, size_t req_sz, void *resp_buf, u32 resp_sz, __u64 *exitinfo2) { + unsigned int vmm_err; u64 seqno; int rc; @@ -339,16 +351,35 @@ static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, in 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, exitinfo2); + vmm_err = *exitinfo2 >> SNP_GUEST_VMM_ERR_SHIFT; + /* + * 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 (vmm_err == SNP_GUEST_VMM_ERR_BUSY) + goto retry; + /* * If the extended guest request fails due to having to small of a * certificate data buffer retry the same guest request without the * extended data request. */ if (exit_code == SVM_VMGEXIT_EXT_GUEST_REQUEST && - *exitinfo2 == SNP_GUEST_REQ_INVALID_LEN) { + vmm_err == SNP_GUEST_VMM_ERR_INVALID_LEN) { const unsigned int certs_npages = snp_dev->input.data_npages; exit_code = SVM_VMGEXIT_GUEST_REQUEST; @@ -360,8 +391,8 @@ static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, in if (rc) { dev_alert(snp_dev->dev, - "Detected error from ASP request. rc: %d, fw_err: %llu\n", - rc, *fw_err); + "Detected error from ASP request. rc: %d, exitinfo2: %llu\n", + rc, *exitinfo2); goto disable_vmpck; } @@ -410,7 +441,7 @@ static int get_report(struct snp_guest_dev *snp_dev, struct snp_guest_request_io rc = handle_guest_request(snp_dev, SVM_VMGEXIT_GUEST_REQUEST, arg->msg_version, SNP_MSG_REPORT_REQ, &req, sizeof(req), resp->data, - resp_len, &arg->fw_err); + resp_len, &arg->exitinfo2); if (rc) goto e_free; @@ -450,7 +481,7 @@ static int get_derived_key(struct snp_guest_dev *snp_dev, struct snp_guest_reque 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); + &arg->exitinfo2); if (rc) return rc; @@ -512,10 +543,10 @@ static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_reques snp_dev->input.data_npages = npages; ret = handle_guest_request(snp_dev, SVM_VMGEXIT_EXT_GUEST_REQUEST, arg->msg_version, SNP_MSG_REPORT_REQ, &req.data, - sizeof(req.data), resp->data, resp_len, &arg->fw_err); + sizeof(req.data), resp->data, resp_len, &arg->exitinfo2); /* 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))) @@ -550,7 +581,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) @@ -581,7 +612,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; @@ -731,6 +762,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_ */