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