From patchwork Fri Jul 8 23:23:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mingwei Zhang X-Patchwork-Id: 12911968 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 D8B8EC433EF for ; Fri, 8 Jul 2022 23:23:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237177AbiGHXXO (ORCPT ); Fri, 8 Jul 2022 19:23:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238896AbiGHXXK (ORCPT ); Fri, 8 Jul 2022 19:23:10 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3814B419B8 for ; Fri, 8 Jul 2022 16:23:10 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id 189-20020a6309c6000000b0041249d53b04so94211pgj.22 for ; Fri, 08 Jul 2022 16:23:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=GZ1bIqQ5uxtRbXqyYGz3rmRapEwhTBX1fk0bLa5NCD4=; b=PdWMG3dWy27dhMxJ4fqhuUZFohehK7E4Tp3pHRYmschBb1kzWcKfgVOr9q9uY8HpMr FZTDb3sBk3YA8sWIKMgqJIb7XQL2xpao3uxQH5RRErz8f0/WLFlDlmyJ531cNZsvP8cf cKtW279ZBgJh764HrljzXRrRKh12txodwcWkpAjvgNGnL0Y/AG0so6PxtEi8sKA0v/Nd LKey8WhlWjRgmFVApbD09U0wTObR3BoarmZvXRl1PTjT13+xqWUSjiFjBFhcumLLri7/ W8/33NGK2hLPO0wFT9ux9crf6/r0Kg8EthpSsCNrcDbYNU90gDBXwUYe6r2i2dy8HcZF SzlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=GZ1bIqQ5uxtRbXqyYGz3rmRapEwhTBX1fk0bLa5NCD4=; b=Yl3v1cGd/ZxuxX47tkAQ3wDkgsmIYXOVcnDOFcBHhGx3/X4WYA79Zhe37GbZlWiZaw YuuAajzrY0QDqZamYeG7mFlY+V+VMiCliGQbw3jo5MIqyGwA9imMIAuzYqOxCxarTK/0 lmWMKF3wBkJ2QCUdSsjQU//mrVoiRzho4cDREQlTupGmQbd34pZvNRxz7WYwTiDAGQE+ KHXEfR9qfH0koD9WCYSHDLDYuUCL+c1mMxWRBQJQONQqbV/0vINNvR6/Ic36SuSrHi4p sSxsSbDRIg+paVtfkC4GphzZtAqIIZJNjhYOgC+538fIhMA6nCIyRc/OvfkZi+YCIktQ diUw== X-Gm-Message-State: AJIora/+7cNOdAWYQNLdYgeiAKkfh8Nu+oCF5DcpgXmat7b05qL0yg1B 5zHwjgNDYibn+gb/0mduJovA6xuxsYAz X-Google-Smtp-Source: AGRyM1ujHh+SJnjS2KWyxXlc9BTRfZQ8ci3eKldrE8Ql4k3uN5KiObZLfq6wc5hjwI48Mcooms476LvUC13T X-Received: from mizhang-super.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1071]) (user=mizhang job=sendgmr) by 2002:a05:6a00:ac7:b0:528:7acb:e445 with SMTP id c7-20020a056a000ac700b005287acbe445mr6314370pfl.14.1657322589790; Fri, 08 Jul 2022 16:23:09 -0700 (PDT) Reply-To: Mingwei Zhang Date: Fri, 8 Jul 2022 23:23:03 +0000 In-Reply-To: <20220708232304.1001099-1-mizhang@google.com> Message-Id: <20220708232304.1001099-2-mizhang@google.com> Mime-Version: 1.0 References: <20220708232304.1001099-1-mizhang@google.com> X-Mailer: git-send-email 2.37.0.144.g8ac04bfd2-goog Subject: [PATCH 1/2] KVM: nested/x86: update trace_kvm_nested_vmrun() to suppot VMX From: Mingwei Zhang To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Mingwei Zhang , David Matlack Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Update trace_kvm_nested_vmrun() to support VMX by adding a new field 'isa'; update the output to print out VMX/SVM related naming respectively, eg., vmcb vs. vmcs; npt vs. ept. In addition, print nested EPT/NPT address instead of the 1bit of nested ept/npt on/off. This should convey more information in the trace. When nested ept/npt is not used, simply print "0x0" so that we don't lose any information. Opportunistically update the call site of trace_kvm_nested_vmrun() to make one line per parameter. Signed-off-by: Mingwei Zhang --- arch/x86/kvm/svm/nested.c | 7 +++++-- arch/x86/kvm/trace.h | 29 ++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index ba7cd26f438f..8581164b6808 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -724,11 +724,14 @@ int enter_svm_guest_mode(struct kvm_vcpu *vcpu, u64 vmcb12_gpa, struct vcpu_svm *svm = to_svm(vcpu); int ret; - trace_kvm_nested_vmrun(svm->vmcb->save.rip, vmcb12_gpa, + trace_kvm_nested_vmrun(svm->vmcb->save.rip, + vmcb12_gpa, vmcb12->save.rip, vmcb12->control.int_ctl, vmcb12->control.event_inj, - vmcb12->control.nested_ctl); + vmcb12->control.nested_ctl, + vmcb12->control.nested_cr3, + KVM_ISA_SVM); trace_kvm_nested_intercepts(vmcb12->control.intercepts[INTERCEPT_CR] & 0xffff, vmcb12->control.intercepts[INTERCEPT_CR] >> 16, diff --git a/arch/x86/kvm/trace.h b/arch/x86/kvm/trace.h index de4762517569..aac4c8bd2c3a 100644 --- a/arch/x86/kvm/trace.h +++ b/arch/x86/kvm/trace.h @@ -580,8 +580,10 @@ TRACE_EVENT(kvm_pv_eoi, */ TRACE_EVENT(kvm_nested_vmrun, TP_PROTO(__u64 rip, __u64 vmcb, __u64 nested_rip, __u32 int_ctl, - __u32 event_inj, bool npt), - TP_ARGS(rip, vmcb, nested_rip, int_ctl, event_inj, npt), + __u32 event_inj, bool npt_enabled, __u64 npt_addr, + __u32 isa), + TP_ARGS(rip, vmcb, nested_rip, int_ctl, event_inj, npt_enabled, + npt_addr, isa), TP_STRUCT__entry( __field( __u64, rip ) @@ -589,7 +591,9 @@ TRACE_EVENT(kvm_nested_vmrun, __field( __u64, nested_rip ) __field( __u32, int_ctl ) __field( __u32, event_inj ) - __field( bool, npt ) + __field( bool, npt_enabled ) + __field( __u64, npt_addr ) + __field( __u32, isa ) ), TP_fast_assign( @@ -598,14 +602,21 @@ TRACE_EVENT(kvm_nested_vmrun, __entry->nested_rip = nested_rip; __entry->int_ctl = int_ctl; __entry->event_inj = event_inj; - __entry->npt = npt; + __entry->npt_enabled = npt_enabled; + __entry->npt_addr = npt_addr; + __entry->isa = isa; ), - TP_printk("rip: 0x%016llx vmcb: 0x%016llx nrip: 0x%016llx int_ctl: 0x%08x " - "event_inj: 0x%08x npt: %s", - __entry->rip, __entry->vmcb, __entry->nested_rip, - __entry->int_ctl, __entry->event_inj, - __entry->npt ? "on" : "off") + TP_printk("rip: 0x%016llx %s: 0x%016llx nested rip: 0x%016llx " + "int_ctl: 0x%08x event_inj: 0x%08x nested %s: 0x%016llx", + __entry->rip, + __entry->isa == KVM_ISA_VMX ? "vmcs" : "vmcb", + __entry->vmcb, + __entry->nested_rip, + __entry->int_ctl, + __entry->event_inj, + __entry->isa == KVM_ISA_VMX ? "ept" : "npt", + __entry->npt_enabled ? __entry->npt_addr : 0x0) ); TRACE_EVENT(kvm_nested_intercepts, From patchwork Fri Jul 8 23:23:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mingwei Zhang X-Patchwork-Id: 12911969 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 8C3D5C43334 for ; Fri, 8 Jul 2022 23:23:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239424AbiGHXXP (ORCPT ); Fri, 8 Jul 2022 19:23:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239176AbiGHXXM (ORCPT ); Fri, 8 Jul 2022 19:23:12 -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 87D26419AE for ; Fri, 8 Jul 2022 16:23:11 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id i5-20020a170902c94500b0016a644a6008so39636pla.1 for ; Fri, 08 Jul 2022 16:23:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=YCs/Ozya1DEi/lgLzfirR8Zlh6X4WyJYUDH8smOVNLc=; b=fM2FZMwhOjn0XFbozuKXIQ0p7ngjA3tLHPA2/jJN2AHxscipUW7ePQzlBV2U0kvScb iqESxrCm7SSafg3O8a2jO1SjtJTLTEOSV1JmCyytwFlnLV6zhlumK6L2vQeYtZXL+VyO eR8e7rTCxPhOrjQt1+WgOiy2zspv0q/eEOkultnrK0vaS61gW85M74cIM89MNqPYlsEC fwjutTQwOaMHXPbw6RuYIvcO3hgTyMLH8AfTyiHWySbq0FC2sj5JOSJyylNSri5SLan8 9qDsa360ZbB8p/7Jr0xcHtJ0TvCME3qU3TaE3EUG5POX7xWdTfOBsgGawl3UujCG+wlX m3iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=YCs/Ozya1DEi/lgLzfirR8Zlh6X4WyJYUDH8smOVNLc=; b=WNpGBN2xjwPtXDdq3edPUCg0PNkCGGCc7Jq/q5RuYHI8a6fIdibBKsiP4AA5eobEBY lwcHUJ0KwnYq9cNX53/dIi94Pi4waavEXokOh9QUwQYkoKvzPYKcn7UVkcXvFcOpN1j/ UlIlbMfgXfbg1+pfrUF/zgBOH3/sAhrXpprqiE1zremjMr69Ao/YI+cdMkswH7DCKJrE f0CQBFM5Esyyz3ayj8lWxJ2SpnwJgKGIubpvJoE/t0iE0H40x6nsiBumnrXjzWhJ6znC d2yv/f7bv2q3cWCmx9/nkPggbKJbPsBdCfUuvt1SY69T5W3o+o1G673qIjIQLKlE/N+/ IsZg== X-Gm-Message-State: AJIora9RXuOKEfpei8SnGUTRzOiNfiYVngWX1m0LOtGO7+5P/gEGsb99 z3UwCwrynjqqx+8aORAsHavYI30btbWS X-Google-Smtp-Source: AGRyM1vZxxcWg4+gD+2pS+oyj5Bm5xDUty77kz3mw24tt8ks5Tmjt8Oo9+IVWAjz/X5uQnH5fqqez+UZtR4Y X-Received: from mizhang-super.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1071]) (user=mizhang job=sendgmr) by 2002:a05:6a00:2384:b0:52a:b75b:1123 with SMTP id f4-20020a056a00238400b0052ab75b1123mr2170901pfc.8.1657322591304; Fri, 08 Jul 2022 16:23:11 -0700 (PDT) Reply-To: Mingwei Zhang Date: Fri, 8 Jul 2022 23:23:04 +0000 In-Reply-To: <20220708232304.1001099-1-mizhang@google.com> Message-Id: <20220708232304.1001099-3-mizhang@google.com> Mime-Version: 1.0 References: <20220708232304.1001099-1-mizhang@google.com> X-Mailer: git-send-email 2.37.0.144.g8ac04bfd2-goog Subject: [PATCH 2/2] kvm: nVMX: add tracepoint for kvm:kvm_nested_vmrun From: Mingwei Zhang To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Mingwei Zhang , David Matlack Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: David Matlack This tracepoint is called by nested SVM during emulated VMRUN. Call also during emulated VMLAUNCH and VMRESUME in nested VMX. Attempt to use analagous VMCS fields to the VMCB fields that are reported in the SVM case: "int_ctl": 32-bit field of the VMCB that the CPU uses to deliver virtual interrupts. The analagous VMCS field is the 16-bit "guest interrupt status". "event_inj": 32-bit field of VMCB that is used to inject events (exceptions and interrupts) into the guest. The analagous VMCS field is the "VM-entry interruption-information field". "npt_enabled": 1 when the VCPU has enabled nested paging. The analagous VMCS field is the enable-EPT execution control. "npt_addr": 64-bit field when the VCPU has enabled nested paging. The analagous VMCS field is the ept_pointer. Signed-off-by: David Matlack [Add several parameters and move the code into the nested_vmx_enter_non_root_mode().] Signed-off-by: Mingwei Zhang --- arch/x86/kvm/vmx/nested.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index f5cb18e00e78..7289187b020a 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -3367,6 +3367,16 @@ enum nvmx_vmentry_status nested_vmx_enter_non_root_mode(struct kvm_vcpu *vcpu, }; u32 failed_index; + trace_kvm_nested_vmrun( + kvm_rip_read(vcpu), + vmx->nested.current_vmptr, + vmcs12->guest_rip, + vmcs12->guest_intr_status, + vmcs12->vm_entry_intr_info_field, + vmcs12->secondary_vm_exec_control & SECONDARY_EXEC_ENABLE_EPT, + vmcs12->ept_pointer, + KVM_ISA_VMX); + kvm_service_local_tlb_flush_requests(vcpu); evaluate_pending_interrupts = exec_controls_get(vmx) &