From nobody Mon Apr 6 21:11:05 2026 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 98BCFC433FE for ; Thu, 6 Oct 2022 17:12:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231295AbiJFRL6 (ORCPT ); Thu, 6 Oct 2022 13:11:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231200AbiJFRLy (ORCPT ); Thu, 6 Oct 2022 13:11:54 -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 527FBA7ABA for ; Thu, 6 Oct 2022 10:11:52 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id nl8-20020a17090b384800b00205f930565cso1373537pjb.2 for ; Thu, 06 Oct 2022 10:11:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=gIRTEOV760XmyIZ/Qi7fwmuzWwZOXMhh2dv+gAx8YTQ=; b=hKrqnN77SIF0aoCHhjnc01Xfz+qA6XLrRWcZhg0cRFbr5kbWjrZKjUUdodyeCKSgyg titUyrnc9EVwraqc6/H04PeiwVTsLAWkofdan0t4tlf3ZEXyeVLZjrEsFUrAg2g5FDdb g/Sy9uuSHFmowKhfmBDnbktYZqgcSFb/ryLKl97TbgWq5eXQgE8VMXx41XG3vP73ATOd hRbjAxM2l5bu9nomRHaKH007naphm+U2EWtAQDuAD5pUmPmE1IuSDL5eiEfbAqvGTjbT sX1mFo8711e1VgtzFgvGXxVvemZjXWetxvFYCLOh31mxw/8f/Eq17VAAeHKEqBBe0LDU muaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=gIRTEOV760XmyIZ/Qi7fwmuzWwZOXMhh2dv+gAx8YTQ=; b=bvJp/9ZLqNnvpowu9iYcXH8KSu7EE2QPUN5Nflp5wqLWrHKP1l3zYKIo0cZ84aksvX j3gFgOwb+rlpIlzsRjS2WM6iqNsPALw2OL+fsI3rXZn8WwYG1qmtn61Yu31O6qVqMuut lxMJbtFnQppPj1VJe9YWeK6knAVst3H+wVpaU1svzL0fzAnhU0Q56jvk8gw1jdVWbqJA aCMWqAX6QsFhLmEhmrhmBEiwQZJtFiCrkJc+czUH0+ukK0tuQW5JNXYGbqfEeFg/xpxL ptJB/M7+6u4UA2oLydAAHch9v9FczVKYuWHNY0O4OhBC/C9+L80QUZKuY5zP4Nz64QgY TlUA== X-Gm-Message-State: ACrzQf0X1AE6oVn/dTN5VUifDcQCoeNo85q5KBSx4gH3fDtMj/Uvjl/Y f8HlvRm3yG6Wj0f914EUJfYUQNYrgDpT X-Google-Smtp-Source: AMsMyM7pA4CBYBz9VUO/SHmDpNSich9Ia0/sJqXHITGbOjZvJdyv9F0xpY0akV2fVfUNIJxMT0DSG2qBpbgk X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a17:902:db0a:b0:178:32b9:6f51 with SMTP id m10-20020a170902db0a00b0017832b96f51mr405091plx.145.1665076311692; Thu, 06 Oct 2022 10:11:51 -0700 (PDT) Date: Thu, 6 Oct 2022 10:11:29 -0700 In-Reply-To: <20221006171133.372359-1-vipinsh@google.com> Mime-Version: 1.0 References: <20221006171133.372359-1-vipinsh@google.com> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog Message-ID: <20221006171133.372359-2-vipinsh@google.com> Subject: [PATCH v4 1/4] KVM: selftests: Add missing break between 'e' and 'g' option in dirty_log_perf_test From: Vipin Sharma To: seanjc@google.com, pbonzini@redhat.com, dmatlack@google.com Cc: andrew.jones@linux.dev, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Passing -e option (Run VCPUs while dirty logging is being disabled) in dirty_log_perf_test also unintentionally enables -g (Do not enable KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2). Add break between two swtich case logic. Fixes: cfe12e64b065 ("KVM: selftests: Add an option to run vCPUs while disa= bling dirty logging") Signed-off-by: Vipin Sharma --- tools/testing/selftests/kvm/dirty_log_perf_test.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/kvm/dirty_log_perf_test.c b/tools/test= ing/selftests/kvm/dirty_log_perf_test.c index f99e39a672d3..56e08da3a87f 100644 --- a/tools/testing/selftests/kvm/dirty_log_perf_test.c +++ b/tools/testing/selftests/kvm/dirty_log_perf_test.c @@ -411,6 +411,7 @@ int main(int argc, char *argv[]) case 'e': /* 'e' is for evil. */ run_vcpus_while_disabling_dirty_logging =3D true; + break; case 'g': dirty_log_manual_caps =3D 0; break; --=20 2.38.0.rc1.362.ged0d419d3c-goog From nobody Mon Apr 6 21:11:05 2026 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 79A36C433FE for ; Thu, 6 Oct 2022 17:12:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231476AbiJFRMK (ORCPT ); Thu, 6 Oct 2022 13:12:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231330AbiJFRME (ORCPT ); Thu, 6 Oct 2022 13:12:04 -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 A5772A925B for ; Thu, 6 Oct 2022 10:11:57 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id h2-20020a656382000000b0044b0f6c572fso1470555pgv.20 for ; Thu, 06 Oct 2022 10:11:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=+m8/CnpnyvF/GMTtF6+sToX6YjEtcCxB1JvOB9LqxJw=; b=bEEeGStkWQ9tDtAKZlxY+aXZsDrTvhsrjG04Pv36MqoKltKsnid4WbSy2RSNz46eE+ wfMcjVWl30Yvd54pq3N34yb9539uZvYgC1OqaNs68OFdNrnaTYseY/fOh+MpHckIwEBe om+WC3S1xvhTToqZsFJmFKV3IHMISih/NJsHOm01cRYXL04CDsGEjB8f4IQr8qGGC3H1 rFkrCgzmZvGwDiBo57nLXz4BIgvbXz+CDL7bnk+KwTIPGPtv6tL/roFLdolKl9JTlWsZ hacEcHi7jCRUmtO66Z6LEaoAwNtXunMpfTFunchWUiMrMak5YiOYZvLavEib/T8RlMM5 Ta7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+m8/CnpnyvF/GMTtF6+sToX6YjEtcCxB1JvOB9LqxJw=; b=IwPzkqlCG31GDv0sGZMYSMsFDdOrPk5EJWW7Mza5bsXvSCjtN23kJcUjHuhIOeGvE3 M+0jLNc9b2eLp/uo3IWpE0/7DmN/sQfh4lYG2YHcJu/iAiRmdWdyubEHpXazqd4c05x2 KUPmS56XI1QmP9srEkeJFvHUEJE+1E8XB2t0ETO8Cx0AZHCWMJu1CvzmG5xvazOG+u7Z hxoygjB9Q5CsV6qUU8I0o/VS/5ta/sE79N4cBX2K9Ll0fMx4ii1bBLITAXTiDkWB6jcy LiMOaK8xRivpHttYbYHKrkSYyy70zi5+UOmFQZuFDtc+xcsR4YU+yvA6btsdvpMvRb9p Ncng== X-Gm-Message-State: ACrzQf0GtKt4sGxR+XeqygJqGQuF59/UMlzbCb89z6YLM0yIcmrTz3bs yCHjvshrfAL6jK46Y1zdvLW7tAs48NKE X-Google-Smtp-Source: AMsMyM4EuWUAtLJuSMcBhnzgG5uMCwio8Ayx/qHOQZsTb78oFzUaXV1VZD7SwBIexyvMajxtUufsLA/RzpgT X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a17:902:d591:b0:17d:9cd9:2ae6 with SMTP id k17-20020a170902d59100b0017d9cd92ae6mr409223plh.165.1665076316595; Thu, 06 Oct 2022 10:11:56 -0700 (PDT) Date: Thu, 6 Oct 2022 10:11:30 -0700 In-Reply-To: <20221006171133.372359-1-vipinsh@google.com> Mime-Version: 1.0 References: <20221006171133.372359-1-vipinsh@google.com> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog Message-ID: <20221006171133.372359-3-vipinsh@google.com> Subject: [PATCH v4 2/4] KVM: selftests: Put command line options in alphabetical order in dirty_log_perf_test From: Vipin Sharma To: seanjc@google.com, pbonzini@redhat.com, dmatlack@google.com Cc: andrew.jones@linux.dev, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" There are 13 command line options and they are not in any order. Put them in alphabetical order to make it easy to add new options. No functional change intended. Signed-off-by: Vipin Sharma --- .../selftests/kvm/dirty_log_perf_test.c | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/tools/testing/selftests/kvm/dirty_log_perf_test.c b/tools/test= ing/selftests/kvm/dirty_log_perf_test.c index 56e08da3a87f..5bb6954b2358 100644 --- a/tools/testing/selftests/kvm/dirty_log_perf_test.c +++ b/tools/testing/selftests/kvm/dirty_log_perf_test.c @@ -406,50 +406,52 @@ int main(int argc, char *argv[]) =20 guest_modes_append_default(); =20 - while ((opt =3D getopt(argc, argv, "eghi:p:m:nb:f:v:os:x:")) !=3D -1) { + while ((opt =3D getopt(argc, argv, "b:ef:ghi:m:nop:s:v:x:")) !=3D -1) { switch (opt) { + case 'b': + guest_percpu_mem_size =3D parse_size(optarg); + break; case 'e': /* 'e' is for evil. */ run_vcpus_while_disabling_dirty_logging =3D true; break; + case 'f': + p.wr_fract =3D atoi(optarg); + TEST_ASSERT(p.wr_fract >=3D 1, + "Write fraction cannot be less than one"); + break; case 'g': dirty_log_manual_caps =3D 0; break; + case 'h': + help(argv[0]); + break; case 'i': p.iterations =3D atoi(optarg); break; - case 'p': - p.phys_offset =3D strtoull(optarg, NULL, 0); - break; case 'm': guest_modes_cmdline(optarg); break; case 'n': perf_test_args.nested =3D true; break; - case 'b': - guest_percpu_mem_size =3D parse_size(optarg); + case 'o': + p.partition_vcpu_memory_access =3D false; break; - case 'f': - p.wr_fract =3D atoi(optarg); - TEST_ASSERT(p.wr_fract >=3D 1, - "Write fraction cannot be less than one"); + case 'p': + p.phys_offset =3D strtoull(optarg, NULL, 0); + break; + case 's': + p.backing_src =3D parse_backing_src_type(optarg); break; case 'v': nr_vcpus =3D atoi(optarg); TEST_ASSERT(nr_vcpus > 0 && nr_vcpus <=3D max_vcpus, "Invalid number of vcpus, must be between 1 and %d", max_vcpus); break; - case 'o': - p.partition_vcpu_memory_access =3D false; - break; - case 's': - p.backing_src =3D parse_backing_src_type(optarg); - break; case 'x': p.slots =3D atoi(optarg); break; - case 'h': default: help(argv[0]); break; --=20 2.38.0.rc1.362.ged0d419d3c-goog From nobody Mon Apr 6 21:11:05 2026 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 C8046C433F5 for ; Thu, 6 Oct 2022 17:12:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231699AbiJFRMO (ORCPT ); Thu, 6 Oct 2022 13:12:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231567AbiJFRMG (ORCPT ); Thu, 6 Oct 2022 13:12:06 -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 F271DA98D2 for ; Thu, 6 Oct 2022 10:12:00 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id 69-20020a630148000000b0043bbb38f75bso1464057pgb.6 for ; Thu, 06 Oct 2022 10:12:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=5dKSwh7+qx3XoQgeIzt1baz66Fx4CxMFyvLvfA9g4zQ=; b=Lmb4FRH/8NwdJTQqNP/Z7GuAmBufmUr0IfcW+8J8m1PuxV7d8le14ZtRfVzWt+jX6K 9gg8eEFCktXBPzTLoHFFYB7Kh/cljJKqb++gSqaqAHmaOkEp02S/H9FrkbJSJyK4zAtK Wow73n0y9nTKNKRscrinw5dTabMriKID6AwOpebsnjwE9Kk4yK5h0EHLpV7WbLCSWxd3 n5lUSRdKDAb4+ik1Y9mEyb2R8IjoMpKwYoEuKvc0qNorGm5unEJEF0T1+P5IzItJOSY4 ZU+sF8YkDQTIp4NsxRf6idJ1kbujaP9T6EcJ1J3FWRXPoR/7iMJ/rl4XH4BegtkIL6mW QLog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5dKSwh7+qx3XoQgeIzt1baz66Fx4CxMFyvLvfA9g4zQ=; b=PtkcwhEpmES45wkqdlaX71fxE6fDkp1zPxOGNZTiYWkESkbvJviG/VwPpfYEBtM17i 5aSlezFiTVCsmyI9dZ2hkNZwCOHNkVnZXdw02skg7MQJSFxwbNbC4KmDu+olZm+bZny+ vlRo7TCMiB5cDKwmvUUKG9sTETxDzYoK71keJNFak2GHhRnzVBhQkZvKBkNhuhX4IvCY WKZGDgFrZOwy9VoIeW/kQfdtFx/9qGNLWN0qMjgDd6wsyyc6KVMyKBobUa3ZwB3kOC8f 8JtGFbT4WVnRZ5HTRkzx61A007j8mufCzbqQr61rhs4F1nNp5rSuAA+2fO4QyO1k7L3X 3Oxg== X-Gm-Message-State: ACrzQf0E9PqL74rBep6CY+dEXYFVTsp3E5gLzVHR3oT4Zz95W313VD2e 9z205UMoyeX1beaVrv0wL5K1q5FnFFoE X-Google-Smtp-Source: AMsMyM6GmhR/uOI0BPw9RRhimHfc4pi1CX3QkLp4hPonViI3HkPbI/W5yyLXZ+1Y0ap9wuPwb226xDT/f/Qp X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a05:6a00:2292:b0:547:5bd7:8966 with SMTP id f18-20020a056a00229200b005475bd78966mr789571pfe.62.1665076319953; Thu, 06 Oct 2022 10:11:59 -0700 (PDT) Date: Thu, 6 Oct 2022 10:11:31 -0700 In-Reply-To: <20221006171133.372359-1-vipinsh@google.com> Mime-Version: 1.0 References: <20221006171133.372359-1-vipinsh@google.com> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog Message-ID: <20221006171133.372359-4-vipinsh@google.com> Subject: [PATCH v4 3/4] KVM: selftests: Add atoi_paranoid() to catch errors missed by atoi() From: Vipin Sharma To: seanjc@google.com, pbonzini@redhat.com, dmatlack@google.com Cc: andrew.jones@linux.dev, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" atoi() doesn't detect errors. There is no way to know that a 0 return is correct conversion or due to an error. Introduce atoi_paranoid() to detect errors and provide correct conversion. Replace all atoi() calls with atoi_paranoid(). Signed-off-by: Vipin Sharma Suggested-by: David Matlack Suggested-by: Sean Christopherson --- .../testing/selftests/kvm/aarch64/arch_timer.c | 8 ++++---- tools/testing/selftests/kvm/aarch64/vgic_irq.c | 6 +++--- .../selftests/kvm/access_tracking_perf_test.c | 2 +- .../testing/selftests/kvm/demand_paging_test.c | 2 +- .../selftests/kvm/dirty_log_perf_test.c | 8 ++++---- .../testing/selftests/kvm/include/test_util.h | 2 ++ .../selftests/kvm/kvm_page_table_test.c | 2 +- tools/testing/selftests/kvm/lib/test_util.c | 18 ++++++++++++++++++ .../selftests/kvm/max_guest_memory_test.c | 6 +++--- .../kvm/memslot_modification_stress_test.c | 4 ++-- .../testing/selftests/kvm/memslot_perf_test.c | 10 +++++----- .../selftests/kvm/set_memory_region_test.c | 2 +- .../selftests/kvm/x86_64/nx_huge_pages_test.c | 4 ++-- 13 files changed, 47 insertions(+), 27 deletions(-) diff --git a/tools/testing/selftests/kvm/aarch64/arch_timer.c b/tools/testi= ng/selftests/kvm/aarch64/arch_timer.c index 574eb73f0e90..251e7ff04883 100644 --- a/tools/testing/selftests/kvm/aarch64/arch_timer.c +++ b/tools/testing/selftests/kvm/aarch64/arch_timer.c @@ -414,7 +414,7 @@ static bool parse_args(int argc, char *argv[]) while ((opt =3D getopt(argc, argv, "hn:i:p:m:")) !=3D -1) { switch (opt) { case 'n': - test_args.nr_vcpus =3D atoi(optarg); + test_args.nr_vcpus =3D atoi_paranoid(optarg); if (test_args.nr_vcpus <=3D 0) { pr_info("Positive value needed for -n\n"); goto err; @@ -425,21 +425,21 @@ static bool parse_args(int argc, char *argv[]) } break; case 'i': - test_args.nr_iter =3D atoi(optarg); + test_args.nr_iter =3D atoi_paranoid(optarg); if (test_args.nr_iter <=3D 0) { pr_info("Positive value needed for -i\n"); goto err; } break; case 'p': - test_args.timer_period_ms =3D atoi(optarg); + test_args.timer_period_ms =3D atoi_paranoid(optarg); if (test_args.timer_period_ms <=3D 0) { pr_info("Positive value needed for -p\n"); goto err; } break; case 'm': - test_args.migration_freq_ms =3D atoi(optarg); + test_args.migration_freq_ms =3D atoi_paranoid(optarg); if (test_args.migration_freq_ms < 0) { pr_info("0 or positive value needed for -m\n"); goto err; diff --git a/tools/testing/selftests/kvm/aarch64/vgic_irq.c b/tools/testing= /selftests/kvm/aarch64/vgic_irq.c index 17417220a083..ae90b718070a 100644 --- a/tools/testing/selftests/kvm/aarch64/vgic_irq.c +++ b/tools/testing/selftests/kvm/aarch64/vgic_irq.c @@ -824,16 +824,16 @@ int main(int argc, char **argv) while ((opt =3D getopt(argc, argv, "hn:e:l:")) !=3D -1) { switch (opt) { case 'n': - nr_irqs =3D atoi(optarg); + nr_irqs =3D atoi_paranoid(optarg); if (nr_irqs > 1024 || nr_irqs % 32) help(argv[0]); break; case 'e': - eoi_split =3D (bool)atoi(optarg); + eoi_split =3D (bool)atoi_paranoid(optarg); default_args =3D false; break; case 'l': - level_sensitive =3D (bool)atoi(optarg); + level_sensitive =3D (bool)atoi_paranoid(optarg); default_args =3D false; break; case 'h': diff --git a/tools/testing/selftests/kvm/access_tracking_perf_test.c b/tool= s/testing/selftests/kvm/access_tracking_perf_test.c index 76c583a07ea2..c6bcc5301e2c 100644 --- a/tools/testing/selftests/kvm/access_tracking_perf_test.c +++ b/tools/testing/selftests/kvm/access_tracking_perf_test.c @@ -368,7 +368,7 @@ int main(int argc, char *argv[]) params.vcpu_memory_bytes =3D parse_size(optarg); break; case 'v': - params.nr_vcpus =3D atoi(optarg); + params.nr_vcpus =3D atoi_paranoid(optarg); break; case 'o': overlap_memory_access =3D true; diff --git a/tools/testing/selftests/kvm/demand_paging_test.c b/tools/testi= ng/selftests/kvm/demand_paging_test.c index 779ae54f89c4..82597fb04146 100644 --- a/tools/testing/selftests/kvm/demand_paging_test.c +++ b/tools/testing/selftests/kvm/demand_paging_test.c @@ -427,7 +427,7 @@ int main(int argc, char *argv[]) p.src_type =3D parse_backing_src_type(optarg); break; case 'v': - nr_vcpus =3D atoi(optarg); + nr_vcpus =3D atoi_paranoid(optarg); TEST_ASSERT(nr_vcpus > 0 && nr_vcpus <=3D max_vcpus, "Invalid number of vcpus, must be between 1 and %d", max_vcpus); break; diff --git a/tools/testing/selftests/kvm/dirty_log_perf_test.c b/tools/test= ing/selftests/kvm/dirty_log_perf_test.c index 5bb6954b2358..ecda802b78ff 100644 --- a/tools/testing/selftests/kvm/dirty_log_perf_test.c +++ b/tools/testing/selftests/kvm/dirty_log_perf_test.c @@ -416,7 +416,7 @@ int main(int argc, char *argv[]) run_vcpus_while_disabling_dirty_logging =3D true; break; case 'f': - p.wr_fract =3D atoi(optarg); + p.wr_fract =3D atoi_paranoid(optarg); TEST_ASSERT(p.wr_fract >=3D 1, "Write fraction cannot be less than one"); break; @@ -427,7 +427,7 @@ int main(int argc, char *argv[]) help(argv[0]); break; case 'i': - p.iterations =3D atoi(optarg); + p.iterations =3D atoi_paranoid(optarg); break; case 'm': guest_modes_cmdline(optarg); @@ -445,12 +445,12 @@ int main(int argc, char *argv[]) p.backing_src =3D parse_backing_src_type(optarg); break; case 'v': - nr_vcpus =3D atoi(optarg); + nr_vcpus =3D atoi_paranoid(optarg); TEST_ASSERT(nr_vcpus > 0 && nr_vcpus <=3D max_vcpus, "Invalid number of vcpus, must be between 1 and %d", max_vcpus); break; case 'x': - p.slots =3D atoi(optarg); + p.slots =3D atoi_paranoid(optarg); break; default: help(argv[0]); diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testin= g/selftests/kvm/include/test_util.h index befc754ce9b3..feae42863759 100644 --- a/tools/testing/selftests/kvm/include/test_util.h +++ b/tools/testing/selftests/kvm/include/test_util.h @@ -152,4 +152,6 @@ static inline void *align_ptr_up(void *x, size_t size) return (void *)align_up((unsigned long)x, size); } =20 +int atoi_paranoid(const char *num_str); + #endif /* SELFTEST_KVM_TEST_UTIL_H */ diff --git a/tools/testing/selftests/kvm/kvm_page_table_test.c b/tools/test= ing/selftests/kvm/kvm_page_table_test.c index f42c6ac6d71d..ea7feb69bb88 100644 --- a/tools/testing/selftests/kvm/kvm_page_table_test.c +++ b/tools/testing/selftests/kvm/kvm_page_table_test.c @@ -461,7 +461,7 @@ int main(int argc, char *argv[]) p.test_mem_size =3D parse_size(optarg); break; case 'v': - nr_vcpus =3D atoi(optarg); + nr_vcpus =3D atoi_paranoid(optarg); TEST_ASSERT(nr_vcpus > 0 && nr_vcpus <=3D max_vcpus, "Invalid number of vcpus, must be between 1 and %d", max_vcpus); break; diff --git a/tools/testing/selftests/kvm/lib/test_util.c b/tools/testing/se= lftests/kvm/lib/test_util.c index 6d23878bbfe1..8cce52ee139f 100644 --- a/tools/testing/selftests/kvm/lib/test_util.c +++ b/tools/testing/selftests/kvm/lib/test_util.c @@ -334,3 +334,21 @@ long get_run_delay(void) =20 return val[1]; } + +int atoi_paranoid(const char *num_str) +{ + int num; + char *end_ptr; + + errno =3D 0; + num =3D (int)strtol(num_str, &end_ptr, 10); + TEST_ASSERT(!errno, "strtol(\"%s\") failed", num_str); + TEST_ASSERT(num_str !=3D end_ptr, + "strtol(\"%s\") didn't find any valid number.\n", num_str); + TEST_ASSERT( + *end_ptr =3D=3D '\0', + "strtol(\"%s\") failed to parse trailing characters \"%s\".\n", + num_str, end_ptr); + + return num; +} diff --git a/tools/testing/selftests/kvm/max_guest_memory_test.c b/tools/te= sting/selftests/kvm/max_guest_memory_test.c index 9a6e4f3ad6b5..1595b73dc09a 100644 --- a/tools/testing/selftests/kvm/max_guest_memory_test.c +++ b/tools/testing/selftests/kvm/max_guest_memory_test.c @@ -193,15 +193,15 @@ int main(int argc, char *argv[]) while ((opt =3D getopt(argc, argv, "c:h:m:s:H")) !=3D -1) { switch (opt) { case 'c': - nr_vcpus =3D atoi(optarg); + nr_vcpus =3D atoi_paranoid(optarg); TEST_ASSERT(nr_vcpus > 0, "number of vcpus must be >0"); break; case 'm': - max_mem =3D atoi(optarg) * size_1gb; + max_mem =3D atoi_paranoid(optarg) * size_1gb; TEST_ASSERT(max_mem > 0, "memory size must be >0"); break; case 's': - slot_size =3D atoi(optarg) * size_1gb; + slot_size =3D atoi_paranoid(optarg) * size_1gb; TEST_ASSERT(slot_size > 0, "slot size must be >0"); break; case 'H': diff --git a/tools/testing/selftests/kvm/memslot_modification_stress_test.c= b/tools/testing/selftests/kvm/memslot_modification_stress_test.c index 6ee7e1dde404..865276993ffb 100644 --- a/tools/testing/selftests/kvm/memslot_modification_stress_test.c +++ b/tools/testing/selftests/kvm/memslot_modification_stress_test.c @@ -166,7 +166,7 @@ int main(int argc, char *argv[]) guest_percpu_mem_size =3D parse_size(optarg); break; case 'v': - nr_vcpus =3D atoi(optarg); + nr_vcpus =3D atoi_paranoid(optarg); TEST_ASSERT(nr_vcpus > 0 && nr_vcpus <=3D max_vcpus, "Invalid number of vcpus, must be between 1 and %d", max_vcpus); @@ -175,7 +175,7 @@ int main(int argc, char *argv[]) p.partition_vcpu_memory_access =3D false; break; case 'i': - p.nr_memslot_modifications =3D atoi(optarg); + p.nr_memslot_modifications =3D atoi_paranoid(optarg); break; case 'h': default: diff --git a/tools/testing/selftests/kvm/memslot_perf_test.c b/tools/testin= g/selftests/kvm/memslot_perf_test.c index 44995446d942..4bae9e3f5ca1 100644 --- a/tools/testing/selftests/kvm/memslot_perf_test.c +++ b/tools/testing/selftests/kvm/memslot_perf_test.c @@ -885,21 +885,21 @@ static bool parse_args(int argc, char *argv[], map_unmap_verify =3D true; break; case 's': - targs->nslots =3D atoi(optarg); + targs->nslots =3D atoi_paranoid(optarg); if (targs->nslots <=3D 0 && targs->nslots !=3D -1) { pr_info("Slot count cap has to be positive or -1 for no cap\n"); return false; } break; case 'f': - targs->tfirst =3D atoi(optarg); + targs->tfirst =3D atoi_paranoid(optarg); if (targs->tfirst < 0) { pr_info("First test to run has to be non-negative\n"); return false; } break; case 'e': - targs->tlast =3D atoi(optarg); + targs->tlast =3D atoi_paranoid(optarg); if (targs->tlast < 0 || targs->tlast >=3D NTESTS) { pr_info("Last test to run has to be non-negative and less than %zu\n", NTESTS); @@ -907,14 +907,14 @@ static bool parse_args(int argc, char *argv[], } break; case 'l': - targs->seconds =3D atoi(optarg); + targs->seconds =3D atoi_paranoid(optarg); if (targs->seconds < 0) { pr_info("Test length in seconds has to be non-negative\n"); return false; } break; case 'r': - targs->runs =3D atoi(optarg); + targs->runs =3D atoi_paranoid(optarg); if (targs->runs <=3D 0) { pr_info("Runs per test has to be positive\n"); return false; diff --git a/tools/testing/selftests/kvm/set_memory_region_test.c b/tools/t= esting/selftests/kvm/set_memory_region_test.c index 0d55f508d595..c366949c8362 100644 --- a/tools/testing/selftests/kvm/set_memory_region_test.c +++ b/tools/testing/selftests/kvm/set_memory_region_test.c @@ -407,7 +407,7 @@ int main(int argc, char *argv[]) =20 #ifdef __x86_64__ if (argc > 1) - loops =3D atoi(argv[1]); + loops =3D atoi_paranoid(argv[1]); else loops =3D 10; =20 diff --git a/tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.c b/tool= s/testing/selftests/kvm/x86_64/nx_huge_pages_test.c index 59ffe7fd354f..354b6902849c 100644 --- a/tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.c +++ b/tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.c @@ -241,10 +241,10 @@ int main(int argc, char **argv) while ((opt =3D getopt(argc, argv, "hp:t:r")) !=3D -1) { switch (opt) { case 'p': - reclaim_period_ms =3D atoi(optarg); + reclaim_period_ms =3D atoi_paranoid(optarg); break; case 't': - token =3D atoi(optarg); + token =3D atoi_paranoid(optarg); break; case 'r': reboot_permissions =3D true; --=20 2.38.0.rc1.362.ged0d419d3c-goog From nobody Mon Apr 6 21:11:05 2026 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 484BFC433F5 for ; Thu, 6 Oct 2022 17:12:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230104AbiJFRMS (ORCPT ); Thu, 6 Oct 2022 13:12:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231649AbiJFRMH (ORCPT ); Thu, 6 Oct 2022 13:12:07 -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 8B00FA98F6 for ; Thu, 6 Oct 2022 10:12:03 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id o11-20020a17090aac0b00b0020625062cbaso3246742pjq.2 for ; Thu, 06 Oct 2022 10:12:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=bNbcK3LL3MeRLMBsJX3wEFu+BxWkeXqN6i942qppoGM=; b=S8qrJeH0gN8gfBUaxED2sgbwZGLAVK9GuIdQQZD/J9UmHKy8zhuU2xSlToWAUcJKRe 5UKLTE50Lczc578QLLXLci1Fgb4UnLYL6/jGTHZWTGsLNVhla8yeTnMgNL4XgNCP8smh VMwDnAFa2wzCl2Rwrd6njaMK5jAhURzTPj0X0aTA2QJ5Py899Ni9BiJUDJZx/N6XXg2Q fs/YKdzRFFuQyL6jSmNaElLcqD5h3qd+zzYOYl1BvzND84wSlRE0F6r34DfztQGMfoSE j8G9YPdERjLazF77IcBX9JgmyIKjbGQLcyEyJ14lQlRPo//0+O2Y8LZyL5SOQKxuqqS+ RMdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=bNbcK3LL3MeRLMBsJX3wEFu+BxWkeXqN6i942qppoGM=; b=XcvXcCSaQxf3fVBmt+JO5EsHZDaozrsfMPUYG5QcI4tAKMNXUUv5tn6zG58S3D0kmg bKey6lVqsPMItCO3Esymqo030VfHe2toeJdBt4HVyZh3WFEMvFnJ0Roi7z1MbG0R4w5t vNxs8ZymGjn7SYs7P6arA5AKMT/0O+GoIeDTqce3qGp0Ryp28RX7ERt24gg/VCLIDKH0 eHPRy7vAzblxDwwgMzGVsh6zK0NG9mOa6YLERTHbWM7XrKCMu3iH5EHNeVtooyr+oE7k EciV/McWTSz3YSO65rUa3PVP4kT1G9f8rSGUM3Xc/WRHwLliC/dyl0O8UkIZwrq7q+iS cEUA== X-Gm-Message-State: ACrzQf2SIK5vIIF/kld67lYLrbqVOpxnlWpk3scs5Kg7PgvfAFw/ZyEN bUF0gKoy8IMhiPVwEQj3uF0Uevf/naX0 X-Google-Smtp-Source: AMsMyM5rSvgSAK+YZ3JBGH9d6o9ZH5TCl/R/DmTIyBNezNnhmGVCjxSdKqbhIzk32aAAaVMSynctk/QdmCFi X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a17:902:784d:b0:178:6946:3ff7 with SMTP id e13-20020a170902784d00b0017869463ff7mr449882pln.133.1665076323020; Thu, 06 Oct 2022 10:12:03 -0700 (PDT) Date: Thu, 6 Oct 2022 10:11:32 -0700 In-Reply-To: <20221006171133.372359-1-vipinsh@google.com> Mime-Version: 1.0 References: <20221006171133.372359-1-vipinsh@google.com> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog Message-ID: <20221006171133.372359-5-vipinsh@google.com> Subject: [PATCH v4 4/4] KVM: selftests: Run dirty_log_perf_test on specific CPUs From: Vipin Sharma To: seanjc@google.com, pbonzini@redhat.com, dmatlack@google.com Cc: andrew.jones@linux.dev, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add command line options, -c, to run the vCPUs and optionally the main process on the specific CPUs on a host machine. This is useful as it provides a way to analyze performance based on the vCPUs and dirty log worker locations, like on the different numa nodes or on the same numa nodes. Link: https://lore.kernel.org/lkml/20220801151928.270380-1-vipinsh@google.c= om Signed-off-by: Vipin Sharma Suggested-by: David Matlack Suggested-by: Sean Christopherson Suggested-by: Paolo Bonzini Suggested-by: is generally intended to document that someone else came up w= ith --- .../selftests/kvm/dirty_log_perf_test.c | 23 +++++++- .../selftests/kvm/include/perf_test_util.h | 6 ++ .../selftests/kvm/lib/perf_test_util.c | 58 ++++++++++++++++++- 3 files changed, 84 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/kvm/dirty_log_perf_test.c b/tools/test= ing/selftests/kvm/dirty_log_perf_test.c index ecda802b78ff..33f83e423f75 100644 --- a/tools/testing/selftests/kvm/dirty_log_perf_test.c +++ b/tools/testing/selftests/kvm/dirty_log_perf_test.c @@ -353,7 +353,7 @@ static void help(char *name) puts(""); printf("usage: %s [-h] [-i iterations] [-p offset] [-g] " "[-m mode] [-n] [-b vcpu bytes] [-v vcpus] [-o] [-s mem type]" - "[-x memslots]\n", name); + "[-x memslots] [-c physical cpus to run test on]\n", name); puts(""); printf(" -i: specify iteration counts (default: %"PRIu64")\n", TEST_HOST_LOOP_N); @@ -383,6 +383,18 @@ static void help(char *name) backing_src_help("-s"); printf(" -x: Split the memory region into this number of memslots.\n" " (default: 1)\n"); + printf(" -c: Comma separated values of the physical CPUs, which will run\= n" + " the vCPUs, optionally, followed by the main application thre= ad cpu.\n" + " Number of values must be at least the number of vCPUs.\n" + " The very next number is used to pin main application thread.= \n\n" + " Example: ./dirty_log_perf_test -v 3 -c 22,23,24,50\n" + " This means that the vcpu 0 will run on the physical cpu 22,\= n" + " vcpu 1 on the physical cpu 23, vcpu 2 on the physical cpu 24= \n" + " and the main thread will run on cpu 50.\n\n" + " Example: ./dirty_log_perf_test -v 3 -c 22,23,24\n" + " Same as the previous example except now main application\n" + " thread can run on any physical cpu\n\n" + " (default: No cpu mapping)\n"); puts(""); exit(0); } @@ -398,6 +410,7 @@ int main(int argc, char *argv[]) .slots =3D 1, }; int opt; + const char *pcpu_list =3D NULL; =20 dirty_log_manual_caps =3D kvm_check_cap(KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2); @@ -406,11 +419,14 @@ int main(int argc, char *argv[]) =20 guest_modes_append_default(); =20 - while ((opt =3D getopt(argc, argv, "b:ef:ghi:m:nop:s:v:x:")) !=3D -1) { + while ((opt =3D getopt(argc, argv, "b:c:ef:ghi:m:nop:s:v:x:")) !=3D -1) { switch (opt) { case 'b': guest_percpu_mem_size =3D parse_size(optarg); break; + case 'c': + pcpu_list =3D optarg; + break; case 'e': /* 'e' is for evil. */ run_vcpus_while_disabling_dirty_logging =3D true; @@ -458,6 +474,9 @@ int main(int argc, char *argv[]) } } =20 + if (pcpu_list) + perf_test_setup_pinning(pcpu_list, nr_vcpus); + TEST_ASSERT(p.iterations >=3D 2, "The test should have at least two itera= tions"); =20 pr_info("Test iterations: %"PRIu64"\n", p.iterations); diff --git a/tools/testing/selftests/kvm/include/perf_test_util.h b/tools/t= esting/selftests/kvm/include/perf_test_util.h index eaa88df0555a..8197260e3b6b 100644 --- a/tools/testing/selftests/kvm/include/perf_test_util.h +++ b/tools/testing/selftests/kvm/include/perf_test_util.h @@ -27,6 +27,8 @@ struct perf_test_vcpu_args { /* Only used by the host userspace part of the vCPU thread */ struct kvm_vcpu *vcpu; int vcpu_idx; + /* The pCPU to which this vCPU is pinned. Only valid if pin_vcpus is true= . */ + int pcpu; }; =20 struct perf_test_args { @@ -39,6 +41,8 @@ struct perf_test_args { =20 /* Run vCPUs in L2 instead of L1, if the architecture supports it. */ bool nested; + /* True if all vCPUs are pinned to pCPUs*/ + bool pin_vcpus; =20 struct perf_test_vcpu_args vcpu_args[KVM_MAX_VCPUS]; }; @@ -60,4 +64,6 @@ void perf_test_guest_code(uint32_t vcpu_id); uint64_t perf_test_nested_pages(int nr_vcpus); void perf_test_setup_nested(struct kvm_vm *vm, int nr_vcpus, struct kvm_vc= pu *vcpus[]); =20 +void perf_test_setup_pinning(const char *pcpus_string, int nr_vcpus); + #endif /* SELFTEST_KVM_PERF_TEST_UTIL_H */ diff --git a/tools/testing/selftests/kvm/lib/perf_test_util.c b/tools/testi= ng/selftests/kvm/lib/perf_test_util.c index 9618b37c66f7..5d1aca0482b4 100644 --- a/tools/testing/selftests/kvm/lib/perf_test_util.c +++ b/tools/testing/selftests/kvm/lib/perf_test_util.c @@ -2,7 +2,10 @@ /* * Copyright (C) 2020, Google LLC. */ +#define _GNU_SOURCE + #include +#include =20 #include "kvm_util.h" #include "perf_test_util.h" @@ -240,9 +243,25 @@ void __weak perf_test_setup_nested(struct kvm_vm *vm, = int nr_vcpus, struct kvm_v exit(KSFT_SKIP); } =20 +static void pin_me_to_pcpu(int pcpu) +{ + cpu_set_t cpuset; + int err; + + CPU_ZERO(&cpuset); + CPU_SET(pcpu, &cpuset); + err =3D sched_setaffinity(0, sizeof(cpu_set_t), &cpuset); + TEST_ASSERT(err =3D=3D 0, "sched_setaffinity() errored out for pcpu: %d\n= ", pcpu); +} + static void *vcpu_thread_main(void *data) { struct vcpu_thread *vcpu =3D data; + int idx =3D vcpu->vcpu_idx; + struct perf_test_vcpu_args *vcpu_args =3D &perf_test_args.vcpu_args[idx]; + + if (perf_test_args.pin_vcpus) + pin_me_to_pcpu(vcpu_args->pcpu); =20 WRITE_ONCE(vcpu->running, true); =20 @@ -255,7 +274,7 @@ static void *vcpu_thread_main(void *data) while (!READ_ONCE(all_vcpu_threads_running)) ; =20 - vcpu_thread_fn(&perf_test_args.vcpu_args[vcpu->vcpu_idx]); + vcpu_thread_fn(vcpu_args); =20 return NULL; } @@ -292,3 +311,40 @@ void perf_test_join_vcpu_threads(int nr_vcpus) for (i =3D 0; i < nr_vcpus; i++) pthread_join(vcpu_threads[i].thread, NULL); } + +static int pcpu_num(const char *cpu_str) +{ + int pcpu =3D atoi_paranoid(cpu_str); + TEST_ASSERT(pcpu >=3D 0, "Invalid cpu number: %d\n", pcpu); + return pcpu; +} + +void perf_test_setup_pinning(const char *pcpus_string, int nr_vcpus) +{ + char delim[2] =3D ","; + char *cpu, *cpu_list; + int i =3D 0; + + cpu_list =3D strdup(pcpus_string); + TEST_ASSERT(cpu_list, "strdup() allocation failed.\n"); + + cpu =3D strtok(cpu_list, delim); + + // 1. Get all pcpus for vcpus + while (cpu && i < nr_vcpus) { + perf_test_args.vcpu_args[i++].pcpu =3D pcpu_num(cpu); + cpu =3D strtok(NULL, delim); + } + + TEST_ASSERT(i =3D=3D nr_vcpus, + "Number of pcpus (%d) not sufficient for the number of vcpus (%d).", + i, nr_vcpus); + + perf_test_args.pin_vcpus =3D true; + + // 2. Check if main worker is provided + if (cpu) + pin_me_to_pcpu(pcpu_num(cpu)); + + free(cpu_list); +} --=20 2.38.0.rc1.362.ged0d419d3c-goog