Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2502541pxp; Mon, 21 Mar 2022 22:48:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzwnmP0GWAxuNoh26tQXkcurHZgdrD0s6+xaM8Z4Y4PlcIW7Rr7r8sc481exW8DwpyEPMig X-Received: by 2002:a17:90a:a591:b0:1bc:8015:4c9e with SMTP id b17-20020a17090aa59100b001bc80154c9emr3005579pjq.154.1647928125988; Mon, 21 Mar 2022 22:48:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647928125; cv=none; d=google.com; s=arc-20160816; b=RMulS5KssSA2xn9371ZbVsQoVW1hBgzPE9oD1X3NLCjY9/+i/zdP8WdNP46ii4K6hk MvwaQCEzCOoAv2x0DlL2J6VAsVFZsz8fizspTlvrJVKg6vvXqpJGKpcSXr/MhxOGUH5C HvcC0b4+zQ2RzSXG45F3XCUl2fvd/gcegxa7fEGXtABVl0Y9GHXkDG4uezLQ8a6chhcj eb6GHVi66uY/9u0jmxfskovhBBQSxEhTIMBaSGI4F8o0GjruaF9Il3/cMhAdjcmt8zMw fyzjlgIS7qUvbI8dl5QUoCVN/12A5zPalKjjYLbQ1AMUKAR2XVEeVaoJX675pSsUUbG+ J54g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=fDXhm+RK1m7fZKaYwZIMM/iMGbp4yJhf9o4ZO9CuiVk=; b=NpsWwONHlLVrRcTdp/VzayyvqhvCrU2Ltrv7urfjDS4ax9yPeHGSKyWUuAZ0TEPkt0 hc09b5HPRfeMU2Ps537q114D6tcBljC39wwjmU4ijP70C5JPV4ZHRSQ/VdfH3T45UYXy cEd/KWm6UvUVOhsvtWNzsBnyOYYn3vGTI+u/8loSAK9CK5bYByJkQa7bzt/4eI+hTSEk ZLxfxxfz4sa2aFWC5jBT4LjuvZvFWDF6dr2gnHrwxawhQOh5TUvosUyqjK1GJAkoxsGQ d23cDagEDFNpwreRtrNXHsC4OLi/CL6KaDjKFdhb6jYncfBooy316tlWzFCUvmPmDmW2 NeJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=SA+0u2ZC; 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 w4-20020a170902d70400b00153b2d1654fsi11639259ply.343.2022.03.21.22.48.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 22:48:45 -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=SA+0u2ZC; 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 9CAB2255AF; Mon, 21 Mar 2022 22:10:03 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236671AbiCVFLV (ORCPT + 99 others); Tue, 22 Mar 2022 01:11:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236658AbiCVFLU (ORCPT ); Tue, 22 Mar 2022 01:11:20 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1746FD30 for ; Mon, 21 Mar 2022 22:09:53 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id mz9-20020a17090b378900b001c657559290so1450612pjb.2 for ; Mon, 21 Mar 2022 22:09:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=fDXhm+RK1m7fZKaYwZIMM/iMGbp4yJhf9o4ZO9CuiVk=; b=SA+0u2ZCsN1JRGN+8G3kO6l6TsM2azbqy9m2SrLcGM+Z3VRCD65kSn/GyWoixd9pAA wLPESxr9lCruhs2fYkKM8ahUnKh9yCJBvcaXUCuc+f38QprYFpn5xH1jGBhQE18/5qKP zYqccsV/8DYrOY3lDgspa3+jJvZ37bjR9GiOifgvy3mABx9ul1NY3It3sBKaLxN4+3yW bO52D1xVn3L/OQooNi/Vjp2pczt98WXXblCqrC+pCjP7Sfkp+mFeYydCzLvKzsox1KuC VV8G4JPpO+/AZxkMUfj3YlVYrn8RMQu10Ej+Gpj1ruCt3SwQMSoFeieSkqL7E6EnmCxV lwNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=fDXhm+RK1m7fZKaYwZIMM/iMGbp4yJhf9o4ZO9CuiVk=; b=TAnpYN6EcYVFGAhb51Du3fmUzHj740W7kie5+oG1a2Za51UP+hCCKvvGZnbEX8YPJ4 PB05imsoXtPK5uqSriZGAQ6eMRaFpf9W+sjAG0G0/z+fXM0c4L7HRZB7vnNy0kD26Mkw CHQ9woFQ96UaWnjgOWzvGMGuytEdkVTzdNqwJ1uru4iCj9DSDeBn0VyzBhpudvXNTqLI cH/WJBAqKUumWpRRTmEY+pecY6Dj8dZpABvoaZTsOD/Y5MNcXS65SXCYvCYG4vyyLYIQ pLBILJAeMuXOVOKd4tT06k4eduCuiOJ4RH36609RlZZATSZ3QmwcgAuKayZoF0pUSChn Q87g== X-Gm-Message-State: AOAM532/CYcEnGn0PjOwQ46XkVW3d9DPrGJBKn+0Fnf4cD8vI2rn5uE3 nYtA6KxRfaiGe+SzncPnlQJzug== X-Received: by 2002:a17:90a:a390:b0:1c6:ed76:f555 with SMTP id x16-20020a17090aa39000b001c6ed76f555mr2883292pjp.65.1647925793030; Mon, 21 Mar 2022 22:09:53 -0700 (PDT) Received: from google.com (226.75.127.34.bc.googleusercontent.com. [34.127.75.226]) by smtp.gmail.com with ESMTPSA id u25-20020a62ed19000000b004f140515d56sm21081801pfh.46.2022.03.21.22.09.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 22:09:52 -0700 (PDT) Date: Tue, 22 Mar 2022 05:09:48 +0000 From: Mingwei Zhang To: Ben Gardon 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 Subject: Re: [PATCH 4/4] selftests: KVM: use dirty logging to check if page stats work correctly Message-ID: References: <20220321002638.379672-1-mizhang@google.com> <20220321002638.379672-5-mizhang@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Mon, Mar 21, 2022, Ben Gardon wrote: > 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 > Oh... sorry about that. Will discuss with you offline. Really want to avoid this in the future. > > 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 > >