From nobody Sat Feb 7 16:26:47 2026 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 3D7BBC001DF for ; Fri, 21 Jul 2023 23:56:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230289AbjGUX4t (ORCPT ); Fri, 21 Jul 2023 19:56:49 -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-Google-Smtp-Source: APBJJlHq2HLtrqVyzDIl2SIFChpZIefwP2c8PssvQNkMR6eG1BRg1s9c4iFFHAe+btgzVPNBBcBkMjzRNjE= 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Mark vmread_error_trampoline() as noinstr, and add a second trampoline for the CONFIG_CC_HAS_ASM_GOTO_OUTPUT=3Dn 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) =20 - -.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 =20 - call vmread_error + call vmread_error_trampoline2 =20 /* 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 =20 +.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) =20 -void vmread_error(unsigned long field, bool fault) +noinline void vmread_error(unsigned long field) { - if (fault) + vmx_insn_failed("vmread failed: field=3D%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=3D%lx\n", field); + } else { + instrumentation_begin(); + vmread_error(field); + instrumentation_end(); + } } +#endif =20 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" =20 -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 =20 static __always_inline void vmcs_check16(unsigned long field) --=20 2.41.0.487.g6d72f3e995-goog From nobody Sat Feb 7 16:26:47 2026 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 47365EB64DD for ; Fri, 21 Jul 2023 23:56:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230352AbjGUX4x (ORCPT ); Fri, 21 Jul 2023 19:56:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230235AbjGUX4q (ORCPT ); Fri, 21 Jul 2023 19:56:46 -0400 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0652B30E1 for ; Fri, 21 Jul 2023 16:56:46 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id d9443c01a7336-1b8a7734734so14363525ad.2 for ; Fri, 21 Jul 2023 16:56:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689983805; x=1690588605; 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=/0/Ys3eyilWPWK3MFX3CavmjPp16nyypaJP3VylXGoU=; b=AozewlHZURPovNElQfoYDp0vUxJqneJqSpZ25EaH5FyAd+F6cPs+hMGzHxOByIMyyh cR4vkzvcesyxfxZklzBFTQTHJDnA+yJQFcZVLfCq4J4NTQ54Dhz1GxFvCBQ3OpazhV2t mSegV8J9RIDYTJTSxe1a/R9AdW0mwmzUwYjnECwhFQdQsvzipRK2PPsQOHcTNR2TuU2c OAT/p71pi2JxgYVyi3xGPONi9yWumb2uFjAJlqpu99GgiMhGvGZdUHVW9615aMaMV6Hg j2I0ZYUg4yYhysw5dsu3sD9dUF57v7H59Qf0FX55q7EB0U4nTm5c+T/MFN3AnMoClLaV Zd5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689983805; x=1690588605; 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=/0/Ys3eyilWPWK3MFX3CavmjPp16nyypaJP3VylXGoU=; b=iY5QnPzf2n9mYaxt6gC/j6X4LeEvY+D7KBRMmhcVG6MnvwoLbebsbpwf0h40r+B+XR 0Lz+6ETeMvQAQvlg+Mx8mtVMv+TLkryk2o6zNYgEc57DFJ89dpEtP2Kx6ghd0KLKOYsp XH1WKcxaGGq5Kyq5h6bAUVXfkc8IbmHYKgnQ1/MbSRKHBfDhaWG3gDfMCJuQDDuj9kiM go0pRV6RlZEsQQFhxLNzJWF3FN4SesloUPazJZY1qfAuTXQiRfz9BuTa4dF9NoAsy/wF 0RAwv0WQx2igK0X2d5Y4BcMCJ7Do4BISU0v3QRNCGTNa+NWT+aqUjIlXAyegxEBUrXVn jM0g== X-Gm-Message-State: ABy/qLbaDHHOWoBu9SAkazZtneCR5738zBrO/ejqnBvyI9TSQaa4Tqzl KgshwRBD6XI6IXp9Wxqi7p6I0P42uOc= X-Google-Smtp-Source: APBJJlF9re/QfEiwtTvrQ2bbtlEB4e6P4b3U+Tw4dcVSuQCMsevPuEn/b6qzORLgenNlpOoqeUsTqJReT68= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:903:32cd:b0:1a6:4ce8:3ed5 with SMTP id i13-20020a17090332cd00b001a64ce83ed5mr13087plr.4.1689983805595; Fri, 21 Jul 2023 16:56:45 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 21 Jul 2023 16:56:37 -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-3-seanjc@google.com> Subject: [PATCH 2/2] KVM: VMX: Use vmread_error() to report VM-Fail in "goto" path From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Su Hui Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use vmread_error() to report VM-Fail on VMREAD for the "asm goto" case, now that trampoline case has yet another wrapper around vmread_error() to play nice with instrumentation. Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/vmx_ops.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx_ops.h b/arch/x86/kvm/vmx/vmx_ops.h index 5fa74779a37a..33af7b4c6eb4 100644 --- a/arch/x86/kvm/vmx/vmx_ops.h +++ b/arch/x86/kvm/vmx/vmx_ops.h @@ -108,8 +108,7 @@ static __always_inline unsigned long __vmcs_readl(unsig= ned long field) =20 do_fail: instrumentation_begin(); - WARN_ONCE(1, KBUILD_MODNAME ": vmread failed: field=3D%lx\n", field); - pr_warn_ratelimited(KBUILD_MODNAME ": vmread failed: field=3D%lx\n", fiel= d); + vmread_error(field); instrumentation_end(); return 0; =20 --=20 2.41.0.487.g6d72f3e995-goog