From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9955EC4332F for ; Fri, 4 Nov 2022 23:01:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229495AbiKDXB1 (ORCPT ); Fri, 4 Nov 2022 19:01:27 -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-Google-Smtp-Source: AMsMyM7iQh/dofT2n99P/ZGzCOg9OzIgW4DoxWOr4SlQPsTl4KAjCAiUhd34Md0suWroDmBskPAlUDElCNvhiaxf1w== 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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; } -- 2.38.1.431.g37b22c650d-goog