From patchwork Tue Oct 27 17:59:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Gardon X-Patchwork-Id: 11861265 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC057C55178 for ; Tue, 27 Oct 2020 18:01:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5CB1921655 for ; Tue, 27 Oct 2020 18:01:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ETkQP5HG" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1823940AbgJ0SA7 (ORCPT ); Tue, 27 Oct 2020 14:00:59 -0400 Received: from mail-pj1-f74.google.com ([209.85.216.74]:55818 "EHLO mail-pj1-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1823703AbgJ0R7s (ORCPT ); Tue, 27 Oct 2020 13:59:48 -0400 Received: by mail-pj1-f74.google.com with SMTP id r1so1206096pjp.5 for ; Tue, 27 Oct 2020 10:59:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:message-id:mime-version:subject:from:to:cc; bh=ZbaL988uKrohM7H6ZS9XBC1GZUReqphtGwoVjHruBgI=; b=ETkQP5HGCh/KwMlK6Oa4F6JkS2Vrb4/abSeRSBvhnNdoh7fS6XT3reiyLt2vKVEC0z M9iipXbsW21hYHi4VY4x6NVg9OXjZAUZPAZnHb7jYSlaf4x1ZFfY0FUxi1xSxbrBP5f/ +F5/GDtp3fd8zI9NK/53rWJ6NJurivwnp9kVLRvzrui/mQTKomi0YHubwm/FCoviFIT3 Ozgg0HEh4WKWyKEIjr4VumLXFvyuC1skb2uVBq/lkf46H/hvZAtgFyg17x/qvSZkyUsF 8ZTcFNbTXGcZI883jiYK3JocvhaDa/1CI4lDm53uHpwtHEkWyzhHpBepYSwTuTlQw8uo ArSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:message-id:mime-version:subject:from :to:cc; bh=ZbaL988uKrohM7H6ZS9XBC1GZUReqphtGwoVjHruBgI=; b=lmBDTy3d7H0skHwRVMTU5znPLmH2EFZwZ8TsnNMDcsD1TCMQDHFpEjg/z3OmCSIlVU E4n1vQ969SlPZd+a3i3cIH6zf3GDqIj6bKT6BbB6h/ZaSdfXlgz4EFFXCHGioabu73yv JPL1LqcwaXE976ajrah0IbZOhRH5L9b+1sH2+cXAjjANbAYnU4H4ckOTpFwWLqYu83j7 fQuySBjCR+RPQiILNhyA/t7lo1dau+Q7f1bRbZ9BxgQiIewJlaVmYvNrh6Nt4FNc0LZ2 v6VIytEoKJtrRC5nwEhOf6hjPCleFi7EVphQnlWsGlbY3fzHDWMmKCTXWpZwXuqmNgm7 U3dw== X-Gm-Message-State: AOAM53073pYo/B61m4hUvFNiSiq7+jwC6XgDYumgEENDToGgqIfRjGC/ vgZqzmefTNIB+x4Ig2CJW1NmE2NLnjJ/ X-Google-Smtp-Source: ABdhPJxHHWvVxLU1UFqepNXpxQRVm0nystR88ugkX/J00ithmflQf37LyJF5KikOJDXp10J+BKeVZjWT3LcQ Sender: "bgardon via sendgmr" X-Received: from bgardon.sea.corp.google.com ([2620:15c:100:202:f693:9fff:fef4:a293]) (user=bgardon job=sendgmr) by 2002:a17:90b:f85:: with SMTP id ft5mr266022pjb.1.1603821587576; Tue, 27 Oct 2020 10:59:47 -0700 (PDT) Date: Tue, 27 Oct 2020 10:59:43 -0700 Message-Id: <20201027175944.1183301-1-bgardon@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.29.0.rc2.309.g374f81d7ae-goog Subject: [PATCH 1/2] kvm: x86/mmu: Add existing trace points to TDP MMU From: Ben Gardon To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , Peter Xu , Sean Christopherson , Peter Shier , Junaid Shahid , Peter Feiner , Ben Gardon Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The TDP MMU was initially implemented without some of the usual tracepoints found in mmu.c. Correct this discrepancy by adding the missing trace points to the TDP MMU. Tested: ran the demand paging selftest on an Intel Skylake machine with all the trace points used by the TDP MMU enabled and observed them firing with expected values. This patch can be viewed in Gerrit at: https://linux-review.googlesource.com/c/virt/kvm/kvm/+/3812 Signed-off-by: Ben Gardon --- arch/x86/kvm/mmu/tdp_mmu.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index 27e381c9da6c2..047e2d966abef 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.c +++ b/arch/x86/kvm/mmu/tdp_mmu.c @@ -7,6 +7,8 @@ #include "tdp_mmu.h" #include "spte.h" +#include + #ifdef CONFIG_X86_64 static bool __read_mostly tdp_mmu_enabled = false; module_param_named(tdp_mmu, tdp_mmu_enabled, bool, 0644); @@ -101,6 +103,8 @@ static struct kvm_mmu_page *alloc_tdp_mmu_page(struct kvm_vcpu *vcpu, gfn_t gfn, sp->gfn = gfn; sp->tdp_mmu_page = true; + trace_kvm_mmu_get_page(sp, true); + return sp; } @@ -271,6 +275,8 @@ static void __handle_changed_spte(struct kvm *kvm, int as_id, gfn_t gfn, pt = spte_to_child_pt(old_spte, level); sp = sptep_to_sp(pt); + trace_kvm_mmu_prepare_zap_page(sp); + list_del(&sp->link); if (sp->lpage_disallowed) @@ -473,11 +479,13 @@ static int tdp_mmu_map_handle_target_level(struct kvm_vcpu *vcpu, int write, if (unlikely(is_noslot_pfn(pfn))) { new_spte = make_mmio_spte(vcpu, iter->gfn, ACC_ALL); trace_mark_mmio_spte(iter->sptep, iter->gfn, new_spte); - } else + } else { make_spte_ret = make_spte(vcpu, ACC_ALL, iter->level, iter->gfn, pfn, iter->old_spte, prefault, true, map_writable, !shadow_accessed_mask, &new_spte); + trace_kvm_mmu_set_spte(iter->level, iter->gfn, iter->sptep); + } if (new_spte == iter->old_spte) ret = RET_PF_SPURIOUS; @@ -691,6 +699,8 @@ static int age_gfn_range(struct kvm *kvm, struct kvm_memory_slot *slot, tdp_mmu_set_spte_no_acc_track(kvm, &iter, new_spte); young = 1; + + trace_kvm_age_page(iter.gfn, iter.level, slot, young); } return young; From patchwork Tue Oct 27 17:59:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Gardon X-Patchwork-Id: 11861263 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3DD5EC388F9 for ; Tue, 27 Oct 2020 18:01:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DE0AE21556 for ; Tue, 27 Oct 2020 18:01:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="AVgaJ/v4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1823945AbgJ0SBA (ORCPT ); Tue, 27 Oct 2020 14:01:00 -0400 Received: from mail-qk1-f201.google.com ([209.85.222.201]:48887 "EHLO mail-qk1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1823725AbgJ0R7w (ORCPT ); Tue, 27 Oct 2020 13:59:52 -0400 Received: by mail-qk1-f201.google.com with SMTP id z16so1309913qkg.15 for ; Tue, 27 Oct 2020 10:59:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=pOTcENHU6wqJJ3cPGXaUEXXcmuzILdwS9IUGREQEYLU=; b=AVgaJ/v4KywVIrgTz57lMlfjx3jDjDwAYJ6aYsfyb2gTP1Endgev6TCUT6NK3dVO5c 9vlF0AfnyBKeqndCJVCcvnGjqblnfDahVldKiOBsM6O1aSUZ/wucJ21H956cTu0o5py8 p9LWSHkquW05lQbYO61oW0VxGH3gdW+yu0gxSNcQBDt76xRUT3oChrv2fl1JL+UHtSe3 ng2sehmakCgFytvf2alnQjipxnQC/c8QFaPsvwYwc+FlogWLd4vuiN+EDi2jo5TlTN8o kcyJaVBtKeNGoutAl31mvIemzV5GGS/QHTKSSRZzYJ453UY3DjQNTn/9OxFAqTn2Avfl xXng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=pOTcENHU6wqJJ3cPGXaUEXXcmuzILdwS9IUGREQEYLU=; b=TeuYWuou7pzeMHBTsjdEGRfjkYQJSc9othdvwtHhAmsJM77NnVnU6TvbbxEKz2tGhm ekTkTcoffltiySJOwwJfkwipJOtsMOENbMnyeCE8p8TE5DEk3j7nL4Ar1fGFFdA1QVRh oBAvJi+vdEle6EUg06lYvKU7xp0mlM6CJECe2+jM//4HmmSp5ibe+C3roLAXGmeV/NP1 F4DlPjr1ozy5IvnrMAAITXh0N/2IM651/yKLuxohZI9en9fV5C/X8Trmq70uEXhKkMta GxrGK7+Tz0q36rbOeQyIp32c3Hp5V6/h6/f2gdkSWk4cxH4NtqzvwCxRCoAoQVJ+Y6Vh LcKw== X-Gm-Message-State: AOAM531hywQrFdxd28UAAy4NFGzqGspGiyTTePo4cGOMMpvBJo9U+Z3J u5bCUO8ZeEmefVbeHQFQX2Ic/XGAFuod X-Google-Smtp-Source: ABdhPJxXP3MCaof8IMN7lQHYqo/fDn4xCqd6YNisdN1pPMqUmwwr3qGS47G3JTeiSwOHNBj3loLOA/XHaVDc Sender: "bgardon via sendgmr" X-Received: from bgardon.sea.corp.google.com ([2620:15c:100:202:f693:9fff:fef4:a293]) (user=bgardon job=sendgmr) by 2002:a0c:e054:: with SMTP id y20mr3875558qvk.30.1603821589510; Tue, 27 Oct 2020 10:59:49 -0700 (PDT) Date: Tue, 27 Oct 2020 10:59:44 -0700 In-Reply-To: <20201027175944.1183301-1-bgardon@google.com> Message-Id: <20201027175944.1183301-2-bgardon@google.com> Mime-Version: 1.0 References: <20201027175944.1183301-1-bgardon@google.com> X-Mailer: git-send-email 2.29.0.rc2.309.g374f81d7ae-goog Subject: [PATCH 2/2] kvm: x86/mmu: Add TDP MMU SPTE changed trace point From: Ben Gardon To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , Peter Xu , Sean Christopherson , Peter Shier , Junaid Shahid , Peter Feiner , Ben Gardon Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add an extremely verbose trace point to the TDP MMU to log all SPTE changes, regardless of callstack / motivation. This is useful when a complete picture of the paging structure is needed or a change cannot be explained with the other, existing trace points. Tested: ran the demand paging selftest on an Intel Skylake machine with all the trace points used by the TDP MMU enabled and observed them firing with expected values. This patch can be viewed in Gerrit at: https://linux-review.googlesource.com/c/virt/kvm/kvm/+/3813 Signed-off-by: Ben Gardon --- arch/x86/kvm/mmu/mmutrace.h | 29 +++++++++++++++++++++++++++++ arch/x86/kvm/mmu/tdp_mmu.c | 2 ++ 2 files changed, 31 insertions(+) diff --git a/arch/x86/kvm/mmu/mmutrace.h b/arch/x86/kvm/mmu/mmutrace.h index 213699b27b448..e798489b56b55 100644 --- a/arch/x86/kvm/mmu/mmutrace.h +++ b/arch/x86/kvm/mmu/mmutrace.h @@ -381,6 +381,35 @@ TRACE_EVENT( ) ); +TRACE_EVENT( + kvm_tdp_mmu_spte_changed, + TP_PROTO(int as_id, gfn_t gfn, int level, u64 old_spte, u64 new_spte), + TP_ARGS(as_id, gfn, level, old_spte, new_spte), + + TP_STRUCT__entry( + __field(u64, gfn) + __field(u64, old_spte) + __field(u64, new_spte) + /* Level cannot be larger than 5 on x86, so it fits in a u8. */ + __field(u8, level) + /* as_id can only be 0 or 1 x86, so it fits in a u8. */ + __field(u8, as_id) + ), + + TP_fast_assign( + __entry->gfn = gfn; + __entry->old_spte = old_spte; + __entry->new_spte = new_spte; + __entry->level = level; + __entry->as_id = as_id; + ), + + TP_printk("as id %d gfn %llx level %d old_spte %llx new_spte %llx", + __entry->as_id, __entry->gfn, __entry->level, + __entry->old_spte, __entry->new_spte + ) +); + #endif /* _TRACE_KVMMMU_H */ #undef TRACE_INCLUDE_PATH diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index 047e2d966abef..5820c36ccfdca 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.c +++ b/arch/x86/kvm/mmu/tdp_mmu.c @@ -241,6 +241,8 @@ static void __handle_changed_spte(struct kvm *kvm, int as_id, gfn_t gfn, if (old_spte == new_spte) return; + trace_kvm_tdp_mmu_spte_changed(as_id, gfn, level, old_spte, new_spte); + /* * The only times a SPTE should be changed from a non-present to * non-present state is when an MMIO entry is installed/modified/