Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp638807rdh; Sun, 24 Sep 2023 05:46:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGoHTupVRWpHGisSVeENTQOVYxBTU1uAZNR5W9SWwKIQmoYOVXqovd6demlQkqIsx+4634h X-Received: by 2002:a05:6a20:734f:b0:15f:b5:bfee with SMTP id v15-20020a056a20734f00b0015f00b5bfeemr236053pzc.5.1695559560853; Sun, 24 Sep 2023 05:46:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695559560; cv=none; d=google.com; s=arc-20160816; b=u2Q/lhPqpos20r1sqaD9rFYcOENBX8G2CTBlC080z9av+sm4Inu+8hoYjzmxcZ2Hyf 1mWRYToNw0Fk0ja5PIqAAHj8TZovtZF7B/F6VehABiLXJXT9/R4MkWo0jbFREA8z5tH+ RLiW1jDj8gGaDBR6p3WPfpI1K9mkfmpZWgyqloO8w/beTpzQsOpUuxYrDzGWwjEZEBN3 RCBQnZyf03+N6R1gS3WJvNNgXPhgR2XWKR4Rq5pLqLYk7jKYUtbL2MpRNMRFkqzdY86s 6UavkMV66aiBKMnVCQpJ5MRyWQ7g50eyPFPh4q8ElZvXZEVRAv0dPSLIqvyOxDOE3JtZ +7GA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fFJC83yFEMh96Rc1m+ZUEAQuB1+TZDtoy8648SDKRR8=; fh=OD5LJn7r8xaW8Hto+Zrc7PP2Q/aiDb2yLCcOHFkx4kw=; b=F1Gj3ysYxT58xNOcKVq/KyJsqk5jzYwi3B7YBB9S88aBau6gRXAmuK3qaGAVFDm3OA TjNtpelrEen35sOKI7pYodWCTMNeJYi1yfSK48Cjag9QerLySEjPifPenO+zFvfVlUwI WKhc8V8hMRkrYVK5r7fMUmPcCTZ2LE2AG6871xqBxOSzH1iA5hFlE3VMF2x5bslbMFTC pLU//z3SC+8WEH396rH6RqmL8BS8uOnzNCTy460b032LJRP2xX4+TFY5uygc0/Zac3q5 moXYa3XOkiGB+nTw6z9y+tTaqjSLIEiAlvw6MGuxMq7SvW7FJm7tCgutrgvT0ncik8JQ aBdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="BX/qFGc0"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id o4-20020a170903300400b001c60d334996si1580779pla.622.2023.09.24.05.45.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 05:46:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="BX/qFGc0"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 259E38080C56; Sun, 24 Sep 2023 05:45:22 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229717AbjIXMpP (ORCPT + 99 others); Sun, 24 Sep 2023 08:45:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229658AbjIXMpL (ORCPT ); Sun, 24 Sep 2023 08:45:11 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49328109 for ; Sun, 24 Sep 2023 05:44:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695559462; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fFJC83yFEMh96Rc1m+ZUEAQuB1+TZDtoy8648SDKRR8=; b=BX/qFGc0tPAOmTN2D6jg71JNLmG9+a+jNgN99pBrNpSZDti5TsXNRH9iUfoXMc5cHcocB7 DO0kQ5Xu/gwcA/YAwHqvVtzxWfx0v+xuSst20PGYGdZ9yzmMPq8rSuTQJYIcp343yUB0Um 7fpGUuiheAvk5rzijNAVMWc7vtTnXC0= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-142-SsqCgeoXM32n1LVmv9vs9w-1; Sun, 24 Sep 2023 08:44:20 -0400 X-MC-Unique: SsqCgeoXM32n1LVmv9vs9w-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 262241C0514F; Sun, 24 Sep 2023 12:44:20 +0000 (UTC) Received: from localhost.localdomain (unknown [10.45.226.141]) by smtp.corp.redhat.com (Postfix) with ESMTP id D103140C6EA8; Sun, 24 Sep 2023 12:44:17 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Dave Hansen , x86@kernel.org, linux-kernel@vger.kernel.org, "H. Peter Anvin" , Sean Christopherson , Paolo Bonzini , Ingo Molnar , Thomas Gleixner , Borislav Petkov , Maxim Levitsky Subject: [PATCH v2 2/4] KVM: x86: add more information to the kvm_entry tracepoint Date: Sun, 24 Sep 2023 15:44:08 +0300 Message-Id: <20230924124410.897646-3-mlevitsk@redhat.com> In-Reply-To: <20230924124410.897646-1-mlevitsk@redhat.com> References: <20230924124410.897646-1-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Spam-Status: No, score=2.7 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: ** X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Sun, 24 Sep 2023 05:45:22 -0700 (PDT) Add: - Flag showing that VM is in a guest mode on entry. - Flag showing that immediate vm exit is set to happen after the entry. - VMX/SVM specific interrupt injection info (like in a vm exit). Signed-off-by: Maxim Levitsky --- arch/x86/include/asm/kvm-x86-ops.h | 1 + arch/x86/include/asm/kvm_host.h | 5 ++++- arch/x86/kvm/svm/svm.c | 17 +++++++++++++++++ arch/x86/kvm/trace.h | 19 +++++++++++++++++-- arch/x86/kvm/vmx/vmx.c | 12 ++++++++++++ 5 files changed, 51 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/kvm-x86-ops.h b/arch/x86/include/asm/kvm-x86-ops.h index f654a7f4cc8c0c..346fed6e3c33aa 100644 --- a/arch/x86/include/asm/kvm-x86-ops.h +++ b/arch/x86/include/asm/kvm-x86-ops.h @@ -99,6 +99,7 @@ KVM_X86_OP(get_l2_tsc_multiplier) KVM_X86_OP(write_tsc_offset) KVM_X86_OP(write_tsc_multiplier) KVM_X86_OP(get_exit_info) +KVM_X86_OP(get_entry_info) KVM_X86_OP(check_intercept) KVM_X86_OP(handle_exit_irqoff) KVM_X86_OP(sched_in) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 383a1d0cc0743b..321721813474f7 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1679,13 +1679,16 @@ struct kvm_x86_ops { void (*write_tsc_multiplier)(struct kvm_vcpu *vcpu); /* - * Retrieve somewhat arbitrary exit information. Intended to + * Retrieve somewhat arbitrary exit/entry information. Intended to * be used only from within tracepoints or error paths. */ void (*get_exit_info)(struct kvm_vcpu *vcpu, u32 *reason, u64 *info1, u64 *info2, u32 *exit_int_info, u32 *exit_int_info_err_code); + void (*get_entry_info)(struct kvm_vcpu *vcpu, + u32 *inj_info, u32 *inj_info_error_code); + int (*check_intercept)(struct kvm_vcpu *vcpu, struct x86_instruction_info *info, enum x86_intercept_stage stage, diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 60b130b7f9d510..cd65c04be3d0e2 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -3504,6 +3504,22 @@ static void svm_get_exit_info(struct kvm_vcpu *vcpu, u32 *reason, *error_code = 0; } +static void svm_get_entry_info(struct kvm_vcpu *vcpu, + u32 *inj_info, + u32 *inj_info_error_code) +{ + struct vmcb_control_area *control = &to_svm(vcpu)->vmcb->control; + + *inj_info = control->event_inj; + + if ((*inj_info & SVM_EXITINTINFO_VALID) && + (*inj_info & SVM_EXITINTINFO_VALID_ERR)) + *inj_info_error_code = control->event_inj_err; + else + *inj_info_error_code = 0; + +} + static int svm_handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath) { struct vcpu_svm *svm = to_svm(vcpu); @@ -4992,6 +5008,7 @@ static struct kvm_x86_ops svm_x86_ops __initdata = { .required_apicv_inhibits = AVIC_REQUIRED_APICV_INHIBITS, .get_exit_info = svm_get_exit_info, + .get_entry_info = svm_get_entry_info, .vcpu_after_set_cpuid = svm_vcpu_after_set_cpuid, diff --git a/arch/x86/kvm/trace.h b/arch/x86/kvm/trace.h index 83843379813ee3..f4c56f59f5c11b 100644 --- a/arch/x86/kvm/trace.h +++ b/arch/x86/kvm/trace.h @@ -21,14 +21,29 @@ TRACE_EVENT(kvm_entry, TP_STRUCT__entry( __field( unsigned int, vcpu_id ) __field( unsigned long, rip ) - ), + __field( u32, inj_info ) + __field( u32, inj_info_err ) + __field( bool, guest_mode ) + __field( bool, req_imm_exit ) + ), TP_fast_assign( __entry->vcpu_id = vcpu->vcpu_id; __entry->rip = kvm_rip_read(vcpu); + + static_call(kvm_x86_get_entry_info)(vcpu, + &__entry->inj_info, + &__entry->inj_info_err); + + __entry->req_imm_exit = vcpu->arch.req_immediate_exit; + __entry->guest_mode = is_guest_mode(vcpu); ), - TP_printk("vcpu %u, rip 0x%lx", __entry->vcpu_id, __entry->rip) + TP_printk("vcpu %u, rip 0x%lx inj 0x%08x inj_error_code 0x%08x%s%s", + __entry->vcpu_id, __entry->rip, + __entry->inj_info, __entry->inj_info_err, + __entry->req_imm_exit ? " [imm exit]" : "", + __entry->guest_mode ? " [guest]" : "") ); /* diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index eb7e42235e8811..9dd13f52d4999c 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -6156,6 +6156,17 @@ static void vmx_get_exit_info(struct kvm_vcpu *vcpu, u32 *reason, } } +static void vmx_get_entry_info(struct kvm_vcpu *vcpu, + u32 *inj_info, + u32 *inj_info_error_code) +{ + *inj_info = vmcs_read32(VM_ENTRY_INTR_INFO_FIELD); + if (is_exception_with_error_code(*inj_info)) + *inj_info_error_code = vmcs_read32(VM_ENTRY_EXCEPTION_ERROR_CODE); + else + *inj_info_error_code = 0; +} + static void vmx_destroy_pml_buffer(struct vcpu_vmx *vmx) { if (vmx->pml_pg) { @@ -8297,6 +8308,7 @@ static struct kvm_x86_ops vmx_x86_ops __initdata = { .get_mt_mask = vmx_get_mt_mask, .get_exit_info = vmx_get_exit_info, + .get_entry_info = vmx_get_entry_info, .vcpu_after_set_cpuid = vmx_vcpu_after_set_cpuid, -- 2.26.3