From patchwork Fri Aug 26 18:44:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 12956505 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 A972BECAAA3 for ; Fri, 26 Aug 2022 18:49:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239748AbiHZStN (ORCPT ); Fri, 26 Aug 2022 14:49:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345299AbiHZSsc (ORCPT ); Fri, 26 Aug 2022 14:48:32 -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 8FFEFE86BC for ; Fri, 26 Aug 2022 11:45:45 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id z22-20020a630a56000000b0041b98176de9so1213220pgk.15 for ; Fri, 26 Aug 2022 11:45:45 -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; bh=ybKUjgg6ch0GYw6EETwzWzCbbwkxj1dVORCeP7ssStQ=; b=bhdBMEDzmkep7dAIdCuBqStPdNwlsq4AV2zkIiFFXbPVDlm46CrTBdBALQLBVEhgtc g35/2jujy3+oZbNteXe+2HRA3wsitfCWoc9f3qMlgOr7RRJm9UsRtFhalkjq/1eTp0Sc +d8CmSax4UEaJWeCXHtFN3FFcgx8GklKf9T9yRr8nuyCUUIcsYdan/duqFkIYd1Jh9LH xeL5hBxRXYML7vrQk3v8TsgvgUdmKvv/0h3sWnrFdrQXptMlCY/fWBHfK6YJoIOqbj6I vGpVaXscpsFrK3stnZj8usGtgx8LbqcIsTYK/iwFLeJAg7kIG3x3opMd3o88b3zpNROg wkEQ== 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; bh=ybKUjgg6ch0GYw6EETwzWzCbbwkxj1dVORCeP7ssStQ=; b=hYDjX4VwNL2WeXmgUJ3vgDlmf6mly4aMHf7g330zXHE7W9X1GoOVGDZzSvyT9Pyjiy PvUrA4Cy6QvMorfA8uhSyK0QGt3C36qIFqncfdB52Vop7QYIcrDKNUS//qKgsbpbZK2V UcScRjBtCFM6dZFjZX+3mI2Fu2eFl8xI0e09RBYNyjlH2QiQnXaipV56I7Ont75HkbvH dfPUyRg7cS+2JOioVtdAdftp5VCqpkVWmtc/DmpUwKRuREUKxwuNSU6rphtUQk/+qjl1 rgfZtAx3VB/PaWleqt0STomZwlVYTDp/nZ7W/8AYqNh2ctXBzvSu30uwD5sQ07MMthxs gfXQ== X-Gm-Message-State: ACgBeo2Qqs8n+nJsMLmmOBqWvwgjHvB8/k0q0sNByZzNZQubDQSALgMX Y1zN+dXOJPmNeQDWs2C1l6cgmSPQEzPB X-Google-Smtp-Source: AA6agR40C4F/nP90aB06KBuicRVB8I2AEbMJTiexNJ65vSnFWjzRvwni2isMe6nRr7wWNlzAB4A19RsNV660 X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:aa7:9ac5:0:b0:537:e34f:c09c with SMTP id x5-20020aa79ac5000000b00537e34fc09cmr897487pfp.63.1661539545151; Fri, 26 Aug 2022 11:45:45 -0700 (PDT) Date: Fri, 26 Aug 2022 11:44:57 -0700 In-Reply-To: <20220826184500.1940077-1-vipinsh@google.com> Mime-Version: 1.0 References: <20220826184500.1940077-1-vipinsh@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Message-ID: <20220826184500.1940077-2-vipinsh@google.com> Subject: [PATCH v3 1/4] KVM: selftests: Explicitly set variables based on options in dirty_log_perf_test From: Vipin Sharma To: seanjc@google.com, dmatlack@google.com, pbonzini@redhat.com Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Variable set via -g are also indirectly set by -e option by omitting break statement. Set them explicitly so that movement of switch-case statements does not unintentionally break features. No functional change intended. Signed-off-by: Vipin Sharma --- tools/testing/selftests/kvm/dirty_log_perf_test.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/testing/selftests/kvm/dirty_log_perf_test.c b/tools/testing/selftests/kvm/dirty_log_perf_test.c index f99e39a672d3..a03db7f9f4c0 100644 --- a/tools/testing/selftests/kvm/dirty_log_perf_test.c +++ b/tools/testing/selftests/kvm/dirty_log_perf_test.c @@ -411,6 +411,8 @@ int main(int argc, char *argv[]) case 'e': /* 'e' is for evil. */ run_vcpus_while_disabling_dirty_logging = true; + dirty_log_manual_caps = 0; + break; case 'g': dirty_log_manual_caps = 0; break; From patchwork Fri Aug 26 18:44:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 12956506 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 A351BECAAD7 for ; Fri, 26 Aug 2022 18:49:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345299AbiHZStQ (ORCPT ); Fri, 26 Aug 2022 14:49:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231526AbiHZSss (ORCPT ); Fri, 26 Aug 2022 14:48:48 -0400 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0ED0CE9261 for ; Fri, 26 Aug 2022 11:45:56 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id i1-20020a170902cf0100b001730caeec78so1554902plg.7 for ; Fri, 26 Aug 2022 11:45:56 -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; bh=ed1e9YFm1bkZbR55Fi4AhXJIeJ9QRqoxJ1lB8J6isug=; b=crNOK3R3j37Xfzsw7QfNA/TW9IqQ86Oi4O+K9vKqcNRVNnRTzE1oXlyg98BmhLviPJ KLHYIbkEOkvBDd1CAUcAro992fVQk+vABTN3+2WkuHttTBFSOXWL7HdLVGnMNkkGlzqh aLPSLCRKfUKHTR/OLGAc2hEERwQwipghOY/UpBheYsv7EHMtLiGGJziLMXC2peRxrUHF cHmb9c1lPOczty49iWiq1S0AezJ119qzmB/nm9yxkjrc0X9cBCkG4wMbtm3z6vizScOL mL6P55tmRz+wuKR7IF1Sis2CxD2sQYTuUpPxGvduoZg7KF2JCnPww4DF3z30H5LdM7UD AunQ== 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; bh=ed1e9YFm1bkZbR55Fi4AhXJIeJ9QRqoxJ1lB8J6isug=; b=5fDdvMTftLPrHr5EOxsZdfBtvbAOUEMmmRQ2FamlSBiDNI1wbVewO0ZphxksXfbgGl 3/naPTrNXw9nhA4FmOKjIT0kMVZicKa/hrOyV4qsWn1lqpHJ3kQqn7stP4icdr8+43GI lTNL6izry72SUv3fD2WfDkMafAZwS5R7OPUiZGxpoXLvp8Pt78QzquYPrFCxaj0BGBZ9 UfgRXNePZz+OhBoSLTaHceMVqNWgTgabQM1x2p7t3u3FpPcx63yMn0iw8nh1jDFsqu4e yNjbrJDEO6VHcrXyFa04efYOvZ1VuQ+pjkX7c9HZMbeybunBel1NifadJkKC9Twn7Vfy Zl6A== X-Gm-Message-State: ACgBeo3mpLuR/mHF85wmqBA/2CX4r92nPR0iSso1Z3EYom5yYLFZXBU/ MGemjFTP8p3dGsoZS3U0T+UI7Cjn9j71 X-Google-Smtp-Source: AA6agR4VDwzUoO8UNjuYNU++2w8cs4ot7vOoQfFlsV1MVMK5t9LYoz+dLgPORgCghxFYDB3BmNjS+AqIy1UU X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a17:90a:c1:b0:1f4:f757:6b48 with SMTP id v1-20020a17090a00c100b001f4f7576b48mr5715558pjd.56.1661539555510; Fri, 26 Aug 2022 11:45:55 -0700 (PDT) Date: Fri, 26 Aug 2022 11:44:58 -0700 In-Reply-To: <20220826184500.1940077-1-vipinsh@google.com> Mime-Version: 1.0 References: <20220826184500.1940077-1-vipinsh@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Message-ID: <20220826184500.1940077-3-vipinsh@google.com> Subject: [PATCH v3 2/4] KVM: selftests: Put command line options in alphabetical order in dirty_log_perf_test From: Vipin Sharma To: seanjc@google.com, dmatlack@google.com, pbonzini@redhat.com Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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/testing/selftests/kvm/dirty_log_perf_test.c index a03db7f9f4c0..acf8b80c91d1 100644 --- a/tools/testing/selftests/kvm/dirty_log_perf_test.c +++ b/tools/testing/selftests/kvm/dirty_log_perf_test.c @@ -406,51 +406,53 @@ int main(int argc, char *argv[]) guest_modes_append_default(); - while ((opt = getopt(argc, argv, "eghi:p:m:nb:f:v:os:x:")) != -1) { + while ((opt = getopt(argc, argv, "b:ef:ghi:m:nop:s:v:x:")) != -1) { switch (opt) { + case 'b': + guest_percpu_mem_size = parse_size(optarg); + break; case 'e': /* 'e' is for evil. */ run_vcpus_while_disabling_dirty_logging = true; dirty_log_manual_caps = 0; break; + case 'f': + p.wr_fract = atoi(optarg); + TEST_ASSERT(p.wr_fract >= 1, + "Write fraction cannot be less than one"); + break; case 'g': dirty_log_manual_caps = 0; break; + case 'h': + help(argv[0]); + break; case 'i': p.iterations = atoi(optarg); break; - case 'p': - p.phys_offset = strtoull(optarg, NULL, 0); - break; case 'm': guest_modes_cmdline(optarg); break; case 'n': perf_test_args.nested = true; break; - case 'b': - guest_percpu_mem_size = parse_size(optarg); + case 'o': + p.partition_vcpu_memory_access = false; break; - case 'f': - p.wr_fract = atoi(optarg); - TEST_ASSERT(p.wr_fract >= 1, - "Write fraction cannot be less than one"); + case 'p': + p.phys_offset = strtoull(optarg, NULL, 0); + break; + case 's': + p.backing_src = parse_backing_src_type(optarg); break; case 'v': nr_vcpus = atoi(optarg); TEST_ASSERT(nr_vcpus > 0 && nr_vcpus <= max_vcpus, "Invalid number of vcpus, must be between 1 and %d", max_vcpus); break; - case 'o': - p.partition_vcpu_memory_access = false; - break; - case 's': - p.backing_src = parse_backing_src_type(optarg); - break; case 'x': p.slots = atoi(optarg); break; - case 'h': default: help(argv[0]); break; From patchwork Fri Aug 26 18:44:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 12956507 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 5B257ECAAD7 for ; Fri, 26 Aug 2022 18:49:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345098AbiHZStY (ORCPT ); Fri, 26 Aug 2022 14:49:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345092AbiHZSsx (ORCPT ); Fri, 26 Aug 2022 14:48:53 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D23C1E9921 for ; Fri, 26 Aug 2022 11:46:00 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id j3-20020a634a43000000b00429f2cb4a43so1232085pgl.0 for ; Fri, 26 Aug 2022 11:46: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; bh=OKhiGPhhBpk2IflQMoyVC2O8DiKKOEa1AJ4NqkPjkaI=; b=MftNhJIe3G7MJZO34epL9AuN+qQpSAABFbDWBHTPnMbZJCT2snjdTRc/1zf8J0kdT/ o56u8r+969adVVsW/O9vyWxX+sZVphDx0PNuivOMRrLwj17iZ24WnsboI3M5o75VFMMW 6M7IfMly+wXSeT7ZyjjMQz7/jS8HKBaZ342r605aOc4Val9h6Ad4h+nv1Xg5k5t5+sce VQcVK5f0oKzUZzgrnHIECwhAHb6mS3/OD7egDy4c4B50dMTx0Eyv8d7FFHuEtKzgn0dc k5W4c6/1k4pYnGd0Zy+aEopZUkJnGf4goVtducacZwT758klnGBsn7D3px8xPDw18gA9 lLNg== 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; bh=OKhiGPhhBpk2IflQMoyVC2O8DiKKOEa1AJ4NqkPjkaI=; b=uzc4duklH77+6IunB4ZVqIU8nOCH0n9GuGmfCz85aaJnUl+FA5JxqySTzNum9tltQe sjKNs5tXAW5BVzxzx5IEmomDpF7Kuqd3ztkHX09e/Nkl8f8jbH+CNqaB6W+nB/Cagi/H P0luzkFi2LABJVg+gIv8SoGWUDL6IhRQ2uYkuA6fWeX396gwhTJ98+2/zGie2c4zT6BP LBbnONpMBsHCk8wPnUi1bg03Fhi6AbiPjMPOTaC0hTkYsHYKl0ysN1+bN7lh8lAmoCC9 xPWBDmpASalGWbM23N6vVitzxuijAi6KL53djrxsxGXCuB5T8MfP0DM0WMoLECF1t8Nt OX1g== X-Gm-Message-State: ACgBeo0DaOmtWhhF1I9ykZP3Wrob3+oSWg2U6o6r0jPyHfYc8tgrbTA5 51xt36Uxq39CocIPMaTVKD8YtSbNU2Dk X-Google-Smtp-Source: AA6agR56m2+XvKqCue/yU4iW5ZSp8iYPOv6u/rpaz8OGs17UrQEZWrXNO4NPmOK784SzWZX23VM5N3q2EcZS X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a17:902:aa81:b0:173:3f68:e768 with SMTP id d1-20020a170902aa8100b001733f68e768mr4882412plr.80.1661539560401; Fri, 26 Aug 2022 11:46:00 -0700 (PDT) Date: Fri, 26 Aug 2022 11:44:59 -0700 In-Reply-To: <20220826184500.1940077-1-vipinsh@google.com> Mime-Version: 1.0 References: <20220826184500.1940077-1-vipinsh@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Message-ID: <20220826184500.1940077-4-vipinsh@google.com> Subject: [PATCH v3 3/4] KVM: selftests: Add atoi_paranoid to catch errors missed by atoi From: Vipin Sharma To: seanjc@google.com, dmatlack@google.com, pbonzini@redhat.com Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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 --- tools/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 +- tools/testing/selftests/kvm/demand_paging_test.c | 2 +- tools/testing/selftests/kvm/dirty_log_perf_test.c | 8 ++++---- tools/testing/selftests/kvm/include/test_util.h | 2 ++ tools/testing/selftests/kvm/kvm_page_table_test.c | 2 +- tools/testing/selftests/kvm/lib/test_util.c | 14 ++++++++++++++ .../testing/selftests/kvm/max_guest_memory_test.c | 6 +++--- .../kvm/memslot_modification_stress_test.c | 4 ++-- tools/testing/selftests/kvm/memslot_perf_test.c | 10 +++++----- .../testing/selftests/kvm/set_memory_region_test.c | 2 +- .../selftests/kvm/x86_64/nx_huge_pages_test.c | 4 ++-- 13 files changed, 43 insertions(+), 27 deletions(-) diff --git a/tools/testing/selftests/kvm/aarch64/arch_timer.c b/tools/testing/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 = getopt(argc, argv, "hn:i:p:m:")) != -1) { switch (opt) { case 'n': - test_args.nr_vcpus = atoi(optarg); + test_args.nr_vcpus = atoi_paranoid(optarg); if (test_args.nr_vcpus <= 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 = atoi(optarg); + test_args.nr_iter = atoi_paranoid(optarg); if (test_args.nr_iter <= 0) { pr_info("Positive value needed for -i\n"); goto err; } break; case 'p': - test_args.timer_period_ms = atoi(optarg); + test_args.timer_period_ms = atoi_paranoid(optarg); if (test_args.timer_period_ms <= 0) { pr_info("Positive value needed for -p\n"); goto err; } break; case 'm': - test_args.migration_freq_ms = atoi(optarg); + test_args.migration_freq_ms = 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 = getopt(argc, argv, "hn:e:l:")) != -1) { switch (opt) { case 'n': - nr_irqs = atoi(optarg); + nr_irqs = atoi_paranoid(optarg); if (nr_irqs > 1024 || nr_irqs % 32) help(argv[0]); break; case 'e': - eoi_split = (bool)atoi(optarg); + eoi_split = (bool)atoi_paranoid(optarg); default_args = false; break; case 'l': - level_sensitive = (bool)atoi(optarg); + level_sensitive = (bool)atoi_paranoid(optarg); default_args = false; break; case 'h': diff --git a/tools/testing/selftests/kvm/access_tracking_perf_test.c b/tools/testing/selftests/kvm/access_tracking_perf_test.c index 1c2749b1481a..99b16302d94d 100644 --- a/tools/testing/selftests/kvm/access_tracking_perf_test.c +++ b/tools/testing/selftests/kvm/access_tracking_perf_test.c @@ -361,7 +361,7 @@ int main(int argc, char *argv[]) params.vcpu_memory_bytes = parse_size(optarg); break; case 'v': - params.nr_vcpus = atoi(optarg); + params.nr_vcpus = atoi_paranoid(optarg); break; case 'o': overlap_memory_access = true; diff --git a/tools/testing/selftests/kvm/demand_paging_test.c b/tools/testing/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 = parse_backing_src_type(optarg); break; case 'v': - nr_vcpus = atoi(optarg); + nr_vcpus = atoi_paranoid(optarg); TEST_ASSERT(nr_vcpus > 0 && nr_vcpus <= 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/testing/selftests/kvm/dirty_log_perf_test.c index acf8b80c91d1..1346f6b5a9bd 100644 --- a/tools/testing/selftests/kvm/dirty_log_perf_test.c +++ b/tools/testing/selftests/kvm/dirty_log_perf_test.c @@ -417,7 +417,7 @@ int main(int argc, char *argv[]) dirty_log_manual_caps = 0; break; case 'f': - p.wr_fract = atoi(optarg); + p.wr_fract = atoi_paranoid(optarg); TEST_ASSERT(p.wr_fract >= 1, "Write fraction cannot be less than one"); break; @@ -428,7 +428,7 @@ int main(int argc, char *argv[]) help(argv[0]); break; case 'i': - p.iterations = atoi(optarg); + p.iterations = atoi_paranoid(optarg); break; case 'm': guest_modes_cmdline(optarg); @@ -446,12 +446,12 @@ int main(int argc, char *argv[]) p.backing_src = parse_backing_src_type(optarg); break; case 'v': - nr_vcpus = atoi(optarg); + nr_vcpus = atoi_paranoid(optarg); TEST_ASSERT(nr_vcpus > 0 && nr_vcpus <= max_vcpus, "Invalid number of vcpus, must be between 1 and %d", max_vcpus); break; case 'x': - p.slots = atoi(optarg); + p.slots = atoi_paranoid(optarg); break; default: help(argv[0]); diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testing/selftests/kvm/include/test_util.h index 5c5a88180b6c..56776f431733 100644 --- a/tools/testing/selftests/kvm/include/test_util.h +++ b/tools/testing/selftests/kvm/include/test_util.h @@ -150,4 +150,6 @@ static inline void *align_ptr_up(void *x, size_t size) return (void *)align_up((unsigned long)x, size); } +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/testing/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 = parse_size(optarg); break; case 'v': - nr_vcpus = atoi(optarg); + nr_vcpus = atoi_paranoid(optarg); TEST_ASSERT(nr_vcpus > 0 && nr_vcpus <= 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/selftests/kvm/lib/test_util.c index 6d23878bbfe1..1e560c30a696 100644 --- a/tools/testing/selftests/kvm/lib/test_util.c +++ b/tools/testing/selftests/kvm/lib/test_util.c @@ -334,3 +334,17 @@ long get_run_delay(void) return val[1]; } + +int atoi_paranoid(const char *num_str) +{ + int num; + char *end_ptr; + + errno = 0; + num = (int)strtol(num_str, &end_ptr, 10); + TEST_ASSERT(errno == 0, "Conversion error: %d\n", errno); + TEST_ASSERT(num_str != end_ptr && *end_ptr == '\0', + "Invalid number string.\n"); + + return num; +} diff --git a/tools/testing/selftests/kvm/max_guest_memory_test.c b/tools/testing/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 = getopt(argc, argv, "c:h:m:s:H")) != -1) { switch (opt) { case 'c': - nr_vcpus = atoi(optarg); + nr_vcpus = atoi_paranoid(optarg); TEST_ASSERT(nr_vcpus > 0, "number of vcpus must be >0"); break; case 'm': - max_mem = atoi(optarg) * size_1gb; + max_mem = atoi_paranoid(optarg) * size_1gb; TEST_ASSERT(max_mem > 0, "memory size must be >0"); break; case 's': - slot_size = atoi(optarg) * size_1gb; + slot_size = 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 = parse_size(optarg); break; case 'v': - nr_vcpus = atoi(optarg); + nr_vcpus = atoi_paranoid(optarg); TEST_ASSERT(nr_vcpus > 0 && nr_vcpus <= 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 = false; break; case 'i': - p.nr_memslot_modifications = atoi(optarg); + p.nr_memslot_modifications = atoi_paranoid(optarg); break; case 'h': default: diff --git a/tools/testing/selftests/kvm/memslot_perf_test.c b/tools/testing/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 = true; break; case 's': - targs->nslots = atoi(optarg); + targs->nslots = atoi_paranoid(optarg); if (targs->nslots <= 0 && targs->nslots != -1) { pr_info("Slot count cap has to be positive or -1 for no cap\n"); return false; } break; case 'f': - targs->tfirst = atoi(optarg); + targs->tfirst = 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 = atoi(optarg); + targs->tlast = atoi_paranoid(optarg); if (targs->tlast < 0 || targs->tlast >= 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 = atoi(optarg); + targs->seconds = 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 = atoi(optarg); + targs->runs = atoi_paranoid(optarg); if (targs->runs <= 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/testing/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[]) #ifdef __x86_64__ if (argc > 1) - loops = atoi(argv[1]); + loops = atoi_paranoid(argv[1]); else loops = 10; diff --git a/tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.c b/tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.c index cc6421716400..5e18d716782b 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 @@ -233,10 +233,10 @@ int main(int argc, char **argv) while ((opt = getopt(argc, argv, "hp:t:r")) != -1) { switch (opt) { case 'p': - reclaim_period_ms = atoi(optarg); + reclaim_period_ms = atoi_paranoid(optarg); break; case 't': - token = atoi(optarg); + token = atoi_paranoid(optarg); break; case 'r': reboot_permissions = true; From patchwork Fri Aug 26 18:45:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 12956508 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 979AFECAAA3 for ; Fri, 26 Aug 2022 18:49:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345311AbiHZStv (ORCPT ); Fri, 26 Aug 2022 14:49:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345315AbiHZStK (ORCPT ); Fri, 26 Aug 2022 14:49:10 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3778AEA8B0 for ; Fri, 26 Aug 2022 11:46:07 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id a21-20020a62bd15000000b005360da6b25aso1248094pff.23 for ; Fri, 26 Aug 2022 11:46:07 -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; bh=stpKDIZUfAsiCHACs7kxVCVZD/2HAYo+g81a4039rSM=; b=JLKuVXKrzJAX9lRDhFsvN8/57xqI44Ve65I6izBKMAWQAMDfeEvNRM8DT3GncC3jwZ C5mD65vLDnS6SAxPZoqbFr5f7WpXMTrxN/dyNDj4aqpZvCoZugfQPwalqA6vRAitkQQ+ iVq0c8TSx43/2GslVLWOp4abBXvIvl2/YnUmXq+KQOBelyY9wT8h7qhoazsR714fkWZ1 sd/h8qjuKJ+2YBKQQ0LS2IX6ai5LBKslrfp8j7nMI82yApy++/Q7osQdgMMx85/E/pSr M2nnRFjmfvS/DvYqbuzLCnbHCCSa9wxSi81pxM1dOSbEKgcyRA3ov+eLejm79JsPxgRX O5jA== 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; bh=stpKDIZUfAsiCHACs7kxVCVZD/2HAYo+g81a4039rSM=; b=vWXLiTrSfeV9wKGdFX55LWgN1UHkFEQN2XEDSuBVacx9Pph2RrBLa/YyZ1F7QJyNyA I3N4S85JIF2BcVCc59d0kQ+VXzdchTS3I4APF4NzA08hUzhWgzQ+K/CzcXNtFb0qahFH ynHBBUqsOvvhHAKm/JYhMRsowVjzJ93fXyB5fHXSyDiLjTLrQA9Lz6Y2JDSEOiSZY5vZ 3ONMeookgX7bFnjyEXP67PW9KsdtuXrWiY0YA8Wzm2So08JL8su3SNPKnFtCOwpe2304 HsJUKLiqVC8pIOYpafjCbLY3fgDnFDJPoNY/ZcldJQRRdu06GcFzNwgueaV1rPrQYsP0 /21w== X-Gm-Message-State: ACgBeo1lVWA9MWHXOK+VBXTCVLRdUQcs7RgF8ek+Tvgy7u4acex4jYcH y6+n6+HjKPaAvoSFZnBEarkg9Wm9xm/2 X-Google-Smtp-Source: AA6agR54JHf5XDCzHtZ9WW+dQdBMo2qJwzcI8ikqfIIMo2VhpBmsWT3mg59hNVT6q78/LP+pCPy1siiXW+CB X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a05:6a00:ad1:b0:530:2cb7:84e2 with SMTP id c17-20020a056a000ad100b005302cb784e2mr5057556pfl.18.1661539566895; Fri, 26 Aug 2022 11:46:06 -0700 (PDT) Date: Fri, 26 Aug 2022 11:45:00 -0700 In-Reply-To: <20220826184500.1940077-1-vipinsh@google.com> Mime-Version: 1.0 References: <20220826184500.1940077-1-vipinsh@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Message-ID: <20220826184500.1940077-5-vipinsh@google.com> Subject: [PATCH v3 4/4] KVM: selftests: Run dirty_log_perf_test on specific cpus From: Vipin Sharma To: seanjc@google.com, dmatlack@google.com, pbonzini@redhat.com Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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.com Signed-off-by: Vipin Sharma Suggested-by: David Matlack Suggested-by: Sean Christopherson Suggested-by: Paolo Bonzini --- .../selftests/kvm/dirty_log_perf_test.c | 23 ++++++- .../selftests/kvm/include/perf_test_util.h | 4 ++ .../selftests/kvm/lib/perf_test_util.c | 62 ++++++++++++++++++- 3 files changed, 86 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/kvm/dirty_log_perf_test.c b/tools/testing/selftests/kvm/dirty_log_perf_test.c index 1346f6b5a9bd..9514b5f28b67 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 thread 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 = 1, }; int opt; + const char *pcpu_list = NULL; dirty_log_manual_caps = kvm_check_cap(KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2); @@ -406,11 +419,14 @@ int main(int argc, char *argv[]) guest_modes_append_default(); - while ((opt = getopt(argc, argv, "b:ef:ghi:m:nop:s:v:x:")) != -1) { + while ((opt = getopt(argc, argv, "b:c:ef:ghi:m:nop:s:v:x:")) != -1) { switch (opt) { case 'b': guest_percpu_mem_size = parse_size(optarg); break; + case 'c': + pcpu_list = optarg; + break; case 'e': /* 'e' is for evil. */ run_vcpus_while_disabling_dirty_logging = true; @@ -459,6 +475,9 @@ int main(int argc, char *argv[]) } } + if (pcpu_list) + perf_test_setup_pinning(pcpu_list, nr_vcpus); + TEST_ASSERT(p.iterations >= 2, "The test should have at least two iterations"); pr_info("Test iterations: %"PRIu64"\n", p.iterations); diff --git a/tools/testing/selftests/kvm/include/perf_test_util.h b/tools/testing/selftests/kvm/include/perf_test_util.h index eaa88df0555a..d02619f153a2 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; + bool pin_pcpu; + int pcpu; }; struct perf_test_args { @@ -60,4 +62,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_vcpu *vcpus[]); +int 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/testing/selftests/kvm/lib/perf_test_util.c index 9618b37c66f7..7a1e8223e7c7 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 #include "kvm_util.h" #include "perf_test_util.h" @@ -240,9 +243,26 @@ void __weak perf_test_setup_nested(struct kvm_vm *vm, int nr_vcpus, struct kvm_v exit(KSFT_SKIP); } +static void pin_me_to_pcpu(int pcpu) +{ + cpu_set_t cpuset; + int err; + + CPU_ZERO(&cpuset); + CPU_SET(pcpu, &cpuset); + errno = 0; + err = sched_setaffinity(0, sizeof(cpu_set_t), &cpuset); + TEST_ASSERT(err == 0, "sched_setaffinity errored out: %d\n", errno); +} + static void *vcpu_thread_main(void *data) { struct vcpu_thread *vcpu = data; + int idx = vcpu->vcpu_idx; + struct perf_test_vcpu_args *vcpu_args = &perf_test_args.vcpu_args[idx]; + + if (vcpu_args->pin_pcpu) + pin_me_to_pcpu(vcpu_args->pcpu); WRITE_ONCE(vcpu->running, true); @@ -255,7 +275,7 @@ static void *vcpu_thread_main(void *data) while (!READ_ONCE(all_vcpu_threads_running)) ; - vcpu_thread_fn(&perf_test_args.vcpu_args[vcpu->vcpu_idx]); + vcpu_thread_fn(vcpu_args); return NULL; } @@ -292,3 +312,43 @@ void perf_test_join_vcpu_threads(int nr_vcpus) for (i = 0; i < nr_vcpus; i++) pthread_join(vcpu_threads[i].thread, NULL); } + +int perf_test_setup_pinning(const char *pcpus_string, int nr_vcpus) +{ + char delim[2] = ","; + char *cpu, *cpu_list; + int i = 0, pcpu_num; + + cpu_list = strdup(pcpus_string); + TEST_ASSERT(cpu_list, "strdup() allocation failed.\n"); + + cpu = strtok(cpu_list, delim); + + // 1. Get all pcpus for vcpus + while (cpu && i < nr_vcpus) { + pcpu_num = atoi_paranoid(cpu); + TEST_ASSERT(pcpu_num >= 0, "Invalid cpu number: %d\n", pcpu_num); + + perf_test_args.vcpu_args[i].pin_pcpu = true; + perf_test_args.vcpu_args[i++].pcpu = pcpu_num; + + cpu = strtok(NULL, delim); + } + + TEST_ASSERT(i == nr_vcpus, + "Number of pcpus (%d) not sufficient for the number of vcpus (%d).", + i, nr_vcpus); + + // 2. Check if main worker is provided + if (cpu) { + pcpu_num = atoi_paranoid(cpu); + TEST_ASSERT(pcpu_num >= 0, "Invalid cpu number: %d\n", pcpu_num); + + pin_me_to_pcpu(pcpu_num); + + cpu = strtok(NULL, delim); + } + + free(cpu_list); + return i; +}