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; }