Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp88929rwb; Tue, 6 Dec 2022 17:44:37 -0800 (PST) X-Google-Smtp-Source: AA0mqf5sL+vCG6SSgEv2FWy2/bcCMriCZzP7mmZx4u3VXqk+abBZ71MJhkKT86CCR2lGZqst+rlc X-Received: by 2002:a17:902:ec8a:b0:189:bdd1:daa7 with SMTP id x10-20020a170902ec8a00b00189bdd1daa7mr21404243plg.93.1670377477054; Tue, 06 Dec 2022 17:44:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670377477; cv=none; d=google.com; s=arc-20160816; b=B0Ecy+IpsWb/pnjy/TmwJhUsdOaoXQMJ8DrmurR+fs4vS5LR11khWZyqB1ufmkD0zi c1WXCKCHREMHpIphL0VB7wtIQxZm8YUwgRM5U4YrRWE4/tyAFB75H2gW2jkwj/M9JkAZ q/7cdUE96PcplcdZVJFA5g6sNOcL37hHxeFw9XNnHag5hNQcwHNauQ2X3YrdUPvpkJeu SLNy6zrx+ttqMEhB7MD92qP7z+y9mMHyITlLIUdMZgYFwtRcVWFTGkSNDoyP3FT9VeUB b1nI86e10iiRoZaxuAa1HbMOOfYANgv4jWYA23OrYzXSNbGxufOxGbpgXoWQDeHaTYBc HMLg== 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=GMGURl9LxXOJnwuiD/Ha/hCLoLpmM+oX4OEPqCyeymM=; b=WIxnrG1TLLvPi8lsG/C5cCF+9+yOdGZQoVvyjGSAHEPwYUlkQxqt+77lFN7NatLidk rTvkHQdwKlZXDn1WXPdXtgZmZyFGGNM3dHlw+KmStuvJ3Suj3Y6muvqOo3r4d2KpQjts MvIqS1WYUThf+tfEyjzjb2FEDO4fSDlNr2BSKPV3inq7/FiHLYDyaWTu89GuVEIXYCIV ubCXMvlKnLjC5M5KE1+EqqrOS+C67X59v4skgHjfZxowLSdY3/PMV5aDol+xJq79V3Mv w37nhBW1JecqALvaZC4rQRRGMCTkjyDCN91//cRRs3gKDx/QK1V1D9I8LNB/7/lws7xd NNMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=UnmJAc0+; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k7-20020a056a00134700b00558991a667esi19950356pfu.359.2022.12.06.17.44.27; Tue, 06 Dec 2022 17:44:37 -0800 (PST) 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=UnmJAc0+; 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 S229761AbiLGBCg (ORCPT + 77 others); Tue, 6 Dec 2022 20:02:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229748AbiLGBCc (ORCPT ); Tue, 6 Dec 2022 20:02:32 -0500 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 8540B4F18B for ; Tue, 6 Dec 2022 17:02:30 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id m2-20020a17090a730200b0021020cce6adso18762pjk.3 for ; Tue, 06 Dec 2022 17:02:30 -0800 (PST) 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=GMGURl9LxXOJnwuiD/Ha/hCLoLpmM+oX4OEPqCyeymM=; b=UnmJAc0+Og3g47jm5MGaU3e4YuK2OhTwtsGRAnE+9pvMlfCuaTzH7EZE7WcSBRX0Wh AKLocDxsjvMLxJJkLhsGKnNDEx1JQWlzXUWnR61gNweuPVmV1CzHsx4+uUV4/OnyJO0s MLMNsP1LAQA8Cxn+sBx0w9M5RouMTpSjk21NvueI3YPQMpCHuGvJXnlp2rZDFYP8VeTz Mqlj1ni5AQ4UNXQadNqMHpmCXmZKiEN3nBvCualsOb/PBMliLpe4hOxRrudAeL6vX6VC mBp0DxpFy1jKjHmy29BB1UOiMIxKMG3eJJV9hTsQVYNV/kSHCmoPNYJ8sb1zMOKoZqC0 CHlw== 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=GMGURl9LxXOJnwuiD/Ha/hCLoLpmM+oX4OEPqCyeymM=; b=NGYcBwwl3uP1mblqrSLOI9YD75O0YYi/9aXcQqaw3ugvP9DhCI8JBTFHI4iB/4vsMu QtlY8WHI2+0/LjAhhw6NZ5ITcBOgWlw5q4KnUIGowKcrijsTer+HoQRA4viQh1sEgRte pfmfWl2ZBnk+3L1xw1Lo5SEMRRVuXeAk+PEOzGYsoFq107p0+lfyv3W5XVugiYy3V9U9 GWzwboppmdctthGlGNbsYHmai0xROo1Egn1puO/n0Q5Rro8OnY10aihp3zDUN8FxmfSE 4z8kQrAoorGopLu3DJ7ml8gWeRygnv/ywWYnvVKSMCqxMd9MqHHxJAxN1LTplK+owKMs 6qCQ== X-Gm-Message-State: ANoB5plyYI2Mw8cp1xetcmMyjKejvLCzTBEjugV0AfLCsWxvtpPQ9gaO t+ytMtj4sSVoiIyMf/nHSTdYXPF+f1UAZ4bT4n0LeabogNa6GvtttRCifY1JtVA8b3Kkw2yrE0E kF7tZCxJZ5h+hXx8QrXiwXCLXDruQR/Ffiq8AporzRAgmBICydrXuIK0DRglvvJ2SUgdgu/YZGm QzgyWdq9k= X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2ee6]) (user=dionnaglaze job=sendgmr) by 2002:a65:6385:0:b0:478:e68b:7969 with SMTP id h5-20020a656385000000b00478e68b7969mr3710242pgv.574.1670374949949; Tue, 06 Dec 2022 17:02:29 -0800 (PST) Date: Wed, 7 Dec 2022 01:02:08 +0000 In-Reply-To: <20221207010210.2563293-1-dionnaglaze@google.com> Mime-Version: 1.0 References: <20221207010210.2563293-1-dionnaglaze@google.com> X-Mailer: git-send-email 2.39.0.rc0.267.gcb52ba06e7-goog Message-ID: <20221207010210.2563293-3-dionnaglaze@google.com> Subject: [PATCH v9 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" 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 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 the call is bookended 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") Reviewed-by: Tom Lendacky Reviewed-by: Borislav Petkov 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.39.0.rc0.267.gcb52ba06e7-goog