From mboxrd@z Thu Jan 1 00:00:00 1970 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 3DF24C433EF for ; Fri, 1 Apr 2022 06:36:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245446AbiDAGid (ORCPT ); Fri, 1 Apr 2022 02:38:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234891AbiDAGib (ORCPT ); Fri, 1 Apr 2022 02:38:31 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D034018BCD7 for ; Thu, 31 Mar 2022 23:36:42 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-2e9e838590dso18639407b3.5 for ; Thu, 31 Mar 2022 23:36:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:message-id:mime-version:subject:from:to:cc; bh=XQvLD2+VCYd8ujZZrqgQBNdJ/k/pqWdcD1uVLP/SETA=; b=sH93jOlXhmqZmKDjrsQbSWVdjXjJqk+GKrq1tU8ecmKG9I9YGN1wq9h9X3EHpxMLhD rGHw1tW7KIdSh+hYASkRfIqbbyE0JcM8HeORxn1Lcnp+q/b8AoLTx8nQ8po3wxLys0bS QlNIaKsfbtMkSxFTSXoyPnY2iDkhlvk6sdhZ48tsByMCAAO72C6WonIqHvDw/hcPNKvQ p3w6y5MApQdxoD1UndJkoSG9aogE/xQnXzDkAv9+4hYCo4/6H5qsmer4RSr0q6clYVjY sru4JNUxygoVeynQGPA7i7mCBW6s2nhAveOY5ZET2JNArgNKJrmcqp70euMsY5vZizNQ SjsQ== 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:message-id:mime-version:subject :from:to:cc; bh=XQvLD2+VCYd8ujZZrqgQBNdJ/k/pqWdcD1uVLP/SETA=; b=26qEYS7OGhda/UAxvMBobB69Vdw/PAPhgTZaNDUGtkFr7udWuxzgwSyhVqooAhfzuk bHGiPOjodSlcjMkOspRr2kAF6Zm1sWDRzN4+CkAefDq0E8Jz4gjWz2tmYvEvFs+SkUsk q0XV9m3aUqssS3qxivRaqt/0GvMSt7dzIUMYypFmugID4rNWzuujqScBDl16NFYzlBWh qKYnjqPGDafTUMXcRSeADA7VmfKjtpoG4gWSflNX4khbaxlJzinczB33WxmoBXh5REq5 uhZdKGKoXgmRRXjBcAtRoBx5OgeYzY+sTIV8Y272/H1h71BgY4F4uiA5T1bJycbc/a99 Pg/g== X-Gm-Message-State: AOAM532L1ompnyJZGqzRpkG3fn518kXb8jIhamFvCJRYoF+fw5fCGgmX VQkMW8q3Zr7rgDJB6iJgA7za+dGF/3A7 X-Google-Smtp-Source: ABdhPJxZ7sZf94C9h1cvuMDEav1FZz68pj0JWMlS+wdg+e54npkSGG3TjrUEs8SuBMuUEoDmw/c8BxsJIPyB X-Received: from mizhang-super.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1071]) (user=mizhang job=sendgmr) by 2002:a25:cdca:0:b0:633:c810:6ca with SMTP id d193-20020a25cdca000000b00633c81006camr7285622ybf.261.1648795002090; Thu, 31 Mar 2022 23:36:42 -0700 (PDT) Reply-To: Mingwei Zhang Date: Fri, 1 Apr 2022 06:36:30 +0000 Message-Id: <20220401063636.2414200-1-mizhang@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.35.1.1094.g7c7d902a7c-goog Subject: [PATCH v3 0/6] Verify dirty logging works properly with page stats 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 , Yosry Ahmed , Ben Gardon , David Matlack , Jing Zhang , Peter Xu Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch set aims to fix a bug in which KVM incorrectly assumes a large page as a NX huge page. The bug would prevent guest VM from regaining large pages and cause performance issue. We fix the bug by explicitly checking the lpage_disallowed field in the shadow page. Moreover, to fix the bug properly for TDP MMU, we integrate two patches from Sean that ensures that we update lpage_disallowed in shadow page before making spte visible to guest. To verify the bug fixed, we use dirty logging as the testing target and dirty_log_perf_test as the selftest binary. By adding the code to check the page stats from the per-VM interface, we discovered that VMs could regain large pages after dirty logging disabled. We also verify the existence of the bug if running with unpatched kernels. To make the selftest working properly with per-VM stats interface, we borrowes two patches come from Ben's series: "[PATCH 00/13] KVM: x86: Add a cap to disable NX hugepages on a VM" [1]. [1] https://lore.kernel.org/all/20220310164532.1821490-2-bgardon@google.com/T/ v2 -> v3: - Update lpage_disallowed before making spte visible [seanjc]. - Adding tdp_mmu_pages stats [seanjc] - update comments in selftest [bgardon] v2: https://lore.kernel.org/lkml/20220323184915.1335049-1-mizhang@google.com/T/ v1 -> v2: - Update the commit message. [dmatlack] - Update the comments in patch 3/4 to clarify the motivation. [bgardon] - Add another iteration in dirty_log_perf_test to regain pages [bgardon] Ben Gardon (2): KVM: selftests: Dump VM stats in binary stats test KVM: selftests: Test reading a single stat Mingwei Zhang (2): KVM: x86/mmu: explicitly check nx_hugepage in disallowed_hugepage_adjust() selftests: KVM: use page stats to check if dirty logging works properly Sean Christopherson (2): KVM: x86/mmu: Set lpage_disallowed in TDP MMU before setting SPTE KVM: x86/mmu: Track the number of TDP MMU pages, but not the actual pages arch/x86/include/asm/kvm_host.h | 11 +- arch/x86/kvm/mmu/mmu.c | 28 ++- arch/x86/kvm/mmu/mmu_internal.h | 2 +- arch/x86/kvm/mmu/tdp_mmu.c | 36 ++-- .../selftests/kvm/dirty_log_perf_test.c | 53 +++++ .../selftests/kvm/include/kvm_util_base.h | 2 + .../selftests/kvm/kvm_binary_stats_test.c | 6 + tools/testing/selftests/kvm/lib/kvm_util.c | 196 ++++++++++++++++++ 8 files changed, 303 insertions(+), 31 deletions(-) -- 2.35.1.1094.g7c7d902a7c-goog