Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2500743pxp; Mon, 21 Mar 2022 22:44:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwdTVGU5YJvotZat3X4sTeIuNhjoHaj7LnUw1vCAB1E8CISFi5ZViz+PoUWa37BMTtICs6q X-Received: by 2002:a17:902:70c1:b0:154:667f:e361 with SMTP id l1-20020a17090270c100b00154667fe361mr6646442plt.148.1647927894719; Mon, 21 Mar 2022 22:44:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647927894; cv=none; d=google.com; s=arc-20160816; b=jZQhF2OszbowoFwuJ6XMP+ymu6Aiy9bbq/4BLAtUSgg9L6jEf55J1hS+Ms4iMv3r8F FzxQoHj++LhDq1+VFqzeb9dw83dk5YqqP4qowRUoFfzirgQxptgA+Zl2EpFtDJbsUTrK D96LbRCQrBltHKdURLzh4KFB8BZeeUFqqT4UN8QvHstmripYdJJwpgfc6RDfitX0Gt9w aZ/88MYL0fmdpTMAgaiib2y2LxLDUHlGSL3XMxAi0w4+yXe8XUTSByA/rZysJ9OoQ1et cH7qGyiLGC9xwSQ9ip6NW5TzuCHw0/0gGnJ3nKOjz6FS/lb+kXnWZUn60kc2Apo0joJo jdmA== 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=X7NAKB7l6ViXJ0oZ4Jc2ZumZYNmi/rHjpDXtyPmV2R8=; b=v8oGT87NUECkztn+6eSHr2wM7dAj6KbKJbOx3/duESokiLqt2Mx2LGnZi4uGcx9gyM qSCsse5KGaPsq3MG8M+Oe455daNq7wS+JKHlYJKIIn1JiE5slCSD7SENuhlJd9nCtWm5 R9EJgO0XVAdVNApgPZMCFAlc2Id6JuKlaRlkccWoYYINtCfEI0jWEQW3ESp7+v/UZ67V BFjms5ra56dGAaex4exNuIh8dbo9hu8HkDdH7/x81U93RtYxafHHqtsMfX9zz59Mu1vm c+RyFoI99rf4+GlNEJcjvtLCEmHVC1qyZKu4vhugZa4J8RC5VfOcOct+Hkeuh6kuTD4l 50yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="g3/FoHiU"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id b28-20020a631b5c000000b003816043f126si14135305pgm.795.2022.03.21.22.44.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 22:44:54 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="g3/FoHiU"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 7D1AB2BFA; Mon, 21 Mar 2022 22:02:37 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236557AbiCVFD6 (ORCPT + 99 others); Tue, 22 Mar 2022 01:03:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236781AbiCVFDG (ORCPT ); Tue, 22 Mar 2022 01:03:06 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF2D26579 for ; Mon, 21 Mar 2022 22:01:36 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id a5so17307397pfv.2 for ; Mon, 21 Mar 2022 22:01:36 -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=X7NAKB7l6ViXJ0oZ4Jc2ZumZYNmi/rHjpDXtyPmV2R8=; b=g3/FoHiUazbAID4UONDlWu0/MFcvOTjt9030xcuq1geqmbWVNd/30+8N+0Oq7SlHTQ ShCcylTQvBgkiQhwzYfo5uScmvDKsVnbyySjOT2pbNoCI3xoA3fnr6tPR1ZEdVxc4yIZ GIiJtUdyGRRRkTMwyZLEQ08d9UimWCk+vEFVav0Ns8PqF8gF30oyJr64lVacOqhA7QU+ 94WGw+cAt1enuJ+pweCAio+S3tSISIDTnVjB5zSkbSMH3FUDkVPrzuEoF0mnL2dhKJn7 NpFhMLlVELoHr8QI17ihOXH6prwb3uB0EeX+dIVmRcfndFphCCumALz+UoTJAE8hgbvr 9Q0A== 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=X7NAKB7l6ViXJ0oZ4Jc2ZumZYNmi/rHjpDXtyPmV2R8=; b=wk3alOjATx1He92u9YXmQWTNqOEEH0/CcRgCt9pPa86urSUQ7wCfR4i0x4DVLJbj8g SkheTuSSKBvo7FQPfaIL84POCrUpFYU8TN8frPaBMRLEzloj6wN3Yr+ALQFitlKrs9/C dRk3r7g58KdpEciyN/WKQZfIK1doZ1nD6UxUPZvuNPPd+qHVmEBMn1fqYxb4BQ5pRrp0 1VDNCseN59W3ZCLvFD2DUHOGcm8YnD9EsumQQ6FQIIy0EvR7C+P5gTNjWp5eAvGAgT/F gaO/TXK6FLywL2eT75K0+pltGEwn5LV8sBpWw3sHF2bV87eC7eC9rtN17+/df5HJMxpa ymDQ== X-Gm-Message-State: AOAM532rB72wUy4wGzJwQMAO1DTYs/e/xLmtvoJws6vc9ht1Dodn+p8e ZFzYpHBIM7Z0meGmgfhbzBlZzA== X-Received: by 2002:a63:2204:0:b0:378:9f08:206d with SMTP id i4-20020a632204000000b003789f08206dmr21032801pgi.3.1647925296250; Mon, 21 Mar 2022 22:01:36 -0700 (PDT) Received: from google.com (226.75.127.34.bc.googleusercontent.com. [34.127.75.226]) by smtp.gmail.com with ESMTPSA id l20-20020a056a00141400b004f65cedfb09sm21201478pfu.48.2022.03.21.22.01.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 22:01:35 -0700 (PDT) Date: Tue, 22 Mar 2022 05:01:32 +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 > > Note this is only true if eager page splitting is enabled. It would be > more accurate to say: > "While dirty logging is enabled, KVM will re-map any accessed page in > NPT/EPT at 4K." > > > 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 > > It might be worth having a follow up commit which checks if eager > splitting is enabled and changes the assertions accordingly. So eager splitting is still pending for review, right? But yes, I can add one after the feature get merged. > > > 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. > > Note a key stage here is after dirty logging is enabled, and then the > VM touches all the memory in the data region. > I believe that's the point at which you're making the assertion that > all mappings are 4k currently, which is the right place if eager > splitting is not enabled. Oh, sorry. This one should be after dirty logging is done, not 'just after turning on dirty logging'. Will update it. > > > - 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 > > 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) > > This should also handle 2M hugetlb memory. > I think there might be a library function to translate backing src > type to page size too, which could make this check cleaner. Ack. > > > + 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 > > Note this is after dirty logging has been enabled, AND all pages in > the data region have been written by the guest. > > > > > /* 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) > > + ; > > + } > > We might as well do this on all archs. Even without the stats, it at > least validates that disabling dirty logging doesn't break the VM. > Ack. > > + > > + 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 > >