Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2277014pxp; Mon, 21 Mar 2022 15:39:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/NE/HTSvb8KbYIHYV9ncRl//N98X3cNcDngTjUItjDwnCr0a6XYChzx783tNX5ZZbvFx3 X-Received: by 2002:a17:90b:3904:b0:1c6:c1f8:cbd8 with SMTP id ob4-20020a17090b390400b001c6c1f8cbd8mr1408493pjb.53.1647902394857; Mon, 21 Mar 2022 15:39:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647902394; cv=none; d=google.com; s=arc-20160816; b=jSaM8WsVQE7CKTfqsODYCmVM5+61BWgQelOB4vrcO18E8+NGMpHVbAExvFqMmqb1Bk Pbg+fLx6rif01XgQ7mCY2u1ilLmI8WZiIdoSJJVS7/TtPASx6jkbjIcyGxDZqWTsG8Gh b3RvPe74wDS8jQgNAIuAgMDdT2FW/eqXBgNNcGsfWnDv6jddoYpAnHEZrk5jz9xW9TTR NwZ4Eb5I7xc6mnC9lrqjpjHWodR6gsKuVIPoinRvkkm3TFSsyu2QgDAjG1UjpU1kdrDK lzJdzilU7SSJJIijugq9Z8Na46843fiiLCiuOYBrcRxj8JDcEIv1ooGwYX5vFUnLpAT+ 7/bQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=MPBHLr0cnx+S1dvf9V9sqGfXPZPsxNMBB1OP6fOxbfo=; b=iWb3XbjK91vH/SdPWuhbq8A1R3aZEkyqKa2HjGFdwwJxALm/Sz8eT9Y3tTlnC3Ajh/ 9+eihsHx5gP6zhxSUaZHd528hrNHiShV/GT3snVb0k6GJBOHdGcjOuaH4IA3B5pQlwa2 8xT4eMQP257gDQmLyxuR38i5yZu1yz2p4cewM1Mw5uNH5YXhBXKt4R9LkiXhGmP1OJNN RAftQbcNQyuRGRZ9d233lxjOi6NqgWEvu8+Bi/d3b9Qk4ZD5IFAJBQ1XrsFzuhjNW1oD Bq0WMPySHL8oNBErFoO5tXmQiqxeWAj4u7PyG6BDukTH8TAXM4mLtxzFSqVWdHSaGRen dG+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=JFFEh1CT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id n1-20020a170903110100b00153b2d16545si11382562plh.333.2022.03.21.15.39.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 15:39:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=JFFEh1CT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CB66A3C7353; Mon, 21 Mar 2022 14:50:50 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352009AbiCUSJu (ORCPT + 99 others); Mon, 21 Mar 2022 14:09:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351995AbiCUSJq (ORCPT ); Mon, 21 Mar 2022 14:09:46 -0400 Received: from mail-yw1-x112f.google.com (mail-yw1-x112f.google.com [IPv6:2607:f8b0:4864:20::112f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 423F5387B5 for ; Mon, 21 Mar 2022 11:08:20 -0700 (PDT) Received: by mail-yw1-x112f.google.com with SMTP id 00721157ae682-2d07ae0b1c0so165070757b3.2 for ; Mon, 21 Mar 2022 11:08:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=MPBHLr0cnx+S1dvf9V9sqGfXPZPsxNMBB1OP6fOxbfo=; b=JFFEh1CTGLbS7t3f7mr0ceuCtf00CYZBnI4evLM7E4wDEEhE/w8kiOWfjfqIgas2Lc yhbz9cou9K3ZQNWVwAZuXk04N/Ouym7QdnoNUAR8OBUXWCmWr0UeVeprTUicc/NfrsJ7 4hc2NQ+tKEJZJOOk0V+7Gcju8PCa6w9AfEFNI94XiIqJ5CW+u8VfFKh7J5LErquzFlRo xBe9yhPXjwhfBXyWFWPDmhgvfquTvn7CZC2cfh9qCiCaSJPXMc55hgrtfIzXJ6y2bRhx f+kMY70XmmzigJCqkvcinx88w57JNMpO9yS819FDxXspGbGIEGBXOQbqyVD4LnFwNtaf CmpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=MPBHLr0cnx+S1dvf9V9sqGfXPZPsxNMBB1OP6fOxbfo=; b=qgGXQLj2jp+vbtFkwd+53r/Qe4umSpDsms5qB4e4szX8oizXKzuZJ+Y2s+ZNPx0Uqt aQF7Q2kJhLHmq7AMsYn2bVty6QHOiJ+J7I7T4Rsrp894XDHpsiqQ6Q1rduDJViS70JPz baKZ2AYlp2AXYkZ/3a7cqJfz1Fp6fI88g1qg5ISHwORcFW59bVYeXG3GK4qRYn9ZSPRc Es5y/qOpJoEvvS/u5PjUU505ThZlVRHZsYk9ybUhisZbPrUfGo90QySxcM8SNO/iMXeH WHpe83tnRVpl7o4pToBkAoWBnReI93o0bEtZDzgMZI1+agRkqr1Z6CCobFoF+nWfM4K4 y47g== X-Gm-Message-State: AOAM533ZwME9SiIYphO1Ztz7K09e9qYn0FHlggt55hSq2Pqr75FIoaNM UW75XFFNqp39XMSsUVLRirpWeDTOAgqttzfqVjLQnQ== X-Received: by 2002:a0d:d44e:0:b0:2e5:dc71:c82b with SMTP id w75-20020a0dd44e000000b002e5dc71c82bmr16488979ywd.42.1647886098873; Mon, 21 Mar 2022 11:08:18 -0700 (PDT) MIME-Version: 1.0 References: <20220321002638.379672-1-mizhang@google.com> <20220321002638.379672-5-mizhang@google.com> In-Reply-To: <20220321002638.379672-5-mizhang@google.com> From: Ben Gardon Date: Mon, 21 Mar 2022 11:08:08 -0700 Message-ID: Subject: Re: [PATCH 4/4] selftests: KVM: use dirty logging to check if page stats work correctly To: Mingwei Zhang Cc: Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, David Matlack , Jing Zhang , Peter Xu , Ben Gardon Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Mar 20, 2022 at 5:26 PM Mingwei Zhang wrote: > > When dirty logging is enabled, KVM splits the all hugepage mapping in > NPT/EPT into the smallest 4K size. This property could be used to check if > the page stats metrics work properly in KVM mmu. At the same time, this > logic might be used the other way around: using page stats to verify if > dirty logging really splits all huge pages. Moreover, when dirty logging is > disabled, KVM zaps corresponding SPTEs and we could check whether the large > pages come back when guest touches the pages again. > > So add page stats checking in dirty logging performance selftest. In > particular, add checks in three locations: > - just after vm is created; > - after populating memory into vm but before enabling dirty logging; > - just after turning on dirty logging. > - after one final iteration after turning off dirty logging. > > Tested using commands: > - ./dirty_log_perf_test -s anonymous_hugetlb_1gb > - ./dirty_log_perf_test -s anonymous_thp > > Cc: Sean Christopherson > Cc: David Matlack > Cc: Jing Zhang > Cc: Peter Xu > > Suggested-by: Ben Gardon Woops, got a mail bounce from this. Should be: Suggested-by: Ben Gardon > Signed-off-by: Mingwei Zhang > --- > .../selftests/kvm/dirty_log_perf_test.c | 52 +++++++++++++++++++ > 1 file changed, 52 insertions(+) > > diff --git a/tools/testing/selftests/kvm/dirty_log_perf_test.c b/tools/testing/selftests/kvm/dirty_log_perf_test.c > index 1954b964d1cf..ab0457d91658 100644 > --- a/tools/testing/selftests/kvm/dirty_log_perf_test.c > +++ b/tools/testing/selftests/kvm/dirty_log_perf_test.c > @@ -19,6 +19,10 @@ > #include "perf_test_util.h" > #include "guest_modes.h" > > +#ifdef __x86_64__ > +#include "processor.h" > +#endif > + > /* How many host loops to run by default (one KVM_GET_DIRTY_LOG for each loop)*/ > #define TEST_HOST_LOOP_N 2UL > > @@ -185,6 +189,14 @@ static void run_test(enum vm_guest_mode mode, void *arg) > p->slots, p->backing_src, > p->partition_vcpu_memory_access); > > +#ifdef __x86_64__ > + TEST_ASSERT(vm_get_single_stat(vm, "pages_4k") == 0, > + "4K page is non zero"); > + TEST_ASSERT(vm_get_single_stat(vm, "pages_2m") == 0, > + "2M page is non zero"); > + TEST_ASSERT(vm_get_single_stat(vm, "pages_1g") == 0, > + "1G page is non zero"); > +#endif > perf_test_set_wr_fract(vm, p->wr_fract); > > guest_num_pages = (nr_vcpus * guest_percpu_mem_size) >> vm_get_page_shift(vm); > @@ -222,6 +234,16 @@ static void run_test(enum vm_guest_mode mode, void *arg) > pr_info("Populate memory time: %ld.%.9lds\n", > ts_diff.tv_sec, ts_diff.tv_nsec); > > +#ifdef __x86_64__ > + TEST_ASSERT(vm_get_single_stat(vm, "pages_4k") != 0, > + "4K page is zero"); > + if (p->backing_src == VM_MEM_SRC_ANONYMOUS_THP) > + TEST_ASSERT(vm_get_single_stat(vm, "pages_2m") != 0, > + "2M page is zero"); > + if (p->backing_src == VM_MEM_SRC_ANONYMOUS_HUGETLB_1GB) > + TEST_ASSERT(vm_get_single_stat(vm, "pages_1g") != 0, > + "1G page is zero"); > +#endif > /* Enable dirty logging */ > clock_gettime(CLOCK_MONOTONIC, &start); > enable_dirty_logging(vm, p->slots); > @@ -267,6 +289,14 @@ static void run_test(enum vm_guest_mode mode, void *arg) > iteration, ts_diff.tv_sec, ts_diff.tv_nsec); > } > } > +#ifdef __x86_64__ > + TEST_ASSERT(vm_get_single_stat(vm, "pages_4k") != 0, > + "4K page is zero after dirty logging"); > + TEST_ASSERT(vm_get_single_stat(vm, "pages_2m") == 0, > + "2M page is non-zero after dirty logging"); > + TEST_ASSERT(vm_get_single_stat(vm, "pages_1g") == 0, > + "1G page is non-zero after dirty logging"); > +#endif > > /* Disable dirty logging */ > clock_gettime(CLOCK_MONOTONIC, &start); > @@ -275,6 +305,28 @@ static void run_test(enum vm_guest_mode mode, void *arg) > pr_info("Disabling dirty logging time: %ld.%.9lds\n", > ts_diff.tv_sec, ts_diff.tv_nsec); > > +#ifdef __x86_64__ > + /* > + * Increment iteration to run the vcpus again to verify if huge pages > + * come back. > + */ > + iteration++; > + pr_info("Starting the final iteration to verify page stats\n"); > + > + for (vcpu_id = 0; vcpu_id < nr_vcpus; vcpu_id++) { > + while (READ_ONCE(vcpu_last_completed_iteration[vcpu_id]) > + != iteration) > + ; > + } > + > + if (p->backing_src == VM_MEM_SRC_ANONYMOUS_THP) > + TEST_ASSERT(vm_get_single_stat(vm, "pages_2m") != 0, > + "2M page is zero"); > + if (p->backing_src == VM_MEM_SRC_ANONYMOUS_HUGETLB_1GB) > + TEST_ASSERT(vm_get_single_stat(vm, "pages_1g") != 0, > + "1G page is zero"); > +#endif > + > /* Tell the vcpu thread to quit */ > host_quit = true; > perf_test_join_vcpu_threads(nr_vcpus); > -- > 2.35.1.894.gb6a874cedc-goog >