From patchwork Wed Sep 15 21:30:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Matlack X-Patchwork-Id: 12497533 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=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham 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 9BCF7C433F5 for ; Wed, 15 Sep 2021 21:30:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7E12F61056 for ; Wed, 15 Sep 2021 21:30:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232331AbhIOVcB (ORCPT ); Wed, 15 Sep 2021 17:32:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232127AbhIOVcA (ORCPT ); Wed, 15 Sep 2021 17:32:00 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12E39C061574 for ; Wed, 15 Sep 2021 14:30:41 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id a16-20020a63d410000000b00268ebc7f4faso2884344pgh.17 for ; Wed, 15 Sep 2021 14:30:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=BA66WKx97EK3j9tmGUcSd7HMF4RFkdSNq90zx/RuXw4=; b=Lz79uQ5byqrb9VZ/sk7CK8Lx2ceLQi7B6b5tvcwiX94wsv3j+O411FG5gwUGkeFI4h nZJiBnBVq/CDFSEccxLhMB/FpkZ1uPGSnAUIGLlRJ0IB2yUDWwjtfvbVB3Z+IWpZu2xm +Z4zJ4MfbTf2hnXNedsLPuhe2M/TAoeS6cZjk3582ph6xqRbx95xj/2V961Wb454zRsA iExlVvhrWxB6BBnQu2SqxAaAhAFrZx/TvOufAUA58qC42+aFbltE/CvElpRnEcLAJnQm Uot4KGrcVehMBtjr7wnAY8nlLpZhk+/IbxtEvdkYE4Yrp1hU1eM5RWX19ijPhObl0DaG G7vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=BA66WKx97EK3j9tmGUcSd7HMF4RFkdSNq90zx/RuXw4=; b=p76pbFQrSAm18I5NivKnqsn1mVtnsfhYPcBst2KAG9NZXMIpNNpPtkMy4ERQ/jFRDS wD9mZxN4eYYsYHVK7OQAjryQMk6j9KciR64VI6trvNnlc8WsFM2xk+SpJdj84PrXfu7v U1qUTV0dyFVohcJW6AmVm1z6HBOjKbhTVqefXJRzShVBfet2C/m2hhrYqlyHUSdptz16 yKpGyxfHV8Y6cEmftidF5jAYQuWCup21uQpzXevOYyQzWlc4TkKlyryD7oXZkVOO1dJ4 btOuQtt5Bp7Ja5GoOB2Asp6olKW09VXD21GCPOq2Byto8WAfKqCpprhHaM5Y56mbmAMQ J2aQ== X-Gm-Message-State: AOAM531xMdamy1uHW1FZOTbRAEHrg6u7N7WJBks0OClznVZ5rV7gAstR ++VInZzaOeVz/q5vyahN/QbptDfTP6T2PQ== X-Google-Smtp-Source: ABdhPJwXVrUepBMgm48cLmyGsT3BolrvxB4fKgHorUE9mJigUSamGLF1Y/6gwmhEvykOJg/uaxfPLT/M5bsXgA== X-Received: from dmatlack-heavy.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:19cd]) (user=dmatlack job=sendgmr) by 2002:a17:902:da89:b0:13b:7d3d:59e9 with SMTP id j9-20020a170902da8900b0013b7d3d59e9mr1579667plx.41.1631741440587; Wed, 15 Sep 2021 14:30:40 -0700 (PDT) Date: Wed, 15 Sep 2021 21:30:32 +0000 In-Reply-To: <20210915213034.1613552-1-dmatlack@google.com> Message-Id: <20210915213034.1613552-2-dmatlack@google.com> Mime-Version: 1.0 References: <20210915213034.1613552-1-dmatlack@google.com> X-Mailer: git-send-email 2.33.0.309.g3052b89438-goog Subject: [PATCH 1/3] KVM: selftests: Change backing_src flag to -s in demand_paging_test From: David Matlack To: Paolo Bonzini Cc: kvm@vger.kernel.org, Andrew Jones , Ben Gardon , Axel Rasmussen , Yanan Wang , David Matlack Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Every other KVM selftest uses -s for the backing_src, so switch demand_paging_test to match. Signed-off-by: David Matlack Reviewed-by: Ben Gardon Reviewed-by: Andrew Jones --- tools/testing/selftests/kvm/demand_paging_test.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/kvm/demand_paging_test.c b/tools/testing/selftests/kvm/demand_paging_test.c index e79c1b64977f..735c081e774e 100644 --- a/tools/testing/selftests/kvm/demand_paging_test.c +++ b/tools/testing/selftests/kvm/demand_paging_test.c @@ -416,7 +416,7 @@ static void help(char *name) { puts(""); printf("usage: %s [-h] [-m vm_mode] [-u uffd_mode] [-d uffd_delay_usec]\n" - " [-b memory] [-t type] [-v vcpus] [-o]\n", name); + " [-b memory] [-s type] [-v vcpus] [-o]\n", name); guest_modes_help(); printf(" -u: use userfaultfd to handle vCPU page faults. Mode is a\n" " UFFD registration mode: 'MISSING' or 'MINOR'.\n"); @@ -426,7 +426,7 @@ static void help(char *name) printf(" -b: specify the size of the memory region which should be\n" " demand paged by each vCPU. e.g. 10M or 3G.\n" " Default: 1G\n"); - printf(" -t: The type of backing memory to use. Default: anonymous\n"); + printf(" -s: The type of backing memory to use. Default: anonymous\n"); backing_src_help(); printf(" -v: specify the number of vCPUs to run.\n"); printf(" -o: Overlap guest memory accesses instead of partitioning\n" @@ -446,7 +446,7 @@ int main(int argc, char *argv[]) guest_modes_append_default(); - while ((opt = getopt(argc, argv, "hm:u:d:b:t:v:o")) != -1) { + while ((opt = getopt(argc, argv, "hm:u:d:b:s:v:o")) != -1) { switch (opt) { case 'm': guest_modes_cmdline(optarg); @@ -465,7 +465,7 @@ int main(int argc, char *argv[]) case 'b': guest_percpu_mem_size = parse_size(optarg); break; - case 't': + case 's': p.src_type = parse_backing_src_type(optarg); break; case 'v': @@ -485,7 +485,7 @@ int main(int argc, char *argv[]) if (p.uffd_mode == UFFDIO_REGISTER_MODE_MINOR && !backing_src_is_shared(p.src_type)) { - TEST_FAIL("userfaultfd MINOR mode requires shared memory; pick a different -t"); + TEST_FAIL("userfaultfd MINOR mode requires shared memory; pick a different -s"); } for_each_guest_mode(run_test, &p); From patchwork Wed Sep 15 21:30:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Matlack X-Patchwork-Id: 12497535 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=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham 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 8BCF5C433F5 for ; Wed, 15 Sep 2021 21:30:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 75D1760E8B for ; Wed, 15 Sep 2021 21:30:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232409AbhIOVcC (ORCPT ); Wed, 15 Sep 2021 17:32:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232127AbhIOVcC (ORCPT ); Wed, 15 Sep 2021 17:32:02 -0400 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95A00C061574 for ; Wed, 15 Sep 2021 14:30:42 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id u13-20020a17090a4bcd00b00198e965f8f4so5071533pjl.8 for ; Wed, 15 Sep 2021 14:30:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=xE1wWNgSxANJ47KmLcYyykwPZY/TSwAMFYT90WI0sL8=; b=Zgw22gepYbLSMmm0NGMFYtKmolyeEItbNzpbhyujWJz3IjL8IRABeLdbIgSzS57xi1 kMlP12SpXbXNf7nzqxXOcr4BkRMfvVl7Dr2SPjn5eXNKCcWDDUprzf8RUf7jShv4fX7F 4NsBrsLcUEK9F0B6UNWXf+D78GLimT/NWTD4OU/z7gIa/gPG+0MJFa1fU6W4nqS+RpCu IRSkmtA0OJcF9Q1Gpa4XGGDsZGwflY6fHAQgFZ6fiIBxCJB78a1CDmfnomiCmmyLld2N SXPfYCXiGiuzhR8n1NxSOcoQbW5bCBpO/ZLeo4e6VhidU4fgvTTcv9Uf7Os5u86MoTla qZnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=xE1wWNgSxANJ47KmLcYyykwPZY/TSwAMFYT90WI0sL8=; b=057jRKRxsUVe2JEVbJr+W8GPXwlifUNJmLA+FWVPO+P8C0NI7ZovsgSR6FuqLreUPm 9XiUOSqBBtYs4OuNeYaR8y0RgoPZ/0CI5hB7posuiA+jalm5ki7zO+kQcMwNcsHbpX+O B6iGx9yM5o4nSOcsIrB28DSk/s+QIt27ptjvuV9smpGx1M5YqyY5ICj5v0hZKUb0PCRm 8CjopsRlpf4rp3iZFF2ocHpIrD5tEPBXExzdy5nbcOe6prLb0+AEqkrTQe6aZbtOWfaZ DG67dURzwX+pQy0+6Dnt3rvuVhQ4sRo+IjI2l8XVjI8l57g74E57PTP9kSaukIEUwpw6 44Zg== X-Gm-Message-State: AOAM530GVl9CNtXDx6o+kF3tcyae4WQ3R3ovNgCoRXL+13FFTuKokAdJ lUCkYpYs3TWINSMd7+/TKpy1E3vktluOKA== X-Google-Smtp-Source: ABdhPJwfaXckmxGpGSMBytgTkPOOEHKpB4eIgJxRLk7Bylmqwws8jADBsxH67kWbn+woovFdfNkwauByM1Yy6A== X-Received: from dmatlack-heavy.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:19cd]) (user=dmatlack job=sendgmr) by 2002:a05:6a00:1150:b0:40a:78df:8179 with SMTP id b16-20020a056a00115000b0040a78df8179mr1922998pfm.67.1631741442000; Wed, 15 Sep 2021 14:30:42 -0700 (PDT) Date: Wed, 15 Sep 2021 21:30:33 +0000 In-Reply-To: <20210915213034.1613552-1-dmatlack@google.com> Message-Id: <20210915213034.1613552-3-dmatlack@google.com> Mime-Version: 1.0 References: <20210915213034.1613552-1-dmatlack@google.com> X-Mailer: git-send-email 2.33.0.309.g3052b89438-goog Subject: [PATCH 2/3] KVM: selftests: Refactor help message for -s backing_src From: David Matlack To: Paolo Bonzini Cc: kvm@vger.kernel.org, Andrew Jones , Ben Gardon , Axel Rasmussen , Yanan Wang , David Matlack Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org All selftests that support the backing_src option were printing their own description of the flag and then calling backing_src_help() to dump the list of available backing sources. Consolidate the flag printing in backing_src_help() to align indentation, reduce duplicated strings, and improve consistency across tests. Note: Passing "-s" to backing_src_help is unnecessary since every test uses the same flag. However I decided to keep it for code readability at the call sites. While here this opportunistically fixes the incorrectly interleaved printing -x help message and list of backing source types in dirty_log_perf_test. Fixes: 609e6202ea5f ("KVM: selftests: Support multiple slots in dirty_log_perf_test") Signed-off-by: David Matlack Reviewed-by: Ben Gardon Reviewed-by: Andrew Jones --- .../selftests/kvm/access_tracking_perf_test.c | 6 ++---- .../testing/selftests/kvm/demand_paging_test.c | 5 ++--- .../testing/selftests/kvm/dirty_log_perf_test.c | 8 +++----- tools/testing/selftests/kvm/include/test_util.h | 5 ++++- .../testing/selftests/kvm/kvm_page_table_test.c | 7 ++----- tools/testing/selftests/kvm/lib/test_util.c | 17 +++++++++++++---- 6 files changed, 26 insertions(+), 22 deletions(-) diff --git a/tools/testing/selftests/kvm/access_tracking_perf_test.c b/tools/testing/selftests/kvm/access_tracking_perf_test.c index 71e277c7c3f3..5d95113c7b7c 100644 --- a/tools/testing/selftests/kvm/access_tracking_perf_test.c +++ b/tools/testing/selftests/kvm/access_tracking_perf_test.c @@ -371,9 +371,7 @@ static void help(char *name) printf(" -v: specify the number of vCPUs to run.\n"); printf(" -o: Overlap guest memory accesses instead of partitioning\n" " them into a separate region of memory for each vCPU.\n"); - printf(" -s: specify the type of memory that should be used to\n" - " back the guest data region.\n\n"); - backing_src_help(); + backing_src_help("-s"); puts(""); exit(0); } @@ -381,7 +379,7 @@ static void help(char *name) int main(int argc, char *argv[]) { struct test_params params = { - .backing_src = VM_MEM_SRC_ANONYMOUS, + .backing_src = DEFAULT_VM_MEM_SRC, .vcpu_memory_bytes = DEFAULT_PER_VCPU_MEM_SIZE, .vcpus = 1, }; diff --git a/tools/testing/selftests/kvm/demand_paging_test.c b/tools/testing/selftests/kvm/demand_paging_test.c index 735c081e774e..96cd3e0357f6 100644 --- a/tools/testing/selftests/kvm/demand_paging_test.c +++ b/tools/testing/selftests/kvm/demand_paging_test.c @@ -426,8 +426,7 @@ static void help(char *name) printf(" -b: specify the size of the memory region which should be\n" " demand paged by each vCPU. e.g. 10M or 3G.\n" " Default: 1G\n"); - printf(" -s: The type of backing memory to use. Default: anonymous\n"); - backing_src_help(); + backing_src_help("-s"); printf(" -v: specify the number of vCPUs to run.\n"); printf(" -o: Overlap guest memory accesses instead of partitioning\n" " them into a separate region of memory for each vCPU.\n"); @@ -439,7 +438,7 @@ int main(int argc, char *argv[]) { int max_vcpus = kvm_check_cap(KVM_CAP_MAX_VCPUS); struct test_params p = { - .src_type = VM_MEM_SRC_ANONYMOUS, + .src_type = DEFAULT_VM_MEM_SRC, .partition_vcpu_memory_access = true, }; int opt; diff --git a/tools/testing/selftests/kvm/dirty_log_perf_test.c b/tools/testing/selftests/kvm/dirty_log_perf_test.c index 3c30d0045d8d..5ad9f2bc7369 100644 --- a/tools/testing/selftests/kvm/dirty_log_perf_test.c +++ b/tools/testing/selftests/kvm/dirty_log_perf_test.c @@ -308,11 +308,9 @@ static void help(char *name) printf(" -v: specify the number of vCPUs to run.\n"); printf(" -o: Overlap guest memory accesses instead of partitioning\n" " them into a separate region of memory for each vCPU.\n"); - printf(" -s: specify the type of memory that should be used to\n" - " back the guest data region.\n\n"); + backing_src_help("-s"); printf(" -x: Split the memory region into this number of memslots.\n" - " (default: 1)"); - backing_src_help(); + " (default: 1)\n"); puts(""); exit(0); } @@ -324,7 +322,7 @@ int main(int argc, char *argv[]) .iterations = TEST_HOST_LOOP_N, .wr_fract = 1, .partition_vcpu_memory_access = true, - .backing_src = VM_MEM_SRC_ANONYMOUS, + .backing_src = DEFAULT_VM_MEM_SRC, .slots = 1, }; int opt; diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testing/selftests/kvm/include/test_util.h index d79be15dd3d2..2f09f2994733 100644 --- a/tools/testing/selftests/kvm/include/test_util.h +++ b/tools/testing/selftests/kvm/include/test_util.h @@ -68,6 +68,7 @@ struct timespec timespec_sub(struct timespec ts1, struct timespec ts2); struct timespec timespec_elapsed(struct timespec start); struct timespec timespec_div(struct timespec ts, int divisor); + enum vm_mem_backing_src_type { VM_MEM_SRC_ANONYMOUS, VM_MEM_SRC_ANONYMOUS_THP, @@ -90,6 +91,8 @@ enum vm_mem_backing_src_type { NUM_SRC_TYPES, }; +#define DEFAULT_VM_MEM_SRC VM_MEM_SRC_ANONYMOUS + struct vm_mem_backing_src_alias { const char *name; uint32_t flag; @@ -100,7 +103,7 @@ size_t get_trans_hugepagesz(void); size_t get_def_hugetlb_pagesz(void); const struct vm_mem_backing_src_alias *vm_mem_backing_src_alias(uint32_t i); size_t get_backing_src_pagesz(uint32_t i); -void backing_src_help(void); +void backing_src_help(const char *flag); enum vm_mem_backing_src_type parse_backing_src_type(const char *type_name); /* diff --git a/tools/testing/selftests/kvm/kvm_page_table_test.c b/tools/testing/selftests/kvm/kvm_page_table_test.c index 0d04a7db7f24..36407cb0ec85 100644 --- a/tools/testing/selftests/kvm/kvm_page_table_test.c +++ b/tools/testing/selftests/kvm/kvm_page_table_test.c @@ -456,10 +456,7 @@ static void help(char *name) " (default: 1G)\n"); printf(" -v: specify the number of vCPUs to run\n" " (default: 1)\n"); - printf(" -s: specify the type of memory that should be used to\n" - " back the guest data region.\n" - " (default: anonymous)\n\n"); - backing_src_help(); + backing_src_help("-s"); puts(""); } @@ -468,7 +465,7 @@ int main(int argc, char *argv[]) int max_vcpus = kvm_check_cap(KVM_CAP_MAX_VCPUS); struct test_params p = { .test_mem_size = DEFAULT_TEST_MEM_SIZE, - .src_type = VM_MEM_SRC_ANONYMOUS, + .src_type = DEFAULT_VM_MEM_SRC, }; int opt; diff --git a/tools/testing/selftests/kvm/lib/test_util.c b/tools/testing/selftests/kvm/lib/test_util.c index af1031fed97f..ea23a86132ed 100644 --- a/tools/testing/selftests/kvm/lib/test_util.c +++ b/tools/testing/selftests/kvm/lib/test_util.c @@ -279,13 +279,22 @@ size_t get_backing_src_pagesz(uint32_t i) } } -void backing_src_help(void) +void print_available_backing_src_types(const char *prefix) { int i; - printf("Available backing src types:\n"); + printf("%sAvailable backing src types:\n", prefix); + for (i = 0; i < NUM_SRC_TYPES; i++) - printf("\t%s\n", vm_mem_backing_src_alias(i)->name); + printf("%s %s\n", prefix, vm_mem_backing_src_alias(i)->name); +} + +void backing_src_help(const char *flag) +{ + printf(" %s: specify the type of memory that should be used to\n" + " back the guest data region. (default: %s)\n", + flag, vm_mem_backing_src_alias(DEFAULT_VM_MEM_SRC)->name); + print_available_backing_src_types(" "); } enum vm_mem_backing_src_type parse_backing_src_type(const char *type_name) @@ -296,7 +305,7 @@ enum vm_mem_backing_src_type parse_backing_src_type(const char *type_name) if (!strcmp(type_name, vm_mem_backing_src_alias(i)->name)) return i; - backing_src_help(); + print_available_backing_src_types(""); TEST_FAIL("Unknown backing src type: %s", type_name); return -1; } From patchwork Wed Sep 15 21:30:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Matlack X-Patchwork-Id: 12497537 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=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham 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 D0D30C433EF for ; Wed, 15 Sep 2021 21:30:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B831360E8B for ; Wed, 15 Sep 2021 21:30:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232477AbhIOVcE (ORCPT ); Wed, 15 Sep 2021 17:32:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232414AbhIOVcD (ORCPT ); Wed, 15 Sep 2021 17:32:03 -0400 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A9BEC061575 for ; Wed, 15 Sep 2021 14:30:44 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id u3-20020a17090abb0300b0019567f8a277so2751791pjr.1 for ; Wed, 15 Sep 2021 14:30:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=CCDBZYAQDpjPhsx32bz+fsrJPbE5p59+tr7peUsTU40=; b=Ar0uOkXmbWXRjFq9R3LaJwRIQng3qc7bksvsj4KmOKt+cvmmvlW/W1Eb0O0WzWsFw4 ZN7rsli1nWW7r7dVSfBBwB/tEij5hE7OeQQloQGdeqt7ZAUHCF6fkELFp9LetstVd5ZO yAyRJj/Zqtg7tgkwOzfGDpF2v7tZDhaYTFBoyfPIxBk8PFDQGAtOZ7t9hpfYu9yxslYX LaA56OyMzkqaaaDH+Pa8MNEPmm+dsAQvOczIYQm1rA9Ic+Mw8/Dd1EL2eShQzZkT4cvw aSlMfCS1dVTB2yt9MApMS+NjwEN4AQVW9vO35G9Ggdu21Mw58FGk+6XTKS0MnF2iSAz8 GhVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=CCDBZYAQDpjPhsx32bz+fsrJPbE5p59+tr7peUsTU40=; b=Q0WY6TNAuB6IfjWOq/WY7nX5ceaBmt1RClflhFRqMVbYlmyAiZ1ajEFcdJ2bZ2OYzC nX/S8gm8XOBKPv1+2cN6uUeOcF3v15jWkrPacGJQ0hwivZRb9Su2ZgsQ87nFDzX688B1 aAIpvQ7PZVPN5Sl+ijmUuSBTDjkjNPG4jF7lcfAeX6yVPjSCo2Vv/h1RK1HIuAbqO5XX GCkxpbGjuF0VSup9UUsz9SCKNA5uWJHwyqR/1uM7do5vDkA7MYOEtLGvplN8pu41wRJb trYG8FZfsNZLUsUbMn+bZS1d3cKFPERmu+F3SirPEDWGOUoBAVCNWv3mAxoKhL7iApU8 ZuVQ== X-Gm-Message-State: AOAM531C2bNx4bjF/3anXsvGzriuMiIzzpCgFb28l5/fFELNhoso21gy unowrZ8VUu7A9ex5RXP4kSf+mV5w+SgXYQ== X-Google-Smtp-Source: ABdhPJz1oSa+PVP4UnSwrC8YAARyTN1ZQrffQC55eqVDzfPaz/84TTifwOEpMylDLhepyByKsa9BwAr3A536qg== X-Received: from dmatlack-heavy.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:19cd]) (user=dmatlack job=sendgmr) by 2002:a17:90b:33c8:: with SMTP id lk8mr10756920pjb.241.1631741443698; Wed, 15 Sep 2021 14:30:43 -0700 (PDT) Date: Wed, 15 Sep 2021 21:30:34 +0000 In-Reply-To: <20210915213034.1613552-1-dmatlack@google.com> Message-Id: <20210915213034.1613552-4-dmatlack@google.com> Mime-Version: 1.0 References: <20210915213034.1613552-1-dmatlack@google.com> X-Mailer: git-send-email 2.33.0.309.g3052b89438-goog Subject: [PATCH 3/3] KVM: selftests: Fix dirty bitmap offset calculation From: David Matlack To: Paolo Bonzini Cc: kvm@vger.kernel.org, Andrew Jones , Ben Gardon , Axel Rasmussen , Yanan Wang , David Matlack Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The calculation to get the per-slot dirty bitmap was incorrect leading to a buffer overrun. Fix it by dividing the number of pages by BITS_PER_LONG, since each element of the bitmap is a long and there is one bit per page. Fixes: 609e6202ea5f ("KVM: selftests: Support multiple slots in dirty_log_perf_test") Signed-off-by: David Matlack Reviewed-by: Ben Gardon --- tools/testing/selftests/kvm/dirty_log_perf_test.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/kvm/dirty_log_perf_test.c b/tools/testing/selftests/kvm/dirty_log_perf_test.c index 5ad9f2bc7369..0dd4626571e9 100644 --- a/tools/testing/selftests/kvm/dirty_log_perf_test.c +++ b/tools/testing/selftests/kvm/dirty_log_perf_test.c @@ -118,6 +118,12 @@ static inline void disable_dirty_logging(struct kvm_vm *vm, int slots) toggle_dirty_logging(vm, slots, false); } +static unsigned long *get_slot_bitmap(unsigned long *bitmap, uint64_t page_offset) +{ + /* Guaranteed to be evenly divisible by the TEST_ASSERT in run_test. */ + return &bitmap[page_offset / BITS_PER_LONG]; +} + static void get_dirty_log(struct kvm_vm *vm, int slots, unsigned long *bitmap, uint64_t nr_pages) { @@ -126,7 +132,8 @@ static void get_dirty_log(struct kvm_vm *vm, int slots, unsigned long *bitmap, for (i = 0; i < slots; i++) { int slot = PERF_TEST_MEM_SLOT_INDEX + i; - unsigned long *slot_bitmap = bitmap + i * slot_pages; + uint64_t page_offset = slot_pages * i; + unsigned long *slot_bitmap = get_slot_bitmap(bitmap, page_offset); kvm_vm_get_dirty_log(vm, slot, slot_bitmap); } @@ -140,7 +147,8 @@ static void clear_dirty_log(struct kvm_vm *vm, int slots, unsigned long *bitmap, for (i = 0; i < slots; i++) { int slot = PERF_TEST_MEM_SLOT_INDEX + i; - unsigned long *slot_bitmap = bitmap + i * slot_pages; + uint64_t page_offset = slot_pages * i; + unsigned long *slot_bitmap = get_slot_bitmap(bitmap, page_offset); kvm_vm_clear_dirty_log(vm, slot, slot_bitmap, 0, slot_pages); } @@ -172,6 +180,9 @@ static void run_test(enum vm_guest_mode mode, void *arg) guest_num_pages = vm_adjust_num_guest_pages(mode, guest_num_pages); host_num_pages = vm_num_host_pages(mode, guest_num_pages); bmap = bitmap_alloc(host_num_pages); + TEST_ASSERT((host_num_pages / p->slots) % BITS_PER_LONG == 0, + "The number of pages per slot must be divisible by %d.", + BITS_PER_LONG); if (dirty_log_manual_caps) { cap.cap = KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2;