Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp568057rwo; Fri, 21 Jul 2023 17:22:04 -0700 (PDT) X-Google-Smtp-Source: APBJJlEKhaLhkAggsOBe0TXqp2bVFLaAJFig9prN4395b1xHrobKz/fRS+C2cpojPLE6jv601VLd X-Received: by 2002:a17:907:b0e:b0:992:bc8:58e4 with SMTP id h14-20020a1709070b0e00b009920bc858e4mr2677793ejl.20.1689985324191; Fri, 21 Jul 2023 17:22:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689985324; cv=none; d=google.com; s=arc-20160816; b=m44DwYNdhJr65qL6omzo5navqKO8li3Xoi0JA6aGB8TTTJ6WN2rl/MEz1N+OLLXHVV 8riLTF5Z16IZY3CLOKO8inn89Qpdhr8YLSmJHjpEu7h0GLL11MFjMMbTtlVHS6S/wbP3 iGL0S9j8xPg5ghU+ytxA6EzhzXXc1cMvI088hf9vKyVGG/O4AyZI3NGUx/84IW4S6a+U 60uqlC0h7IPVxqERZlHcP5WEhffNashDBZxZ7KUn1ST68hyrsm9t2RbKWSrSe9D2PNyP GgC2PapqednhHBq1Y5LnjYcCP78eJyEnbjgPCS2gYXx1PM4PlqOaTqiebgnFjASBl14R 48iA== 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:reply-to:dkim-signature; bh=6NovDKEkmf62QTHUp16tEbCQYBqsRkwO6qPZcwM/IpM=; fh=876Zq2oV8dp1KMDsVIxM6dotCjDw9qRFXVLhzEk62XM=; b=Ycfun2ZgQceSwxPB6S+6Db6uea6SZB6z/PvgN/nW81lpm2dim6rmVWAlUgARUiLG4J 5SP/mF7Qhp/1EK+1HQ1p6bG7POi54DygSY5Yaunlz6x32Amb6cvPYpgL6zgJQ7GIxcZ4 8inNKph1SDjQwFC6oq3BLwie2XFjpAsPJOe9IKgr45C574PnrAsyRLpqTCvXE6WUhlVg Z+incjR0bgrQczijGd+A/u0w5vWUaVxqVUHZUSp9tnHxd+0BTj/120eZSiu0mnSqAWBk l9Ptdhyn45MAL1Fox2fwAuR4TgKbOVmEMIuhZn+e7gx7adYm4x1NQFwp1PWZGgReqrG7 oWHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b="m9yRmOB/"; 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 a10-20020a170906190a00b009885c5f1d7asi3179756eje.319.2023.07.21.17.21.40; Fri, 21 Jul 2023 17:22:04 -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=20221208 header.b="m9yRmOB/"; 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 S230246AbjGUX4r (ORCPT + 99 others); Fri, 21 Jul 2023 19:56:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230215AbjGUX4p (ORCPT ); Fri, 21 Jul 2023 19:56:45 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BFFB30E1 for ; Fri, 21 Jul 2023 16:56:44 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id d9443c01a7336-1b8a7734734so14363505ad.2 for ; Fri, 21 Jul 2023 16:56:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689983804; x=1690588604; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=6NovDKEkmf62QTHUp16tEbCQYBqsRkwO6qPZcwM/IpM=; b=m9yRmOB/Hl+eRWXlUq0DfSY9BX2JKqXoKRjMwugp1FJVPEFn93LjV6RVFg/EBIDRq0 kUIqf3rVoLK3ExOqmuBX6Ej15HkRRSG2WqUMgTSUsE0tHSGGCrDDv0BvQ+/mm89rgG13 EbG5ufx35VHeUaFsAAQ6Cy3F6RXAaWVTR27OQUnyTVrGJbqs572X2E8gU4+LMSlTBEJo HokuL0vl3+hXvBzruH9I1upAvq6rpHNMHneaScnzPm2SjV8MIpoN64z5De8wAcu4joLp 6iu51nyZC3uAHvoZqfN59Y/hNmHRnb8TEln7bsByO79MJCCH8eMDCnAzGMqxAb8EDGcE USwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689983804; x=1690588604; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=6NovDKEkmf62QTHUp16tEbCQYBqsRkwO6qPZcwM/IpM=; b=MC7iQj8t0hWHu6HOoCL3qaFpbgswrbAxYXINKIJ2RPXNAeIQ+t7CRkRSr/ZCyolZSZ JkpHUzN9TA97OwsQnrtwPpHZ4pqnebeCnMR11IKs26YnfyeA2Xa1E6g5QMX1bvJH/YjV Ndfv3Sy4d6BPf8rSC63YIYizaYKXIqjYQU/L2gSp9slpG0BEDNPdOft79jgtVd5Q77/b EfNtABeI9gsGAfzmfCbHHXwopcFRavW/WEGSEig5uF/AvFeqXTg7+bCspWhhuKBwPXtL djzV1LOnlFXUfoyT2iyC5nYvves3ZTKZ0vxAaQoLtbgype9yS7rgATF4YiM1BBgOQzEI H7lw== X-Gm-Message-State: ABy/qLasSno4O29kcYhDvaU0H+ADjZiFDL8WaKckU4acqwVBp8TL2kYN mRC271VLK3bO5yoLWMtnQY9dggEtl/Y= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:ce83:b0:1b9:ce2c:3bb0 with SMTP id f3-20020a170902ce8300b001b9ce2c3bb0mr13551plg.3.1689983803804; Fri, 21 Jul 2023 16:56:43 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 21 Jul 2023 16:56:36 -0700 In-Reply-To: <20230721235637.2345403-1-seanjc@google.com> Mime-Version: 1.0 References: <20230721235637.2345403-1-seanjc@google.com> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog Message-ID: <20230721235637.2345403-2-seanjc@google.com> Subject: [PATCH 1/2] KVM: VMX: Make VMREAD error path play nice with noinstr From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Su Hui 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_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, 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 Mark vmread_error_trampoline() as noinstr, and add a second trampoline for the CONFIG_CC_HAS_ASM_GOTO_OUTPUT=n case to enable instrumentation when handling VM-Fail on VMREAD. VMREAD is used in various noinstr flows, e.g. immediately after VM-Exit, and objtool rightly complains that the call to the error trampoline leaves a no-instrumentation section without annotating that it's safe to do so. vmlinux.o: warning: objtool: vmx_vcpu_enter_exit+0xc9: call to vmread_error_trampoline() leaves .noinstr.text section Note, strictly speaking, enabling instrumentation in the VM-Fail path isn't exactly safe, but if VMREAD fails the kernel/system is likely hosed anyways, and logging that there is a fatal error is more important than *maybe* encountering slightly unsafe instrumentation. Reported-by: Su Hui Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/vmenter.S | 8 ++++---- arch/x86/kvm/vmx/vmx.c | 18 ++++++++++++++---- arch/x86/kvm/vmx/vmx_ops.h | 9 ++++++++- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/arch/x86/kvm/vmx/vmenter.S b/arch/x86/kvm/vmx/vmenter.S index 07e927d4d099..be275a0410a8 100644 --- a/arch/x86/kvm/vmx/vmenter.S +++ b/arch/x86/kvm/vmx/vmenter.S @@ -303,10 +303,8 @@ SYM_FUNC_START(vmx_do_nmi_irqoff) VMX_DO_EVENT_IRQOFF call asm_exc_nmi_kvm_vmx SYM_FUNC_END(vmx_do_nmi_irqoff) - -.section .text, "ax" - #ifndef CONFIG_CC_HAS_ASM_GOTO_OUTPUT + /** * vmread_error_trampoline - Trampoline from inline asm to vmread_error() * @field: VMCS field encoding that failed @@ -335,7 +333,7 @@ SYM_FUNC_START(vmread_error_trampoline) mov 3*WORD_SIZE(%_ASM_BP), %_ASM_ARG2 mov 2*WORD_SIZE(%_ASM_BP), %_ASM_ARG1 - call vmread_error + call vmread_error_trampoline2 /* Zero out @fault, which will be popped into the result register. */ _ASM_MOV $0, 3*WORD_SIZE(%_ASM_BP) @@ -357,6 +355,8 @@ SYM_FUNC_START(vmread_error_trampoline) SYM_FUNC_END(vmread_error_trampoline) #endif +.section .text, "ax" + SYM_FUNC_START(vmx_do_interrupt_irqoff) VMX_DO_EVENT_IRQOFF CALL_NOSPEC _ASM_ARG1 SYM_FUNC_END(vmx_do_interrupt_irqoff) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 0ecf4be2c6af..d7cf35edda1b 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -441,13 +441,23 @@ do { \ pr_warn_ratelimited(fmt); \ } while (0) -void vmread_error(unsigned long field, bool fault) +noinline void vmread_error(unsigned long field) { - if (fault) + vmx_insn_failed("vmread failed: field=%lx\n", field); +} + +#ifndef CONFIG_CC_HAS_ASM_GOTO_OUTPUT +noinstr void vmread_error_trampoline2(unsigned long field, bool fault) +{ + if (fault) { kvm_spurious_fault(); - else - vmx_insn_failed("vmread failed: field=%lx\n", field); + } else { + instrumentation_begin(); + vmread_error(field); + instrumentation_end(); + } } +#endif noinline void vmwrite_error(unsigned long field, unsigned long value) { diff --git a/arch/x86/kvm/vmx/vmx_ops.h b/arch/x86/kvm/vmx/vmx_ops.h index ce47dc265f89..5fa74779a37a 100644 --- a/arch/x86/kvm/vmx/vmx_ops.h +++ b/arch/x86/kvm/vmx/vmx_ops.h @@ -10,7 +10,7 @@ #include "vmcs.h" #include "../x86.h" -void vmread_error(unsigned long field, bool fault); +void vmread_error(unsigned long field); void vmwrite_error(unsigned long field, unsigned long value); void vmclear_error(struct vmcs *vmcs, u64 phys_addr); void vmptrld_error(struct vmcs *vmcs, u64 phys_addr); @@ -31,6 +31,13 @@ void invept_error(unsigned long ext, u64 eptp, gpa_t gpa); * void vmread_error_trampoline(unsigned long field, bool fault); */ extern unsigned long vmread_error_trampoline; + +/* + * The second VMREAD error trampoline, called from the assembly trampoline, + * exists primarily to enable instrumentation for the VM-Fail path. + */ +void vmread_error_trampoline2(unsigned long field, bool fault); + #endif static __always_inline void vmcs_check16(unsigned long field) -- 2.41.0.487.g6d72f3e995-goog