From patchwork Wed Nov 2 23:27:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 14569 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp209446wru; Wed, 2 Nov 2022 16:46:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5wS6n8rsdjfPF/rw/sHOVd6SCvXFYfliXBMzg+Y5goKDuFOm5I5cABjlJgivOwB1aisMor X-Received: by 2002:a05:6402:2794:b0:461:d60c:30c7 with SMTP id b20-20020a056402279400b00461d60c30c7mr26711117ede.392.1667432808747; Wed, 02 Nov 2022 16:46:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667432808; cv=none; d=google.com; s=arc-20160816; b=t9l4WuxhguZFkDMPOoCEKqRTzm79bASB8UmO99Zpvn9nV+4GWpi4WQyX+dmtnkvnvZ 6TD7pjP+t/s1zzH28jl0wI/FMHfgpMOLMzMEsEocuW8J2lKlCsStzdCsVX3I6n6qnsrJ JwPDD2xmV7u8+HnszfcmDfXO5IFyrMp9tYvDu4ZjrTM3HojWTca+kLWs9KJr1ErRn06f gFtOxqVmiD3o23uprIoJDglLyBUMIpdYya4eWJ61RddCcH1eMAvSzvDZ1AVfA2iPKJBq TlENPVz0nsf6u57mNlHiHNfoLtGejCbNefi/KMYJEcdmCytp9oIFeyhyLdo9NdX9cQKz kK7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=6wM4Oy0nUMfbEGH4TnyyZoGSCQjO5BHCNka2AusodrI=; b=yYWK7e9Yxp8WzkT2Q2KPwKhLEy/42x3BfobQS2ShsQdMpxbYLRTiKYKj5ryv9165QH yHLo0jnKXgJ9/gGeu3Xa0ivZz+H5P7/0S0tX/GNPaADEq6o0u0OuC+f9AiJjc99tGyzl MUYFjeosfrJupguIzU5ZMyZgIe5lEtmBDgb24UPjz/XRNIhvzBxz1m3DFKUFgLoh7Lqd oUluf9t7u98ouLJ6+tVOY6tTay30JhBZrF1foUMJqr6DDFlSpskmRZkfVEc6wfR0QIal o2P72duiMmLo8RAexEBDCfkLR000swSf3pT4EqqYTL3mummgoPMj0A+Hk7FY/YQEyLot zO9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=aaWoxlOt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w8-20020aa7cb48000000b00462a87b0546si6095673edt.607.2022.11.02.16.46.24; Wed, 02 Nov 2022 16:46:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=aaWoxlOt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231601AbiKBXkM (ORCPT + 99 others); Wed, 2 Nov 2022 19:40:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231485AbiKBXjy (ORCPT ); Wed, 2 Nov 2022 19:39:54 -0400 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC16E10077 for ; Wed, 2 Nov 2022 16:32:45 -0700 (PDT) Received: by mail-pl1-f202.google.com with SMTP id s15-20020a170902ea0f00b00187050232fcso253047plg.3 for ; Wed, 02 Nov 2022 16:32: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:subject:date:message-id:reply-to; bh=6wM4Oy0nUMfbEGH4TnyyZoGSCQjO5BHCNka2AusodrI=; b=aaWoxlOtXkyHzeY2UI1c5F/unLAqVQbf9+TC5N/PBWZcNjul/X5RFIAFzlGtRKcWs4 OgpA6zR7t7i8bZhrEWaXGoRjthT+d7NlbbV8pts9ahkg/WJdtUj2WxbzjOrh3MtpQG+j I3YxOyGr8bB0FnEUdY7hJgvBFP5IUCdQXpvcoGcm13WAlHgXuMWQ6OfZg8we6s31U+ss Nq0gb/FWFJgrxu4Avp0ZRyDh8zt3rkVuYn+/b8lHOzIGWYEYaFiP4tYRr2F3njnNm4Ju pbJsgauh5cZJbDLA2GdVFxGKwOJUHopQxVNefGf9xBQweKlu6TwzVCDAV9rq30AzD+dg s8zw== 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=6wM4Oy0nUMfbEGH4TnyyZoGSCQjO5BHCNka2AusodrI=; b=66mcJMmM8hqjHF+eSvJoDS41Q4J7EU1h/+41xVuc5s83G/g2XTS0Ffmggs+/JweIYT YcNDSSRCdbadtWXbJoTNjeGhXZtAchky6HKl9GEonFdSY3O+3CnAXpyqMejCMZtK0b/P 3870dlMbPqgF9gm61Cy+faogvC//+Y61ixQ/vKUwHvh9rolLuQP+aDPVtE9GqHXNu0lP b3Ssa/qT3jZdMGt0Wu19kOOmCE6qatnvkr4GrEhe9T91zFvtrQkTs3EufmIevwf7mjwA mZ2ZaHPDrLiWeMr7jS7M2sDZq1Ljt2QKhU0tFeUMnszBuISPxKe+8Mnzmd0Rm7JoVg9D 5MrQ== X-Gm-Message-State: ACrzQf2zfJ4fDqy1AH3UN4tlia4HPoRev8X2HaG3G+IVz9MZ30hoQlv8 Q77N4hUusp4dveiPexo8zX/Va+LrnbIe X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a17:90b:4b0e:b0:214:1328:e33a with SMTP id lx14-20020a17090b4b0e00b002141328e33amr10680462pjb.207.1667431662479; Wed, 02 Nov 2022 16:27:42 -0700 (PDT) Date: Wed, 2 Nov 2022 16:27:31 -0700 In-Reply-To: <20221102232737.1351745-1-vipinsh@google.com> Mime-Version: 1.0 References: <20221102232737.1351745-1-vipinsh@google.com> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog Message-ID: <20221102232737.1351745-2-vipinsh@google.com> Subject: [PATCH v8 1/7] 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, wei.w.wang@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748430024922757167?= X-GMAIL-MSGID: =?utf-8?q?1748430024922757167?= 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 switch case logic. Fixes: cfe12e64b065 ("KVM: selftests: Add an option to run vCPUs while disabling dirty logging") Signed-off-by: Vipin Sharma Reviewed-by: Sean Christopherson --- 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/testing/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 = true; + break; case 'g': dirty_log_manual_caps = 0; break; From patchwork Wed Nov 2 23:27:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 14563 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp208914wru; Wed, 2 Nov 2022 16:45:27 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5aBHG8ibxt9z20riMx+WtNkZ/VX9MTpxl21SymFERpAw8L2M7P9VnEJxD+eodqQtPAEgDi X-Received: by 2002:a50:950d:0:b0:463:298a:448c with SMTP id u13-20020a50950d000000b00463298a448cmr21710449eda.153.1667432727275; Wed, 02 Nov 2022 16:45:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667432727; cv=none; d=google.com; s=arc-20160816; b=IkgM3F6DFEzqdpF7GXrcaI6WrcDVWeOOHRawSvsGGI89Z/ZmjZvhjuBOlcKAnApxJS EDho+kJ6nbsCtJAHexu6SaJW1bdEhi5HOAEUnhVFbExMXU9CdURJwkGHXeeNnEWKcxnn /4/ZhugIYnY6DuPsaD1TvgSqAx2+KDi/MJS09ovSqltpS2GTZhmoLto4myyrQnSlAF2A UXkNG7HbzcrrOi7xrfFaNqHbAPhEiIMqz66EZkJFBZx9ap7AYsZi/GIJf0I8itLa6yKL tCPOh6MZNPKyXMtokVFfCe4vmifOUCjdpX6uy63k30l+JERtU+bUZ6abpFtXo9phQW6Z StQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=sdCA7mcVjAUWc0YMUhoHrXJZD+ZYpCbmWTqjMXRG8IY=; b=WmesFkzJxJvX3Pbq3UsR6BJQzI0c8HdhNgvN1URnrxyz0Zy40Dt/gbC0EDRLcVfrIt r9rpmyVvTZdMBI16CdhALzAmqGaTuxj6+z0dSzcvT673SQJOhlLMN7+srj0/HiPcbeDr QZiF64qWCU9m1x2vJIdQiVrZ7KoqSerH8yVPzfFQOJCpwvk54kviV4ytikYp1rUBdF6I fLxPVyEP9XE4Zx61FlE2y2rLHZmeka8DiJtX8O+tLbWhXDmExzz6suGSMTza9ehN6aFu PIoiIZ8HTViZAf6OqZe2qRgnUtbbBYB4R4cafzgLoNuSvJo/ukPMBXctuZLo9gK0TRWe Ugcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=PGaFr+qG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s5-20020a056402520500b0045ca15afe1csi20237684edd.553.2022.11.02.16.45.02; Wed, 02 Nov 2022 16:45:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=PGaFr+qG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231624AbiKBXgy (ORCPT + 99 others); Wed, 2 Nov 2022 19:36:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231396AbiKBXg1 (ORCPT ); Wed, 2 Nov 2022 19:36:27 -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 6181D64E0 for ; Wed, 2 Nov 2022 16:28:25 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id b1-20020a17090a10c100b0020da29fa5e5so85790pje.2 for ; Wed, 02 Nov 2022 16:28:25 -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=sdCA7mcVjAUWc0YMUhoHrXJZD+ZYpCbmWTqjMXRG8IY=; b=PGaFr+qGgiFZsuqNJ4r0qGcqe0peI7+c4i53VjKhst54w0URdIJKXzZNrE1Ly93vHm ZUbVyccc+uf8FdIO/NLMK+zN19LS2ILfB8gdsaXOgRqmNf5gNf8Sq41ErU5US7FBhDnN IbJDzyfjQaKFpkHkPl3bYwopRjVjLACAqEC0DNB29g1Ge5y9OBvBYWx5FgfCeRj47bTd uP0JA8MOwOO3U1UGREYehl5yuws8MbqIXcCuXKo+lp0r7KUXTVAPpiUkXP49Oc4FpCms bJYwo+JQ3/cJgnCgmhkiynV8huNUX8jXmwm0fx3NQvdXEGtKtu0iZB7J+Ljry5Hp06qq yEJg== 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=sdCA7mcVjAUWc0YMUhoHrXJZD+ZYpCbmWTqjMXRG8IY=; b=s5z3+ULMvN782tjsjGE35o4jCaaPV5SC6OhzOPyhs3qlNakcaAUoxs8ufwXfKL7J7X vpT41/CY4BL7Uc79sUgiV+PGjBGkFkAMLi1/3MW1u0wBtibaN6+llmTT91oovjjXVIWq YetP3tI3DUVchIw0vtsi6QY7QCtciihQZKpIL95JetJZ6pF3BeTRRTzjH+vQo9EopGZ/ m8DzLetCEZAakIo/rp4KLjAXhAOkIuj8d84sCni1ndRCznEL9xtU7TUXzS3OuWhSGUu2 eeQIpczFqdNBe9j5gXKu+WwYaGQAUwXCA76OQDXXfuiJKy8JDeo9I7ISnYiPzn1BhLlR ue0w== X-Gm-Message-State: ACrzQf0w6U0J7rGHDkOjvBupGlujDXMLiLEYbirCw5HBlax/pHKt4N0J IX87pyaJUH997RSu8+Ka+aQDT7bLfKMo X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a17:903:2342:b0:181:bc30:b02f with SMTP id c2-20020a170903234200b00181bc30b02fmr27154262plh.30.1667431664230; Wed, 02 Nov 2022 16:27:44 -0700 (PDT) Date: Wed, 2 Nov 2022 16:27:32 -0700 In-Reply-To: <20221102232737.1351745-1-vipinsh@google.com> Mime-Version: 1.0 References: <20221102232737.1351745-1-vipinsh@google.com> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog Message-ID: <20221102232737.1351745-3-vipinsh@google.com> Subject: [PATCH v8 2/7] 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, wei.w.wang@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748429939600040736?= X-GMAIL-MSGID: =?utf-8?q?1748429939600040736?= 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 Reviewed-by: Wei Wang Reviewed-by: Sean Christopherson --- .../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 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[]) 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; 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 Wed Nov 2 23:27:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 14567 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp209158wru; Wed, 2 Nov 2022 16:46:07 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Hj/wgBG4uAa6lReKLm37S6o9DuNChUI4M/OJePRgEehAZi+vGvFbJFM3mGCwyJR5A0FYR X-Received: by 2002:a17:907:1b09:b0:7ac:db30:2cf0 with SMTP id mp9-20020a1709071b0900b007acdb302cf0mr26077737ejc.679.1667432767781; Wed, 02 Nov 2022 16:46:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667432767; cv=none; d=google.com; s=arc-20160816; b=D0P3ZaexUpGBr8nw24CpSu2Je9u1+BUMayhDFGPFesyLWj5VMgj98uXL5tf2Ke+c/U DUuzoQdK9WMpUUhj71OL6ZMfLFok3UAssiEi4hj00/l5lslyRp1b34rbEpy8RttWXwt/ SK6Bde+R6kP2hdDZvfk/xQrygjch7VrqbodtPhCJZtP3RAiGFXj0ISjPl9DBbaeoscFA HFc74g/Ma3laZ9K8PzbudF0miyQDkUYzFbs4f3i4d47v3juP7Trev4HzTrJKgifcu3g/ BNoAqhVQ4jrRcChhthbvKX4La/CwXt4jamQJQ8mwmYbA0b6ZGlRNufIgYURaeZGqM8C1 tB7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=2TwXrPUJch0Rw/TGfR74PWZyxOV/nk5K4+mVGpIBq80=; b=De7lrZO9wil5Oa1w48KxnX93ggsJv3Adv5fdOzM7UGVQq7RDKnKF1HMcbG3zzDyxom JqSHtNotVL98BOhgTmAQmqjFBCa56WezxWLESFqU99qQjh0tfdj3sb8Gix26h/UgrP7p ry0/8Gi2twd4LVxp2xP86KSK3kJzF5D9jSCKC9TKf/h5TzcErxmaBDStAkbCQowrPz3N uns3TG5l1w1+ysKO02tfoxLs8VlyHDM4ZHKdpaUPQFf/Xz28Tuf46Z3V83fC9nLoS4oG 3yRvDIugbugdM//vVzehVpM6rOpWyESb/ReCVNtfhQFu6tUFHhCNlyQOuVs5RPqNYBz7 ILdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=UCCSXPw7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f3-20020a056402150300b00462b89cc2c6si14846386edw.267.2022.11.02.16.45.44; Wed, 02 Nov 2022 16:46:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=UCCSXPw7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231571AbiKBXiW (ORCPT + 99 others); Wed, 2 Nov 2022 19:38:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231255AbiKBXiF (ORCPT ); Wed, 2 Nov 2022 19:38:05 -0400 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 741F818B29 for ; Wed, 2 Nov 2022 16:29:21 -0700 (PDT) Received: by mail-yb1-f202.google.com with SMTP id k7-20020a256f07000000b006cbcc030bc8so348138ybc.18 for ; Wed, 02 Nov 2022 16:29:21 -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=2TwXrPUJch0Rw/TGfR74PWZyxOV/nk5K4+mVGpIBq80=; b=UCCSXPw7OdN8xj3EMrXKN4J0ROW+3YfDeQ9UPO867fJN2ZHj9oW+0GsZhQ3ajxdAbC AL0jGdqSM7lcG3agHtjGNpVdNEjHkpfn3bMWwPYFSBa8J9zHy+k+DbKQrC5eE2e5QOVu BIoR/OBTuMPYRB/Kp17e8yC8SHbaxWt8n+ZcbcwIhEwGpVTv/1GU776LtS0R/sukEwr1 ZL1Pv4b0u6GpFthDnZ8SoDqP0IVsvePEh2laa7GHPu1iP6XHgMQxufhZVu3FA6Fyj2O6 E5UOnuxQKANVECzq0CEBW3dCYXWXVyN0s7hxaM3gBaAB0T9OAz0kGyF6l1v/OiXLhbGO CKtw== 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=2TwXrPUJch0Rw/TGfR74PWZyxOV/nk5K4+mVGpIBq80=; b=sYQuZmmPDhtbjoCxeqK5DsNTLcy+ZJcbYrMIBPHmwlYw3Tc7D9lKhx28gAT0fcyV8z G7RNg3A0C2cbWwXjfJZ6olLK75F4QUX6ElGC1qS3twsQpc+21Lxux2bFOjqKqUqkWFY0 wtnWL65mkWvrprnwKe3Y8HwvAWQysXFT42j16Vu17QPOzpe+ooIza9uoTOvlUo8MW0eu WJDhqEre5xRLUIAgdK7X/1Dqoe/Hp8CuNcw1jDyBQU1SptT6LDdZheDdWJy7jR0Jwqty oJCP1u/ll2ILU/lwccZt2yG1Ovj+U4WiuXiO5an/EhqpgUg3tEAzEaD/wC9SiorYwq9Z XkXg== X-Gm-Message-State: ACrzQf2H2zNKF0hePh8SnaiVvilwvbZ3ZScmcjwIBXrovrq/UG+Ng8t8 0Ml2bGWhxy+1YlEfXITfk++wF9rEkxDS X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a25:9986:0:b0:6a7:29ef:133c with SMTP id p6-20020a259986000000b006a729ef133cmr27130852ybo.479.1667431665930; Wed, 02 Nov 2022 16:27:45 -0700 (PDT) Date: Wed, 2 Nov 2022 16:27:33 -0700 In-Reply-To: <20221102232737.1351745-1-vipinsh@google.com> Mime-Version: 1.0 References: <20221102232737.1351745-1-vipinsh@google.com> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog Message-ID: <20221102232737.1351745-4-vipinsh@google.com> Subject: [PATCH v8 3/7] 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, wei.w.wang@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748429981792670207?= X-GMAIL-MSGID: =?utf-8?q?1748429981792670207?= 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 Reviewed-by: Sean Christopherson --- .../selftests/kvm/aarch64/arch_timer.c | 8 ++++---- .../selftests/kvm/aarch64/debug-exceptions.c | 2 +- .../testing/selftests/kvm/aarch64/vgic_irq.c | 6 +++--- .../selftests/kvm/access_tracking_perf_test.c | 2 +- .../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 | 19 +++++++++++++++++++ .../selftests/kvm/max_guest_memory_test.c | 6 +++--- .../kvm/memslot_modification_stress_test.c | 6 +++--- .../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 ++-- 14 files changed, 50 insertions(+), 29 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/debug-exceptions.c b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c index 947bd201435c..19fffdf19c9f 100644 --- a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c +++ b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c @@ -423,7 +423,7 @@ int main(int argc, char *argv[]) while ((opt = getopt(argc, argv, "i:")) != -1) { switch (opt) { case 'i': - ss_iteration = atoi(optarg); + ss_iteration = atoi_paranoid(optarg); break; case 'h': default: 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 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 = 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 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 = true; 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; @@ -427,7 +427,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); @@ -445,12 +445,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 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); } +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..c2d9c6827779 100644 --- a/tools/testing/selftests/kvm/lib/test_util.c +++ b/tools/testing/selftests/kvm/lib/test_util.c @@ -334,3 +334,22 @@ long get_run_delay(void) return val[1]; } + +int atoi_paranoid(const char *num_str) +{ + char *end_ptr; + long num; + + errno = 0; + num = strtol(num_str, &end_ptr, 0); + TEST_ASSERT(!errno, "strtol(\"%s\") failed", num_str); + TEST_ASSERT(num_str != end_ptr, + "strtol(\"%s\") didn't find a valid integer.", num_str); + TEST_ASSERT(*end_ptr == '\0', + "strtol(\"%s\") failed to parse trailing characters \"%s\".", + num_str, end_ptr); + TEST_ASSERT(num >= INT_MIN && num <= INT_MAX, + "%ld not in range of [%d, %d]", num, INT_MIN, INT_MAX); + + 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..d7ddc8a105a2 100644 --- a/tools/testing/selftests/kvm/memslot_modification_stress_test.c +++ b/tools/testing/selftests/kvm/memslot_modification_stress_test.c @@ -158,7 +158,7 @@ int main(int argc, char *argv[]) guest_modes_cmdline(optarg); break; case 'd': - p.memslot_modification_delay = strtoul(optarg, NULL, 0); + p.memslot_modification_delay = atoi_paranoid(optarg); TEST_ASSERT(p.memslot_modification_delay >= 0, "A negative delay is not supported."); break; @@ -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 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 = 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 Wed Nov 2 23:27:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 14566 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp209144wru; Wed, 2 Nov 2022 16:46:05 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7lwBw7j74dJQ0lJHDUDu4WanKmDJOhmMS4qSQlDMRXVAin75R+jqL3tNMkcpGTGJrW5T37 X-Received: by 2002:a17:906:3e01:b0:781:6462:700f with SMTP id k1-20020a1709063e0100b007816462700fmr26553214eji.307.1667432765559; Wed, 02 Nov 2022 16:46:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667432765; cv=none; d=google.com; s=arc-20160816; b=m+/WZZsUorfJSYRwPzSm9nXso+Ws86rdYlUbMu8DF6PxAeO4hxKC9NQc/686j7GD+Y L2OZI+tNOwNGUr+8xg4/AlskyzrPKLJGUPAukFK9YDpXjbUEUHGZW3MI9pyqVQ214Dtz ZHaH/ttitAI3EwbmY7vxZ4u+/JCKnmA++gfDJUXaAedj6ICIws1ucTuknSzQAMcqyi7P vXK1br+eOwwfOoMh9sgcdlivPptDIkj8AhkhO1gV7SmLy/6TLk70ZWNt3r3eMhS2laRX sdsYlpDPyhJguVwtYZrOZtXtmuwRlpitFy59BkRYZjSEprTplLNoI/+xc+L4VW8Ke91J CipQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=iC0/T0AhLSWTGEIBQBOFB08rB97eCOcnEVK/qTBONrw=; b=aBZLmOyzR+X8jUHxCpDgYC7v65AgAZIHDY2umtXLSe/4cUAu7RQZZC+xLgQxc9GFw5 12J8grZNixOHG613CJdGxuFh5HWMJ9C6cQH0G6wRJduh0gwfC/jYfidOOS2YPJj4IC3a gyxVnYOveJs7QnVTyhvDwBQHzDqyri5JgdUvJCVLZDn4C+rYG7lfabpZvvQcpgOw0Ofb IhUpYZGMvZIZoYo5VraC7BnAmHB0aUNC8Sq8jnidStL4ybR/Lx8KNPJ5OOo0b471xqm4 Q9gZH70hyYjqvyUDfRkwqUfeNnZrkPXMQ67CANj+R4gbY3ZHmhURDoKsoRUiGYn1SXXW IGWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="tZw/FyIV"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j17-20020a170906431100b0079330b37fb5si11761055ejm.564.2022.11.02.16.45.41; Wed, 02 Nov 2022 16:46:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="tZw/FyIV"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231326AbiKBXhu (ORCPT + 99 others); Wed, 2 Nov 2022 19:37:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230381AbiKBXhd (ORCPT ); Wed, 2 Nov 2022 19:37:33 -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 E3E2717A8E for ; Wed, 2 Nov 2022 16:28:57 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id 186-20020a6301c3000000b0046fa202f720so87781pgb.20 for ; Wed, 02 Nov 2022 16:28: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=iC0/T0AhLSWTGEIBQBOFB08rB97eCOcnEVK/qTBONrw=; b=tZw/FyIVcLFV6FA43bzdEfF9B7To8LmWA2trx2hUjXhZIwCqyiHS5JPWpTe77VM+Zu A0vvMWIX0mmMQWsuW5gcXP3zUecRsw2cEjV1dUamNxNTGcfF4iz6i7W1YHi7fo209V7r 71ruyH5ckKO+X8r5hZ/fgQw9WCkg6P0aeK1P9N3IfL9vGCZY4+40d3hRKxGy6cPRSIcX p9l2yO/RmzfjCYN3NyPDHhIPEt/IJqmX6893+qbHH/TBu0mbukYWgjozBLmpd7BUYWQ7 aIkUPatwDmQMh/4L6DZOR53SFEGISgBmptXfdW0zNg5biLNXlqn8WbVsG6doRANl/F7u nS7w== 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=iC0/T0AhLSWTGEIBQBOFB08rB97eCOcnEVK/qTBONrw=; b=7ttC6L/WwTo1cF/QIXztGIKYm6PDXFXy6Z40LtOB3X9GBgCNfi53XTFUGyjqoDrbhq BvAmjpbvKZ5r47LArCosHuXVTDcnJ6uhp2pA4sdwDfYTo6JBEpzNCLastvGTLOR7oq5s +6NIwGNSzrXmOp2XaLGlozukyRusnY7Lb1/TvSmyIVivEVuinhxfvRgnABuILApWyQG9 9SQI3pbQnAMP8eOoIfYtAp8HS4if+IGU9jLb3InpSKSzNAtDPVUtaTZRfIqueqKmZcMH ScccCi0hedxsSBkfT/0HHarw9qzE0Z4C4y1mZOP4SyBT+2EyO2OOHbwsMDzEE0mOizWk k5yA== X-Gm-Message-State: ACrzQf0ABgdseM8+X+rvyuGroCsDrxsxY/VTYZ94ks3PtUMNhEKXexyx /UofJKB0o2wPf8pCXk7WisXq2FrWVJ72 X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a17:90b:1d90:b0:213:d0a2:72ab with SMTP id pf16-20020a17090b1d9000b00213d0a272abmr21443758pjb.221.1667431667652; Wed, 02 Nov 2022 16:27:47 -0700 (PDT) Date: Wed, 2 Nov 2022 16:27:34 -0700 In-Reply-To: <20221102232737.1351745-1-vipinsh@google.com> Mime-Version: 1.0 References: <20221102232737.1351745-1-vipinsh@google.com> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog Message-ID: <20221102232737.1351745-5-vipinsh@google.com> Subject: [PATCH v8 4/7] KVM: selftests: Use SZ_1G from sizes.h in max_guest_memory_test.c From: Vipin Sharma To: seanjc@google.com, pbonzini@redhat.com, dmatlack@google.com Cc: andrew.jones@linux.dev, wei.w.wang@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748429979597115452?= X-GMAIL-MSGID: =?utf-8?q?1748429979597115452?= Replace size_1gb defined in max_guest_memory_test.c with the SZ_1G from linux/sizes.h header file. Signed-off-by: Vipin Sharma Reviewed-by: Sean Christopherson --- .../selftests/kvm/max_guest_memory_test.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/kvm/max_guest_memory_test.c b/tools/testing/selftests/kvm/max_guest_memory_test.c index 1595b73dc09a..8056dc5831b5 100644 --- a/tools/testing/selftests/kvm/max_guest_memory_test.c +++ b/tools/testing/selftests/kvm/max_guest_memory_test.c @@ -11,6 +11,7 @@ #include #include #include +#include #include "kvm_util.h" #include "test_util.h" @@ -162,8 +163,7 @@ int main(int argc, char *argv[]) * just below the 4gb boundary. This test could create memory at * 1gb-3gb,but it's simpler to skip straight to 4gb. */ - const uint64_t size_1gb = (1 << 30); - const uint64_t start_gpa = (4ull * size_1gb); + const uint64_t start_gpa = SZ_4G; const int first_slot = 1; struct timespec time_start, time_run1, time_reset, time_run2; @@ -180,13 +180,13 @@ int main(int argc, char *argv[]) * are quite common for x86, requires changing only max_mem (KVM allows * 32k memslots, 32k * 2gb == ~64tb of guest memory). */ - slot_size = 2 * size_1gb; + slot_size = SZ_2G; max_slots = kvm_check_cap(KVM_CAP_NR_MEMSLOTS); TEST_ASSERT(max_slots > first_slot, "KVM is broken"); /* All KVM MMUs should be able to survive a 128gb guest. */ - max_mem = 128 * size_1gb; + max_mem = 128ull * SZ_1G; calc_default_nr_vcpus(); @@ -197,11 +197,11 @@ int main(int argc, char *argv[]) TEST_ASSERT(nr_vcpus > 0, "number of vcpus must be >0"); break; case 'm': - max_mem = atoi_paranoid(optarg) * size_1gb; + max_mem = 1ull * atoi_paranoid(optarg) * SZ_1G; TEST_ASSERT(max_mem > 0, "memory size must be >0"); break; case 's': - slot_size = atoi_paranoid(optarg) * size_1gb; + slot_size = 1ull * atoi_paranoid(optarg) * SZ_1G; TEST_ASSERT(slot_size > 0, "slot size must be >0"); break; case 'H': @@ -245,7 +245,7 @@ int main(int argc, char *argv[]) #ifdef __x86_64__ /* Identity map memory in the guest using 1gb pages. */ - for (i = 0; i < slot_size; i += size_1gb) + for (i = 0; i < slot_size; i += SZ_1G) __virt_pg_map(vm, gpa + i, gpa + i, PG_LEVEL_1G); #else for (i = 0; i < slot_size; i += vm->page_size) @@ -260,7 +260,7 @@ int main(int argc, char *argv[]) vcpus = NULL; pr_info("Running with %lugb of guest memory and %u vCPUs\n", - (gpa - start_gpa) / size_1gb, nr_vcpus); + (gpa - start_gpa) / SZ_1G, nr_vcpus); rendezvous_with_vcpus(&time_start, "spawning"); rendezvous_with_vcpus(&time_run1, "run 1"); From patchwork Wed Nov 2 23:27:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 14564 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp208938wru; Wed, 2 Nov 2022 16:45:32 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7aOmW782w7zPwJoppuOw/N/1SPBM5iyi7LY5NQ+2V0xtVk+GLYjZ3UWbe6kpY//nLWjkPN X-Received: by 2002:a17:906:ee8e:b0:730:3646:d178 with SMTP id wt14-20020a170906ee8e00b007303646d178mr26802027ejb.426.1667432732112; Wed, 02 Nov 2022 16:45:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667432732; cv=none; d=google.com; s=arc-20160816; b=U1LiotKSmf3dZznScpSKSZj5rt0411I83S1PE5xFE24hmjd7ZPbdOffJOlrZ/KK+DP aZM8mUKwKnKbSBA3JtOBCK/R+eO+f591X6ctGkfsElf3xe6uwh6Hh8ruP0Kx9hA7Frz8 WE+DVHM5ge65t85MVo21xaayFTLwfDNsxWJ32bSbLV7oUBWfPDMxVCzvGwdfWumycRU9 j1xqvuFHKtGMdBXGI47+18wRN8KUYk7HJhskR08zvrjp1zYacioBeC5qvwK3aSthPvnk vbs/QDP6PDXqd+a50OebGREsoIViGlJ+7F/OAT1HGJWwscaWwa/VzFJgsLEK/a8PPJyV AmMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=47NN14tzjqb2Jkjp+DZD0PLnkTAdeUGBp2aNHGDmHKU=; b=LARG5yqIsTuj9VRoMwS+qp4+qi1hsFjacNjGhbJHxvMuT883c66TkiiEXtfTGYQXRA uzQ5VeOynbm0Hhgxlxl+YyTe3cl00nfws2ylLw1JZjMJ8jafSLw/l243hFaZVbwFUYNW 7cgs9vQ+8x2FEVepp4ceNmGX0rPB5QHhrRdY6eTTspaC8TB+ME1ETQgrbD3QPFWryyYZ 2XvbrPHS8ereVN3oR7m1ztXl8ScCO4zlKJK9UCaZFQSZCrv40isBde1DZ5hr7NmN2fmA FFGuGW6QRRuKGYqKOP6hV2Ho2g1Cfy73RCIvKhFjx8jkhzbfmfJaKt3PMBefQa84XBK6 Z7tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="iExh/fYc"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m17-20020a50c191000000b004597671e0ddsi14176913edf.338.2022.11.02.16.45.08; Wed, 02 Nov 2022 16:45:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="iExh/fYc"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229624AbiKBXhC (ORCPT + 99 others); Wed, 2 Nov 2022 19:37:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230381AbiKBXgf (ORCPT ); Wed, 2 Nov 2022 19:36:35 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDCD8D2FC for ; Wed, 2 Nov 2022 16:28:30 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id f126-20020a255184000000b006cb2aebd124so379259ybb.11 for ; Wed, 02 Nov 2022 16:28:30 -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=47NN14tzjqb2Jkjp+DZD0PLnkTAdeUGBp2aNHGDmHKU=; b=iExh/fYctDhDT2GR5L2oUQlwBYQkU8U79TQCr7U34lzJZ9FOj4LdJXlk6H96PeM/sy FDYviQAM8Aj4+GPwFBIfX4BIaZQrJxaEgoBet3kygw3fyE3sRYJah6Q+H1flApkDrtSj fmUQwcke74FTSEU5peoNjbJRdIF4gNe27CScm1SR50pWdAAJunYSaPN7lUxk+tkwruyi ZRMo4JarTk/lYV/tukRK3lXXnuEYcUW9AbkLvZLjxbfwMTBeLfacEh44NacfgfTG1HAf S3R4SEL1Cvmr9DjijMEj3K6K4Oa07mMxAIcj28VlWrkl1d8iW/YBgygbgZNAcnUn6ZZH 2XIw== 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=47NN14tzjqb2Jkjp+DZD0PLnkTAdeUGBp2aNHGDmHKU=; b=DkamjX8w/lDVL90lOcLuYAvV1Zh8xebnOapcU7sCIPqNymAoBup2n6bpI99lHSpCyj A+hzMvjlVenFY9UIw966p5Phz+pabmxf165L4Q3ec/RiDXYJ3iX/kNNm9L5p3otv+TxL sL6LGXg4MooKzParjUuHvo10ruNTYQTOZMozI29Bhn3ktCcL4yVMcwNc3xegm9NA61lp E/sPEc5mVLpaLDIcsqZWERgZICgE7eo9ZqN/9C173NItWV2FBnBAZM/oEjgoUXBt0t2G CJaVPf1CHPnpdlq2Lw1wvRRbvKbf6dSU+8yULpMblwbR4vzfeIhNfnKzPB+2xzGa+21X NwwQ== X-Gm-Message-State: ACrzQf1/nNAQ6n6EFpRIMgvyT0y6Ho3VB2Fqbj2XWrFdQNzf3lKrhAhz mXFUrpSgUfFTdQQhcXDuKSAVnCIMPpW3 X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a81:6083:0:b0:355:6608:2730 with SMTP id u125-20020a816083000000b0035566082730mr188700ywb.183.1667431669185; Wed, 02 Nov 2022 16:27:49 -0700 (PDT) Date: Wed, 2 Nov 2022 16:27:35 -0700 In-Reply-To: <20221102232737.1351745-1-vipinsh@google.com> Mime-Version: 1.0 References: <20221102232737.1351745-1-vipinsh@google.com> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog Message-ID: <20221102232737.1351745-6-vipinsh@google.com> Subject: [PATCH v8 5/7] KVM: selftests: Shorten the test args in memslot_modification_stress_test.c From: Vipin Sharma To: seanjc@google.com, pbonzini@redhat.com, dmatlack@google.com Cc: andrew.jones@linux.dev, wei.w.wang@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748429944489243172?= X-GMAIL-MSGID: =?utf-8?q?1748429944489243172?= Change test args memslot_modification_delay and nr_memslot_modifications to delay and nr_iterations for simplicity. Signed-off-by: Vipin Sharma Reviewed-by: Sean Christopherson --- .../kvm/memslot_modification_stress_test.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/kvm/memslot_modification_stress_test.c b/tools/testing/selftests/kvm/memslot_modification_stress_test.c index d7ddc8a105a2..d6089ccaa484 100644 --- a/tools/testing/selftests/kvm/memslot_modification_stress_test.c +++ b/tools/testing/selftests/kvm/memslot_modification_stress_test.c @@ -87,8 +87,8 @@ static void add_remove_memslot(struct kvm_vm *vm, useconds_t delay, } struct test_params { - useconds_t memslot_modification_delay; - uint64_t nr_memslot_modifications; + useconds_t delay; + uint64_t nr_iterations; bool partition_vcpu_memory_access; }; @@ -107,8 +107,8 @@ static void run_test(enum vm_guest_mode mode, void *arg) pr_info("Started all vCPUs\n"); - add_remove_memslot(vm, p->memslot_modification_delay, - p->nr_memslot_modifications); + add_remove_memslot(vm, p->delay, + p->nr_iterations); run_vcpus = false; @@ -144,8 +144,8 @@ int main(int argc, char *argv[]) int max_vcpus = kvm_check_cap(KVM_CAP_MAX_VCPUS); int opt; struct test_params p = { - .memslot_modification_delay = 0, - .nr_memslot_modifications = + .delay = 0, + .nr_iterations = DEFAULT_MEMSLOT_MODIFICATION_ITERATIONS, .partition_vcpu_memory_access = true }; @@ -158,8 +158,8 @@ int main(int argc, char *argv[]) guest_modes_cmdline(optarg); break; case 'd': - p.memslot_modification_delay = atoi_paranoid(optarg); - TEST_ASSERT(p.memslot_modification_delay >= 0, + p.delay = atoi_paranoid(optarg); + TEST_ASSERT(p.delay >= 0, "A negative delay is not supported."); break; case 'b': @@ -175,7 +175,7 @@ int main(int argc, char *argv[]) p.partition_vcpu_memory_access = false; break; case 'i': - p.nr_memslot_modifications = atoi_paranoid(optarg); + p.nr_iterations = atoi_paranoid(optarg); break; case 'h': default: From patchwork Wed Nov 2 23:27:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 14565 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp209066wru; Wed, 2 Nov 2022 16:45:50 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7Rzrh+Al9NwInoU7lDjfvHLix0Ccdtmapgk7yrANRpSNkQBV3ozGzcREA8K9AmCbBPOVGY X-Received: by 2002:a05:6402:d0b:b0:458:a244:4e99 with SMTP id eb11-20020a0564020d0b00b00458a2444e99mr27559190edb.46.1667432750802; Wed, 02 Nov 2022 16:45:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667432750; cv=none; d=google.com; s=arc-20160816; b=HHVPC4yb3o7MuBBS+hkuwR0X+IwXJQuIqxJIjMPEt7wsxjWiofq15VjxypCcJcwVDC k8hxAHnSUwlds3BIklL353hQLsynYUYkJ5J5ejtH5aXQKq+ZfXEqctq53d6zD3G8wgti pdrNbOyCQQEz/IMel1PjJFoFXheVvQx0EMpCxr7NI5P6GVwc/RblEouMi27AqZjLSiPB oU7eob8VaT4yaUdm2waFpAdTx1f0A3C2r4iQkhgaNJ0aucpNwHF7oehp7lw9hP3PKGX6 lz3udqKyPEtfDG0/2YTt6FVgYKhmBtrs64tPbZ3xboIg2icGVZIoI4RKPA6UqQNwR2OL GhFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=YSlDow+7EZhflX7A6xS0X+nlUfCZirAATNOrQV4nO0s=; b=aUwCP3dC1fsANmOx3Z34LeIkTr+s6XBqavcwPdoc3N4a4AfwccMcuuFMaXQ9F/JBGm +aDs7ttfawOxbdGthl2JS76maAp6uKtVTdeilAjDzGRa/9vRVQG3JqQofQZKlmo0V9NA AmuDuUYLErR6DUjrY7Z8fRB/LGiGOkTZbuSNGNMylQeFvU+71WDso3QSKaHa4Eog3E6u Oz90RDejbQEsSZHzvbX/7cdAbtFvXHk2qt4c5GZ2fCXDNOzTnhhHGSSMBAAvA0pY+DWM zrJphFp3qNDl+NfpWdjLCUqHQxNtxPFHFLsttk08/lxiU4Nmz3nuod6CqGijrmVL61zB qsKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=JFNJCykH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sc33-20020a1709078a2100b007adfc1544c9si6221570ejc.37.2022.11.02.16.45.27; Wed, 02 Nov 2022 16:45:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=JFNJCykH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230522AbiKBXhG (ORCPT + 99 others); Wed, 2 Nov 2022 19:37:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231579AbiKBXgh (ORCPT ); Wed, 2 Nov 2022 19:36:37 -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 55CD4D2D0 for ; Wed, 2 Nov 2022 16:28:34 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id h19-20020a63e153000000b00434dfee8dbaso90132pgk.18 for ; Wed, 02 Nov 2022 16:28:34 -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=YSlDow+7EZhflX7A6xS0X+nlUfCZirAATNOrQV4nO0s=; b=JFNJCykH8+RNLw543TI8bZ6ofHsspnc+Fdv9ZLTYDz17GaRAGP1/o+X0GA8k3GNHq9 r/mijOdpgdff3THh0upLfsqs2Du+hROZbWBaJ3sV+lU9KcJMkf6oNY88FfaoR+DWJksX L64LvNbC5Icp/YujlVqRSpQNai+ygqDuJg/BPIB7ASpmTbq2MC8lNLNbXGCOVIvTwzMc FRwPy463vKs9z/WCjUsdU3j/0iKzrZUoIce5+PtujJj5M+qBoklzN7DYExEzjWy7YTeK UiHQWjmydGNsEN7N1NeQDzT+10KMLOukQ0PQnedClfxj/dkrcoDFVadYGnf+p8ZMhuug BSig== 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=YSlDow+7EZhflX7A6xS0X+nlUfCZirAATNOrQV4nO0s=; b=DJmvLXukVs38VT2eEqnFoMaJk8FPjDeGCYDei0E8//4BTdQV8db7/tvDAfPu2miirG hY8Q2cde26+n7+c2tVVDNQmu16GH22jBuOFa6ZXduOiZLHOQu62hB3GvtxUzE+l4K3Fo frTHCXzrynpQU+tZFZIgVTMGjdW7D+YIyPbude77+xogU4uLa1kaqfu1emzitWSxt435 KTrnwA3190v3hkiWR2BZsiLgjdjEXVP8ieFPVGY67sn4ssoaOIzYlnuo1bz9JVmq02QQ qn+54ZBkabOoK2Tz0c9JRbG2E0dHBL3Y0JbfNDAEr20oadov6e4RhFG9vlHCwyz2mDKl bY0Q== X-Gm-Message-State: ACrzQf1q9DlBL/YELl+hE1oWkv0qinhfxQyCZy0P4zuQR5tIY2LkrsQ0 VIG220qko4eYpWQum0OHLIPBTwIBMjyR X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a17:90a:f291:b0:20a:eab5:cf39 with SMTP id fs17-20020a17090af29100b0020aeab5cf39mr152218pjb.1.1667431671109; Wed, 02 Nov 2022 16:27:51 -0700 (PDT) Date: Wed, 2 Nov 2022 16:27:36 -0700 In-Reply-To: <20221102232737.1351745-1-vipinsh@google.com> Mime-Version: 1.0 References: <20221102232737.1351745-1-vipinsh@google.com> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog Message-ID: <20221102232737.1351745-7-vipinsh@google.com> Subject: [PATCH v8 6/7] KVM: selftests: Add atoi_positive() and atoi_non_negative() for input validation From: Vipin Sharma To: seanjc@google.com, pbonzini@redhat.com, dmatlack@google.com Cc: andrew.jones@linux.dev, wei.w.wang@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748429964366003439?= X-GMAIL-MSGID: =?utf-8?q?1748429964366003439?= Many KVM selftests take command line arguments which are supposed to be positive (>0) or non-negative (>=0). Some tests do these validation and some missed adding the check. Add atoi_positive() and atoi_non_negative() to validate inputs in selftests before proceeding to use those values. Signed-off-by: Vipin Sharma Reviewed-by: Sean Christopherson --- .../selftests/kvm/aarch64/arch_timer.c | 25 ++++--------------- .../selftests/kvm/aarch64/debug-exceptions.c | 2 +- .../testing/selftests/kvm/aarch64/vgic_irq.c | 2 +- .../selftests/kvm/access_tracking_perf_test.c | 2 +- .../selftests/kvm/demand_paging_test.c | 4 +-- .../selftests/kvm/dirty_log_perf_test.c | 12 ++++----- .../testing/selftests/kvm/include/test_util.h | 16 ++++++++++++ .../selftests/kvm/kvm_page_table_test.c | 4 +-- .../selftests/kvm/max_guest_memory_test.c | 9 +++---- .../kvm/memslot_modification_stress_test.c | 10 +++----- .../testing/selftests/kvm/memslot_perf_test.c | 22 ++++------------ .../selftests/kvm/set_memory_region_test.c | 2 +- .../selftests/kvm/x86_64/nx_huge_pages_test.c | 3 +-- 13 files changed, 47 insertions(+), 66 deletions(-) diff --git a/tools/testing/selftests/kvm/aarch64/arch_timer.c b/tools/testing/selftests/kvm/aarch64/arch_timer.c index 251e7ff04883..9409617fce9c 100644 --- a/tools/testing/selftests/kvm/aarch64/arch_timer.c +++ b/tools/testing/selftests/kvm/aarch64/arch_timer.c @@ -414,36 +414,21 @@ 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_paranoid(optarg); - if (test_args.nr_vcpus <= 0) { - pr_info("Positive value needed for -n\n"); - goto err; - } else if (test_args.nr_vcpus > KVM_MAX_VCPUS) { + test_args.nr_vcpus = atoi_positive("Number of vCPUs", optarg); + if (test_args.nr_vcpus > KVM_MAX_VCPUS) { pr_info("Max allowed vCPUs: %u\n", KVM_MAX_VCPUS); goto err; } break; case 'i': - test_args.nr_iter = atoi_paranoid(optarg); - if (test_args.nr_iter <= 0) { - pr_info("Positive value needed for -i\n"); - goto err; - } + test_args.nr_iter = atoi_positive("Number of iterations", optarg); break; case 'p': - 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; - } + test_args.timer_period_ms = atoi_positive("Periodicity", optarg); break; case 'm': - 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; - } + test_args.migration_freq_ms = atoi_non_negative("Frequency", optarg); break; case 'h': default: diff --git a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c index 19fffdf19c9f..878c334607e1 100644 --- a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c +++ b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c @@ -423,7 +423,7 @@ int main(int argc, char *argv[]) while ((opt = getopt(argc, argv, "i:")) != -1) { switch (opt) { case 'i': - ss_iteration = atoi_paranoid(optarg); + ss_iteration = atoi_positive("Number of iterations", optarg); break; case 'h': default: diff --git a/tools/testing/selftests/kvm/aarch64/vgic_irq.c b/tools/testing/selftests/kvm/aarch64/vgic_irq.c index ae90b718070a..4ead42a072b7 100644 --- a/tools/testing/selftests/kvm/aarch64/vgic_irq.c +++ b/tools/testing/selftests/kvm/aarch64/vgic_irq.c @@ -824,7 +824,7 @@ int main(int argc, char **argv) while ((opt = getopt(argc, argv, "hn:e:l:")) != -1) { switch (opt) { case 'n': - nr_irqs = atoi_paranoid(optarg); + nr_irqs = atoi_non_negative("Number of IRQs", optarg); if (nr_irqs > 1024 || nr_irqs % 32) help(argv[0]); break; diff --git a/tools/testing/selftests/kvm/access_tracking_perf_test.c b/tools/testing/selftests/kvm/access_tracking_perf_test.c index c6bcc5301e2c..a81e7a7ae18f 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 = parse_size(optarg); break; case 'v': - params.nr_vcpus = atoi_paranoid(optarg); + params.nr_vcpus = atoi_positive("Number of vCPUs", 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 82597fb04146..0c98181fa248 100644 --- a/tools/testing/selftests/kvm/demand_paging_test.c +++ b/tools/testing/selftests/kvm/demand_paging_test.c @@ -427,8 +427,8 @@ int main(int argc, char *argv[]) p.src_type = parse_backing_src_type(optarg); break; case 'v': - nr_vcpus = atoi_paranoid(optarg); - TEST_ASSERT(nr_vcpus > 0 && nr_vcpus <= max_vcpus, + nr_vcpus = atoi_positive("Number of vCPUs", optarg); + TEST_ASSERT(nr_vcpus <= max_vcpus, "Invalid number of vcpus, must be between 1 and %d", max_vcpus); break; case 'o': diff --git a/tools/testing/selftests/kvm/dirty_log_perf_test.c b/tools/testing/selftests/kvm/dirty_log_perf_test.c index ecda802b78ff..4d639683b8ef 100644 --- a/tools/testing/selftests/kvm/dirty_log_perf_test.c +++ b/tools/testing/selftests/kvm/dirty_log_perf_test.c @@ -416,9 +416,7 @@ int main(int argc, char *argv[]) run_vcpus_while_disabling_dirty_logging = true; break; case 'f': - p.wr_fract = atoi_paranoid(optarg); - TEST_ASSERT(p.wr_fract >= 1, - "Write fraction cannot be less than one"); + p.wr_fract = atoi_positive("Write fraction", optarg); break; case 'g': dirty_log_manual_caps = 0; @@ -427,7 +425,7 @@ int main(int argc, char *argv[]) help(argv[0]); break; case 'i': - p.iterations = atoi_paranoid(optarg); + p.iterations = atoi_positive("Number of iterations", optarg); break; case 'm': guest_modes_cmdline(optarg); @@ -445,12 +443,12 @@ int main(int argc, char *argv[]) p.backing_src = parse_backing_src_type(optarg); break; case 'v': - nr_vcpus = atoi_paranoid(optarg); - TEST_ASSERT(nr_vcpus > 0 && nr_vcpus <= max_vcpus, + nr_vcpus = atoi_positive("Number of vCPUs", optarg); + TEST_ASSERT(nr_vcpus <= max_vcpus, "Invalid number of vcpus, must be between 1 and %d", max_vcpus); break; case 'x': - p.slots = atoi_paranoid(optarg); + p.slots = atoi_positive("Number of slots", 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 feae42863759..3be98e81189a 100644 --- a/tools/testing/selftests/kvm/include/test_util.h +++ b/tools/testing/selftests/kvm/include/test_util.h @@ -154,4 +154,20 @@ static inline void *align_ptr_up(void *x, size_t size) int atoi_paranoid(const char *num_str); +static inline uint32_t atoi_positive(const char *name, const char *num_str) +{ + int num = atoi_paranoid(num_str); + + TEST_ASSERT(num > 0, "%s must be greater than 0, got '%s'", name, num_str); + return num; +} + +static inline uint32_t atoi_non_negative(const char *name, const char *num_str) +{ + int num = atoi_paranoid(num_str); + + TEST_ASSERT(num >= 0, "%s must be non-negative, got '%s'", name, num_str); + return num; +} + #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 ea7feb69bb88..696b366be06b 100644 --- a/tools/testing/selftests/kvm/kvm_page_table_test.c +++ b/tools/testing/selftests/kvm/kvm_page_table_test.c @@ -461,8 +461,8 @@ int main(int argc, char *argv[]) p.test_mem_size = parse_size(optarg); break; case 'v': - nr_vcpus = atoi_paranoid(optarg); - TEST_ASSERT(nr_vcpus > 0 && nr_vcpus <= max_vcpus, + nr_vcpus = atoi_positive("Number of vCPUs", optarg); + TEST_ASSERT(nr_vcpus <= max_vcpus, "Invalid number of vcpus, must be between 1 and %d", max_vcpus); break; case 's': diff --git a/tools/testing/selftests/kvm/max_guest_memory_test.c b/tools/testing/selftests/kvm/max_guest_memory_test.c index 8056dc5831b5..feaf2be20ff2 100644 --- a/tools/testing/selftests/kvm/max_guest_memory_test.c +++ b/tools/testing/selftests/kvm/max_guest_memory_test.c @@ -193,16 +193,13 @@ int main(int argc, char *argv[]) while ((opt = getopt(argc, argv, "c:h:m:s:H")) != -1) { switch (opt) { case 'c': - nr_vcpus = atoi_paranoid(optarg); - TEST_ASSERT(nr_vcpus > 0, "number of vcpus must be >0"); + nr_vcpus = atoi_positive("Number of vCPUs", optarg); break; case 'm': - max_mem = 1ull * atoi_paranoid(optarg) * SZ_1G; - TEST_ASSERT(max_mem > 0, "memory size must be >0"); + max_mem = 1ull * atoi_positive("Memory size", optarg) * SZ_1G; break; case 's': - slot_size = 1ull * atoi_paranoid(optarg) * SZ_1G; - TEST_ASSERT(slot_size > 0, "slot size must be >0"); + slot_size = 1ull * atoi_positive("Slot size", optarg) * SZ_1G; break; case 'H': hugepages = true; diff --git a/tools/testing/selftests/kvm/memslot_modification_stress_test.c b/tools/testing/selftests/kvm/memslot_modification_stress_test.c index d6089ccaa484..c3b7c94aec8f 100644 --- a/tools/testing/selftests/kvm/memslot_modification_stress_test.c +++ b/tools/testing/selftests/kvm/memslot_modification_stress_test.c @@ -158,16 +158,14 @@ int main(int argc, char *argv[]) guest_modes_cmdline(optarg); break; case 'd': - p.delay = atoi_paranoid(optarg); - TEST_ASSERT(p.delay >= 0, - "A negative delay is not supported."); + p.delay = atoi_non_negative("Delay", optarg); break; case 'b': guest_percpu_mem_size = parse_size(optarg); break; case 'v': - nr_vcpus = atoi_paranoid(optarg); - TEST_ASSERT(nr_vcpus > 0 && nr_vcpus <= max_vcpus, + nr_vcpus = atoi_positive("Number of vCPUs", optarg); + TEST_ASSERT(nr_vcpus <= max_vcpus, "Invalid number of vcpus, must be between 1 and %d", max_vcpus); break; @@ -175,7 +173,7 @@ int main(int argc, char *argv[]) p.partition_vcpu_memory_access = false; break; case 'i': - p.nr_iterations = atoi_paranoid(optarg); + p.nr_iterations = atoi_positive("Number of iterations", 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 4bae9e3f5ca1..330aaef1c02f 100644 --- a/tools/testing/selftests/kvm/memslot_perf_test.c +++ b/tools/testing/selftests/kvm/memslot_perf_test.c @@ -892,33 +892,21 @@ static bool parse_args(int argc, char *argv[], } break; case 'f': - targs->tfirst = atoi_paranoid(optarg); - if (targs->tfirst < 0) { - pr_info("First test to run has to be non-negative\n"); - return false; - } + targs->tfirst = atoi_non_negative("First test", optarg); break; case 'e': - targs->tlast = atoi_paranoid(optarg); - if (targs->tlast < 0 || targs->tlast >= NTESTS) { + targs->tlast = atoi_non_negative("Last test", optarg); + if (targs->tlast >= NTESTS) { pr_info("Last test to run has to be non-negative and less than %zu\n", NTESTS); return false; } break; case 'l': - targs->seconds = atoi_paranoid(optarg); - if (targs->seconds < 0) { - pr_info("Test length in seconds has to be non-negative\n"); - return false; - } + targs->seconds = atoi_non_negative("Test length", optarg); break; case 'r': - targs->runs = atoi_paranoid(optarg); - if (targs->runs <= 0) { - pr_info("Runs per test has to be positive\n"); - return false; - } + targs->runs = atoi_positive("Runs per test", optarg); break; } } diff --git a/tools/testing/selftests/kvm/set_memory_region_test.c b/tools/testing/selftests/kvm/set_memory_region_test.c index c366949c8362..85c16f09a50e 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_paranoid(argv[1]); + loops = atoi_positive("Number of iterations", 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 354b6902849c..ea0978f22db8 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,7 +241,7 @@ int main(int argc, char **argv) while ((opt = getopt(argc, argv, "hp:t:r")) != -1) { switch (opt) { case 'p': - reclaim_period_ms = atoi_paranoid(optarg); + reclaim_period_ms = atoi_non_negative("Reclaim period", optarg); break; case 't': token = atoi_paranoid(optarg); @@ -257,7 +257,6 @@ int main(int argc, char **argv) } TEST_REQUIRE(kvm_has_cap(KVM_CAP_VM_DISABLE_NX_HUGE_PAGES)); - TEST_REQUIRE(reclaim_period_ms > 0); __TEST_REQUIRE(token == MAGIC_TOKEN, "This test must be run with the magic token %d.\n" From patchwork Wed Nov 2 23:27:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 14568 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp209222wru; Wed, 2 Nov 2022 16:46:14 -0700 (PDT) X-Google-Smtp-Source: AMsMyM452tZEbuY9oe5KUW1XlnKYxImc3NfyHtwUaf4tokTg1WgPDUzKpjVf1aCWl28L62/Wp9wU X-Received: by 2002:a05:6402:2681:b0:461:cbda:fe4b with SMTP id w1-20020a056402268100b00461cbdafe4bmr27635945edd.124.1667432774303; Wed, 02 Nov 2022 16:46:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667432774; cv=none; d=google.com; s=arc-20160816; b=gVJWYrRJWLQo37jCOH3OVUzXab/hRRBmzZxwJ6yHU5HbxwziJPA++IE+Qn9IVCsdnd rP3KIH8vKR5Yn3WlFSnWVRM6rfkYzZdmytmk6CQotq2cy/xBWlnDrUwxPXovNL9LbgT9 YAwXl+m+fPhwBR2Uszp4G8UOLY6dT6tyP1IZufWSfyb+vuWnZ+24qDMQQ5KEFVD1WIhZ tiuNzykr498LlXmrs8klBfWrA6ddEWgq1PGwiV8qYngAwrHxFYpdSsTVu2+Dsabf06eG 7FFE/rH5jloQ+ZmYMu1HVnzhEK0DKYCLbtPvyP3ttDYw3p5c6CyfEjB7dY3JSS+9mPf+ LsGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=VE7RW56VayO0keHNnwyMULSgmJMIPboymyf3dnMpIn8=; b=VKqRKH3QpIhPqDpprhXXjHRCqQw0Jhwn3a4T4x2mJdajyAJQp/l6WFisIK68BLBRcj TTco39VT+hsNt85N2EGV2V6UlQofsTHvoOuIsBrWPTTb+HQXm75UltYnG0922Baymz3k j07PAJznE+hl2KQhsjla/K9Jc4CN/95Gu+XAoRu5Y3KGVkbd7R1dBOdq3an3zgGSF9Eo ONt3odAETPWqbv6SSxbniRWoG0SIoiX6Y0NB+ZtCXrlrUumazl/6VMQRACsO0u9aI6CH 30y1DQiAsy1eV8VzbU9X4rCA4ofFfjjhfoflhJpwNdeNK0AEbOeNkgIdOL+/sbg0PfdQ VhtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=oBt2cyAG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gz25-20020a170907a05900b0078dcdb1c9dfsi15325945ejc.553.2022.11.02.16.45.46; Wed, 02 Nov 2022 16:46:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=oBt2cyAG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231580AbiKBXi1 (ORCPT + 99 others); Wed, 2 Nov 2022 19:38:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231492AbiKBXiJ (ORCPT ); Wed, 2 Nov 2022 19:38:09 -0400 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EDBB6547 for ; Wed, 2 Nov 2022 16:29:26 -0700 (PDT) Received: by mail-pl1-f202.google.com with SMTP id d18-20020a170902ced200b001871dab2d59so212561plg.22 for ; Wed, 02 Nov 2022 16:29:26 -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=VE7RW56VayO0keHNnwyMULSgmJMIPboymyf3dnMpIn8=; b=oBt2cyAGroEh99N7q1oP3Lyx5ZZvCvEPDzBzn78SuT6gpHQOdml/zL+SEucIpnDKoS WT817zq7BrvRmiT0Tzwi1T5i46v8sxV23v2bTDIit+liSAF+p3bHNnsu8SNfwZ1ci9nC t2hkz4czIuws/OduRXDygRCG4HMf/wggs8mPZlGMDM5sBngQIDfWvjioGbj83A28k2zU jppfE0GmOOBeQoj+x9Z243mGLCT8kszHSl5JI3+VYSrcrf8UrXtQ5zGG7TWz70PZ2BTq 89mAqbXzJw8fx8kGYGaOvZYLPOExzM+zz+C07bGGgHo6LLisS13+Ih/HEHOjeFx/J52z CPjw== 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=VE7RW56VayO0keHNnwyMULSgmJMIPboymyf3dnMpIn8=; b=MUNw57ew/pSZMTQSxYRv6fj02yMZm4Xrxz/fjWNqkz7yvqXBrGDlCiGCaAgzmm6hos 0SHDL2sIVVrplw0VcI5UXTDL/tH/6/yIVXn/c2r0gz8H6yoiMkzVYeB7So4FVc/zmsD4 plRpx5GUZar1uHVz1bXZgpCnMTW7SaQ2rsdHVSqYrf5nMc4y631NB7bLuSeZnFo0rbyo hgFu2b3Y/DoteVpeMrxJab6voPgUh9/Ad0k6iw5DCj1fubNF6bExw1hiAoICjbRDZNwB 9Nd5qpJGMW9o1jvun9ZhL7ECheNI1kjcvwi5rx6nh7I00Id7AAEf9wvgkXQ9NPAensxY 7RPQ== X-Gm-Message-State: ACrzQf2Afc10R3E22xSfWVudG5QhUrJ3347LpAjnqZSaPDeQoVcLC32v zFuKnluECTYji+zEY9VmcmPOlyAAP/bi X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a17:902:7c11:b0:178:a6ca:4850 with SMTP id x17-20020a1709027c1100b00178a6ca4850mr28014929pll.111.1667431673111; Wed, 02 Nov 2022 16:27:53 -0700 (PDT) Date: Wed, 2 Nov 2022 16:27:37 -0700 In-Reply-To: <20221102232737.1351745-1-vipinsh@google.com> Mime-Version: 1.0 References: <20221102232737.1351745-1-vipinsh@google.com> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog Message-ID: <20221102232737.1351745-8-vipinsh@google.com> Subject: [PATCH v8 7/7] KVM: selftests: Allowing running 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, wei.w.wang@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748429988923170455?= X-GMAIL-MSGID: =?utf-8?q?1748429988923170455?= Add a command line option, -c, to pin vCPUs to physical CPUs (pCPUs), i.e. to force vCPUs to run on specific pCPUs. Requirement to implement this feature came in discussion on the patch "Make page tables for eager page splitting NUMA aware" https://lore.kernel.org/lkml/YuhPT2drgqL+osLl@google.com/ This feature 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. To keep things simple, implementation is intentionally very limited, either all of the vCPUs will be pinned followed by an optional main thread or nothing will be pinned. Signed-off-by: Vipin Sharma Suggested-by: David Matlack Reviewed-by: Sean Christopherson --- .../selftests/kvm/dirty_log_perf_test.c | 25 ++++++++- .../selftests/kvm/include/kvm_util_base.h | 4 ++ .../selftests/kvm/include/perf_test_util.h | 4 ++ tools/testing/selftests/kvm/lib/kvm_util.c | 54 +++++++++++++++++++ .../selftests/kvm/lib/perf_test_util.c | 8 ++- 5 files changed, 92 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 4d639683b8ef..0612158329aa 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,17 @@ 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: Pin tasks to physical CPUs. Takes a list of comma separated\n" + " values (target pCPU), one for each vCPU, plus an optional\n" + " entry for the main application task (specified via entry\n" + " ). If used, entries must be provided for all\n" + " vCPUs, i.e. pinning vCPUs is all or nothing.\n\n" + " E.g. to create 3 vCPUs, pin vCPU0=>pCPU22, vCPU1=>pCPU23,\n" + " vCPU2=>pCPU24, and pin the application task to pCPU50:\n\n" + " ./dirty_log_perf_test -v 3 -c 22,23,24,50\n\n" + " To leave the application task unpinned, drop the final entry:\n\n" + " ./dirty_log_perf_test -v 3 -c 22,23,24\n\n" + " (default: no pinning)\n"); puts(""); exit(0); } @@ -390,6 +401,7 @@ static void help(char *name) int main(int argc, char *argv[]) { int max_vcpus = kvm_check_cap(KVM_CAP_MAX_VCPUS); + const char *pcpu_list = NULL; struct test_params p = { .iterations = TEST_HOST_LOOP_N, .wr_fract = 1, @@ -406,11 +418,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; @@ -456,6 +471,12 @@ int main(int argc, char *argv[]) } } + if (pcpu_list) { + kvm_parse_vcpu_pinning(pcpu_list, perf_test_args.vcpu_to_pcpu, + nr_vcpus); + perf_test_args.pin_vcpus = true; + } + 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/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h index e42a09cd24a0..3bf2333ef95d 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -688,6 +688,10 @@ static inline struct kvm_vm *vm_create_with_one_vcpu(struct kvm_vcpu **vcpu, struct kvm_vcpu *vm_recreate_with_one_vcpu(struct kvm_vm *vm); +void kvm_pin_this_task_to_pcpu(uint32_t pcpu); +void kvm_parse_vcpu_pinning(const char *pcpus_string, uint32_t vcpu_to_pcpu[], + int nr_vcpus); + unsigned long vm_compute_max_gfn(struct kvm_vm *vm); unsigned int vm_calc_num_guest_pages(enum vm_guest_mode mode, size_t size); unsigned int vm_num_host_pages(enum vm_guest_mode mode, unsigned int num_guest_pages); diff --git a/tools/testing/selftests/kvm/include/perf_test_util.h b/tools/testing/selftests/kvm/include/perf_test_util.h index eaa88df0555a..849c875dd0ff 100644 --- a/tools/testing/selftests/kvm/include/perf_test_util.h +++ b/tools/testing/selftests/kvm/include/perf_test_util.h @@ -39,6 +39,10 @@ struct perf_test_args { /* 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; + /* The vCPU=>pCPU pinning map. Only valid if pin_vcpus is true. */ + uint32_t vcpu_to_pcpu[KVM_MAX_VCPUS]; struct perf_test_vcpu_args vcpu_args[KVM_MAX_VCPUS]; }; diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index f1cb1627161f..3b7710fb3784 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -11,6 +11,7 @@ #include "processor.h" #include +#include #include #include #include @@ -443,6 +444,59 @@ struct kvm_vcpu *vm_recreate_with_one_vcpu(struct kvm_vm *vm) return vm_vcpu_recreate(vm, 0); } +void kvm_pin_this_task_to_pcpu(uint32_t pcpu) +{ + cpu_set_t mask; + int r; + + CPU_ZERO(&mask); + CPU_SET(pcpu, &mask); + r = sched_setaffinity(0, sizeof(mask), &mask); + TEST_ASSERT(!r, "sched_setaffinity() failed for pCPU '%u'.\n", pcpu); +} + +static uint32_t parse_pcpu(const char *cpu_str, const cpu_set_t *allowed_mask) +{ + uint32_t pcpu = atoi_non_negative("CPU number", cpu_str); + + TEST_ASSERT(CPU_ISSET(pcpu, allowed_mask), + "Not allowed to run on pCPU '%d', check cgroups?\n", pcpu); + return pcpu; +} + +void kvm_parse_vcpu_pinning(const char *pcpus_string, uint32_t vcpu_to_pcpu[], + int nr_vcpus) +{ + cpu_set_t allowed_mask; + char *cpu, *cpu_list; + char delim[2] = ","; + int i, r; + + cpu_list = strdup(pcpus_string); + TEST_ASSERT(cpu_list, "strdup() allocation failed.\n"); + + r = sched_getaffinity(0, sizeof(allowed_mask), &allowed_mask); + TEST_ASSERT(!r, "sched_getaffinity() failed"); + + cpu = strtok(cpu_list, delim); + + /* 1. Get all pcpus for vcpus. */ + for (i = 0; i < nr_vcpus; i++) { + TEST_ASSERT(cpu, "pCPU not provided for vCPU '%d'\n", i); + vcpu_to_pcpu[i] = parse_pcpu(cpu, &allowed_mask); + cpu = strtok(NULL, delim); + } + + /* 2. Check if the main worker needs to be pinned. */ + if (cpu) { + kvm_pin_this_task_to_pcpu(parse_pcpu(cpu, &allowed_mask)); + cpu = strtok(NULL, delim); + } + + TEST_ASSERT(!cpu, "pCPU list contains trailing garbage characters '%s'", cpu); + free(cpu_list); +} + /* * Userspace Memory Region Find * diff --git a/tools/testing/selftests/kvm/lib/perf_test_util.c b/tools/testing/selftests/kvm/lib/perf_test_util.c index 9618b37c66f7..3a1d0a44419b 100644 --- a/tools/testing/selftests/kvm/lib/perf_test_util.c +++ b/tools/testing/selftests/kvm/lib/perf_test_util.c @@ -2,6 +2,8 @@ /* * Copyright (C) 2020, Google LLC. */ +#define _GNU_SOURCE + #include #include "kvm_util.h" @@ -243,6 +245,10 @@ void __weak perf_test_setup_nested(struct kvm_vm *vm, int nr_vcpus, struct kvm_v static void *vcpu_thread_main(void *data) { struct vcpu_thread *vcpu = data; + int vcpu_idx = vcpu->vcpu_idx; + + if (perf_test_args.pin_vcpus) + kvm_pin_this_task_to_pcpu(perf_test_args.vcpu_to_pcpu[vcpu_idx]); WRITE_ONCE(vcpu->running, true); @@ -255,7 +261,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(&perf_test_args.vcpu_args[vcpu_idx]); return NULL; }