From nobody Tue Apr 7 03:31:29 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8C8FC4332F for ; Fri, 14 Oct 2022 15:12:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229982AbiJNPMa (ORCPT ); Fri, 14 Oct 2022 11:12:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229588AbiJNPM0 (ORCPT ); Fri, 14 Oct 2022 11:12:26 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63A8E1D20F3; Fri, 14 Oct 2022 08:12:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1665760345; x=1697296345; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=wIgkzDcxMApiitRClzqeNFxb5pcHdUGeIGTQZ+gTGGo=; b=FblL97pGXOA0erswCZvYnpD0/GZcuDhrHIVTfzSU6jjWf0DjUEkFu53G 5eTgyYCHUVtYecyZYtWPLsXvo+CTLxL1JvKTBSuJgzN5wyj7KvghIdR4K lpzpET0UU+R++Hz24wBhgRKOm/PTYrwNfsyy4Vz9h9dr9dIcF9JDkjFM+ WwhAVod7dWe4Qo3kqZVXi/pGmUeUXuE7J26/U22UKq1pHASagLlJ9z/N2 CEah2R1Ocx3zX/kZKj8DHZBFRRpijhVTPy8zDoS1cBeFvaEc7dkJL3HAu JfzRkFaZ4PlksyDC4g5OKykDa/eVtoJLT9xMD167ghYIpii0BFwPYN85d w==; X-IronPort-AV: E=McAfee;i="6500,9779,10500"; a="305386836" X-IronPort-AV: E=Sophos;i="5.95,184,1661842800"; d="scan'208";a="305386836" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Oct 2022 08:12:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10500"; a="660759000" X-IronPort-AV: E=Sophos;i="5.95,184,1661842800"; d="scan'208";a="660759000" Received: from fmsmsx603.amr.corp.intel.com ([10.18.126.83]) by orsmga001.jf.intel.com with ESMTP; 14 Oct 2022 08:12:24 -0700 Received: from fmsmsx607.amr.corp.intel.com (10.18.126.87) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 14 Oct 2022 08:12:24 -0700 Received: from fmsmsx609.amr.corp.intel.com (10.18.126.89) by fmsmsx607.amr.corp.intel.com (10.18.126.87) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 14 Oct 2022 08:12:23 -0700 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx609.amr.corp.intel.com (10.18.126.89) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31 via Frontend Transport; Fri, 14 Oct 2022 08:12:23 -0700 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (104.47.59.170) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2375.31; Fri, 14 Oct 2022 08:12:22 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oG00l5Cc+7aNa60++jh3/+mhuXj8SnD16G+VaFI47HCNy2KvMpQE8ctCTRpPmLHIXH7am9HYZ5hzRpBQKhsUbdCdEnjoUDibyPiE80eF29gO3mMng47hoFAdxC+C3/nCtGRj9PRnLrdfaBj/Rxd8hMWDB6HjDtN1f1T1q37ttTvZHejRyBq1bo0fVnGE3XPtTodzP2/+ubKp7+JMZrwZafmq7PkJLnpCfRZlwk2cpIfcPR9hxM3I3I1ZYNljVJHOfb/OJPBfjnoOZnSwWPjbf5aaHznUGb6o7lJncExm+KViVHRoiGJXfr1xOioaFcHkSQSkLFpP3feGWAdIQjL3Xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=wIgkzDcxMApiitRClzqeNFxb5pcHdUGeIGTQZ+gTGGo=; b=jEzdQw+8DDSVTZO9XkJxM9Nze3sCDGRbrisPIoliapet0poeLEEdv+ImmJhiHiK2MHa2MKgSYBkU9Qzv4wTkk8mVW456eMPHQ3kSyUq69SdHrHVOUY/JhPv/WvNR0SBsy7Bfwq5rciCdPmsCyMB5rCN+almJWpJ98ODozyKw7KyIYlJkxmUgyBCrMZeF9PH7TlzExEV0/NWZjTUwnlIEa3ehPKecUnvNw9NSp0CKHcnKhI6bc9aD17h7hocLxYduIniYhXY+iRbVY1kF4vkyihhZC1kXd6BcgiQT0SA9BMfjD2aOHw3YocrdFZpbUp24NsBHsvPwbf/vM0WYhzYTIA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from DS0PR11MB6373.namprd11.prod.outlook.com (2603:10b6:8:cb::20) by SA1PR11MB7110.namprd11.prod.outlook.com (2603:10b6:806:2b3::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5709.15; Fri, 14 Oct 2022 15:12:21 +0000 Received: from DS0PR11MB6373.namprd11.prod.outlook.com ([fe80::4625:d63e:1152:1246]) by DS0PR11MB6373.namprd11.prod.outlook.com ([fe80::4625:d63e:1152:1246%5]) with mapi id 15.20.5676.041; Fri, 14 Oct 2022 15:12:20 +0000 From: "Wang, Wei W" To: Vipin Sharma , "Christopherson,, Sean" , "pbonzini@redhat.com" , "dmatlack@google.com" CC: "andrew.jones@linux.dev" , "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH v5 0/5] dirty_log_perf_test vCPU pinning Thread-Topic: [PATCH v5 0/5] dirty_log_perf_test vCPU pinning Thread-Index: AQHY3PSo5mk7BJgdskG84RjiFjmwJa4N+zRA Date: Fri, 14 Oct 2022 15:12:20 +0000 Message-ID: References: <20221010220538.1154054-1-vipinsh@google.com> In-Reply-To: <20221010220538.1154054-1-vipinsh@google.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.6.500.17 authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: DS0PR11MB6373:EE_|SA1PR11MB7110:EE_ x-ms-office365-filtering-correlation-id: 91493ec6-f388-4bc9-0883-08daadf67d9d x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: dGaX9BIzqa8O4uZL/vvDlr0rB35j063Q+hx6udMkW07rTiKdLPcz4VZlOZgduZVgcjrss2CAVdaSd+ATAtVE046ba4xvGtNw2ENN39PeX27FsNXDEI7sc+978Pt7z6MBlq3BTijxQsXd+6utrW3wf5uWO2CtSWoydhlDgVPU6jG8eBmsenJBTWKA/ndoz/w7QNe2Zpar029qH13IbooKZFTz+zwPNWdYX8L0aK3tHuqL82hApesMbz1PBRqOkeWhv2nTfP6CbM5oPeBdlf0qXSVPg2nStij7oOn4eOzcxFoxfcGOJKWAykyNRM2lkiUXbHU6j3vleSmE4purkann9GEDBEa2bgC2mieRpufixE8iVketeyuPNMHSJrruL1vnVxzNAvOGL4KZvsyPTvXf4NPzwjC9oLDHIYWr8S+3MkHxQBQLXN2Cr6JIBAFZwwGRHgaCUFhqzymXBLri2PEFAY+BvzWPeY5CP6iVsT2AGGv9sschXKYbTqXUIid95BNiY4VIhw+rX04gs/G/HkyB7DeFfOittMW1k+ydWb9cJVZUESWt/r6LluWRODULlMiwQ1WaiMuIl1Zv7gwDSBSPg24Y5eAheKtuyFMHVSHRltu7NCwFprraQb9ddmsUSxHOPP2XmSbjBsiVNF5KYaBQn6b1JatVg6P95pH3987cwhcstSRPMQleTWURKa13IS+pF6OrxEZrAah5LOE2TptLWZZKgM16fXx95FPPrFFXy3/janMb8Gw6Yv1dhRUzlkKzWAwIkUcRUVhtjSMPhUkk9cxW/NkAxqzRkVp/cdYkfuU= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS0PR11MB6373.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(136003)(366004)(376002)(39860400002)(346002)(396003)(451199015)(5660300002)(41300700001)(55016003)(2906002)(86362001)(478600001)(33656002)(110136005)(316002)(76116006)(7696005)(6506007)(66446008)(8676002)(66556008)(52536014)(8936002)(53546011)(186003)(4326008)(64756008)(66946007)(38070700005)(122000001)(9686003)(82960400001)(66476007)(54906003)(26005)(38100700002)(71200400001)(14143004);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?B?ODQ3TXJKQXhsNVdPNzRCK3FoWXl4YTlyUVdTQ2MrNTAxdzlyRlNaUVpFajdQ?= =?utf-8?B?dlFHL2lUSmg2WHhNOTJ5YUhIcGVPckR4ajRMSVJTbWh4VjVFOThzOVo1U1ds?= =?utf-8?B?RVJQS3J1Nkdkc2ZYOG5ZUUlaUDJDZmIzZFVnSHQyNDJIcE9icHlhQjNHdHYw?= =?utf-8?B?Zmt2MDBuRkFoLytQUVFYNTY0OGZ6QitTK1BJdWlTS2RoY3duVXFoUDd4elZI?= =?utf-8?B?Q2MrR05wdFZqOTFUekZNNGk4SEVyYnllb1dvV2xBb1hFcFVydHBxMGdWSDA3?= =?utf-8?B?eXplblA0WUY4eThZeGhua0cxTDFQbjNZTUZFaVdRWHpWektmdEJVRVlHNzgv?= =?utf-8?B?L3prOVVlNm5Sa1BKaGFKV0dNRWJoSFl2ZSt1K0R6TjVCRmoyRFoyUUJ1Z05h?= =?utf-8?B?Y1pxcXpYQ3MxUU82TzVpQXdoYW1IMUJwSDh6TndrWmtnbTZ2T2ZrME80OWpp?= =?utf-8?B?RkRBOHg4YWt6REFzTlg5Z0pSbHFlNm16SGVoRW9yY0RpL3VZbklYTmZUMitu?= =?utf-8?B?S0RDYWlNY3FwUVNNMnhycGdpUmNPdWtRT01VQkFYbklmS2VnMC82QktpMHFp?= =?utf-8?B?b2dpVFZtRnUwb1Z5U0lCQ0MrRVJ2RnNhQU80YkVDbHBuSXF6eVR0aDZzeG9u?= =?utf-8?B?VkZhTWlLNHh2YkZiVXVwVmNiNER6QSt1WnlWbEwwcFliUCttdjNPUmovKy9s?= =?utf-8?B?cmFPRnU0bSt3b2FOc093VmFnYTUwZ3o5aDdlenRydENKSytqQzc5YlFyTUVk?= =?utf-8?B?TDJUdXFGbzNMemJpNjNhcDEyNVlnWXZndGlvNTJTaW94YzFiUW5pdUQxN1ZO?= =?utf-8?B?eGpONEhyTktPN3FVYnplT2x4eHpDYWo4MXlJaU04YmpzWlQrcXFFRXR2cmpz?= =?utf-8?B?anBPYm9odDJPVy9WZ0lkblVNZHI5R0xqTStsZFNMcG0yVE5LMWM5dFRSZE00?= =?utf-8?B?L0NQUkRDT2MzZWIzSDd6T1lWNGJwci94QjF3bERrR2lzdTNwdFFlVVIxbys5?= =?utf-8?B?dW5tdXRzNDVPMVRIT2VCam9mOG1VSGt5cjBHNTg1cVp1TDlzMGkyOE9NejUy?= =?utf-8?B?dkdpa2JtekFPM0REbVlUUkVxK1BMNTNaN21hdElBek1CMnFEMURyWkFWSiti?= =?utf-8?B?ajNZL3MwbmVwRGRZeHJ1VVFwY0paWVE0VHdHcU1JM1lnOWJVL0pxeGFTZkFx?= =?utf-8?B?V0lWY2oxS1RHQXhiRE96RUtkeGlPSjlMSUVsTU9TRFZ2R1p6Z08waVFZUVlX?= =?utf-8?B?ckZDL3llaWVWeHBPNHBmNGpvN25GSHhNblEzd0IzOGdESnFZNzIzVlBrVTNa?= =?utf-8?B?dXkvU2E2c0l3MFRsZUQ0N0Jwc3VTbm16a2pBQ0hLTUhyUjVPbEVGdk5sM0lo?= =?utf-8?B?N3ZRRTVUa0ZBTzkyM0UxYTEralROamZmd25ya3lJUFRSUSthc2wrazBodVJa?= =?utf-8?B?Zm5rUUpiM2lQODU4ckVZVmpGelFQdGE0TC90Z3hpekhQaGs0K2UweXg2aHE0?= =?utf-8?B?Vzd5OXE4NUtFRkVPNUZ2dDRJOE5SaFJCMjY5Vm1aY3FmelBBTFN4Q044S3Bj?= =?utf-8?B?eTNkUEVLNEF4U2ZuZE1melc5emliL0dSbWVVcXg2WEsrS0VnSFE2d3prdlRa?= =?utf-8?B?VFNUcGxxVnlUWk5ZQlhHcDZPV3o1bkI4UkpwUTNJdzh6Q1I4WVlwbkNCbXJz?= =?utf-8?B?RUtrYnhXd1JOQzdxY3J2aWNKbDFySzFGWWgzNmhUUU1Id1Vrd2s2VW54WmdC?= =?utf-8?B?SWpWWDFKQXE4YWtIM3VwRnhXMWc3R2xBcWpTeUpMYmwzeWVvenlqWXJWOHRE?= =?utf-8?B?bnZvdHdHSERacmJIeFVpMlptMVJYdWM4SkVDcTM3R0lFZ1JQNUszQnFmbzEw?= =?utf-8?B?RkdKSE1qNmlOVGJNeTByRmoyZjdkVGFmWUZNVUhkbUMvQmc0c2VYeG4rREdm?= =?utf-8?B?Qy85MCtBcmFXYTRTeEVHVENQNUNlWFFYQjJsdGxMdG14YWg0R0ZiVFRGY2JW?= =?utf-8?B?MkJIUVhJWFo2bnNwTVB6L21GY3Q3QWt2SnQ1RFEyMS9NTjhsU2JnM3VsbEx1?= =?utf-8?B?UmhsV1kyMGtiSU10VU4xdi9ndVZ2S21pUEJYY2tCSnZrNVlGT0ZDbzI3czZF?= =?utf-8?Q?V3paZq6m5sPPUcYTsdnopU3Iz?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DS0PR11MB6373.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 91493ec6-f388-4bc9-0883-08daadf67d9d X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Oct 2022 15:12:20.7039 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: acKh6KAMuXThvtlWxS0X13rPIaVRlk7jjk7aUqBhpxLQH5jqnfhjhtkjtPOl/ZPAI+YJtj9krfWt472jz7Qk2w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR11MB7110 X-OriginatorOrg: intel.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tuesday, October 11, 2022 6:06 AM, Vipin Sharma wrote:=20 > Pin vCPUs to a host physical CPUs (pCPUs) in dirty_log_perf_test and opti= onally > pin the main application thread to a physical cpu if provided. All tests = based on > perf_test_util framework can take advantage of it if needed. >=20 > While at it, I changed atoi() to atoi_paranoid(), atoi_positive, > atoi_non_negative() in other tests, sorted command line options alphabeti= cally > in dirty_log_perf_test, and added break between -e and -g which was misse= d in > original commit when -e was introduced. Just curious why not re-using the existing tools (e.g. taskset) to do the p= inning? For example, with below changes: diff --git a/tools/testing/selftests/kvm/lib/perf_test_util.c b/tools/testi= ng/se = lftests/kvm/lib/perf_test_util.c index 9618b37c66f7..aac58d1acb3c 100644 --- a/tools/testing/selftests/kvm/lib/perf_test_util.c +++ b/tools/testing/selftests/kvm/lib/perf_test_util.c @@ -264,6 +264,7 @@ void perf_test_start_vcpu_threads(int nr_vcpus, void (*vcpu_fn)(struct perf_test_vcpu_arg= s *)) { int i; + char vcpu_name[5]; vcpu_thread_fn =3D vcpu_fn; WRITE_ONCE(all_vcpu_threads_running, false); @@ -275,6 +276,8 @@ void perf_test_start_vcpu_threads(int nr_vcpus, WRITE_ONCE(vcpu->running, false); pthread_create(&vcpu->thread, NULL, vcpu_thread_main, vcpu); + sprintf(vcpu_name, "%s%d", "vcpu", i); + pthread_setname_np(vcpu->thread, vcpu_name); } and with top we can get PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMM= AND 4464 root 20 0 4248684 4.0g 1628 R 99.9 26.2 0:50.97 dirt= y_log_perf_ 4467 root 20 0 4248684 4.0g 1628 R 99.9 26.2 0:50.93 vcpu0 4469 root 20 0 4248684 4.0g 1628 R 99.9 26.2 0:50.93 vcpu2 4470 root 20 0 4248684 4.0g 1628 R 99.9 26.2 0:50.94 vcpu3 4468 root 20 0 4248684 4.0g 1628 R 99.7 26.2 0:50.93 vcpu1 From nobody Tue Apr 7 03:31:29 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B47AC433F5 for ; Mon, 10 Oct 2022 22:05:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229617AbiJJWF4 (ORCPT ); Mon, 10 Oct 2022 18:05:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229530AbiJJWFv (ORCPT ); Mon, 10 Oct 2022 18:05:51 -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 6C8276112B for ; Mon, 10 Oct 2022 15:05:45 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id n56-20020a056a000d7800b00562b27194d1so4732842pfv.19 for ; Mon, 10 Oct 2022 15:05: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=mLExz0EMZSyuFB8Q/Foo73cV0V2iUxH9jl6FjrHgHuA=; b=MkaNzqUg6OQAS3KXi/d3EbVRp+bK/mHHYYU7YS4eEOcwCnxft2bx4VYtxVPSxLKiwC fQ7Tw1l+vwPqb+QLM/2zYNjyrfI3p/HNNpyYmPzjk0HMovr2yeCwxe4dmKj8eNjaAqlK mAL3alJu+IyzyVhVzBZifiCqjtB43ANoyE2nRCVK8unJoXM/kkEgyo+1fdj7ZLwmbf+M 7wF1YLY42oeGeT5iPsipXNXuxmyszTUnbfQjfZTu9C51ffB0Tn5nffKn1sANITjR4Sg1 CIFjcb0yQf3xwNvje8haD83ZeMqbmdUO9SvYNgoBdjcyDfzdR5VOi5XQSSZNHZzBVf7W ZrHg== 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=mLExz0EMZSyuFB8Q/Foo73cV0V2iUxH9jl6FjrHgHuA=; b=6Lwo9rW4vSAsuOO2Og2ThBHSPiQAvRiPPZMJWkulso5Dkly5/g+V7mIB5EotvjUt2+ mdpV/LVE8lG7KD3SpWR4JV4a/Q3FiShsXxndFFojZwRKjk6ZX2u2Snkujirai3Z8Ue9b 89d1pQKL37/ABJZ0PcY+idRqrLKAgnHryQ1VRMK1xylpIyY/XAwz2gk9PDBqqCRt0HxP qssfW3n4FpIDFCUXPt/90qAJAjo7ZwzOMCl2S97ullGw3EJMAUWjFmUK3vVhGQXnEMTD pNW4/YEPSGC6XSbHnwKVeBqS9OT8NrImS5qXtFI9Z9KK9C1za150F3CIw2R7XCaDUscU czEA== X-Gm-Message-State: ACrzQf0GvNR86UfF+wGJFADwCahm09ASzMzNM8qhVSbQKUMtz1LLox5T /71He7A80hwWB8TdiHkKHsfvMpeK2Z1R X-Google-Smtp-Source: AMsMyM4seMxlZd3QKtALD3XcVrNvAyFwyzsTklJg8t92jVWY9SS0eoPi2DPJxddWEJzfefZiARsvcz1CeL54 X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a05:6a00:e09:b0:563:69ac:5633 with SMTP id bq9-20020a056a000e0900b0056369ac5633mr6808226pfb.54.1665439544947; Mon, 10 Oct 2022 15:05:44 -0700 (PDT) Date: Mon, 10 Oct 2022 15:05:34 -0700 In-Reply-To: <20221010220538.1154054-1-vipinsh@google.com> Mime-Version: 1.0 References: <20221010220538.1154054-1-vipinsh@google.com> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog Message-ID: <20221010220538.1154054-2-vipinsh@google.com> Subject: [PATCH v5 1/5] KVM: selftests: Add missing break between -e and -g option in dirty_log_perf_test From: Vipin Sharma To: seanjc@google.com, pbonzini@redhat.com, dmatlack@google.com Cc: andrew.jones@linux.dev, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Passing -e option (Run VCPUs while dirty logging is being disabled) in dirty_log_perf_test also unintentionally enables -g (Do not enable KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2). Add break between two switch case logic. Fixes: cfe12e64b065 ("KVM: selftests: Add an option to run vCPUs while disa= bling dirty logging") Signed-off-by: Vipin Sharma --- tools/testing/selftests/kvm/dirty_log_perf_test.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/kvm/dirty_log_perf_test.c b/tools/test= ing/selftests/kvm/dirty_log_perf_test.c index f99e39a672d3..56e08da3a87f 100644 --- a/tools/testing/selftests/kvm/dirty_log_perf_test.c +++ b/tools/testing/selftests/kvm/dirty_log_perf_test.c @@ -411,6 +411,7 @@ int main(int argc, char *argv[]) case 'e': /* 'e' is for evil. */ run_vcpus_while_disabling_dirty_logging =3D true; + break; case 'g': dirty_log_manual_caps =3D 0; break; --=20 2.38.0.rc1.362.ged0d419d3c-goog From nobody Tue Apr 7 03:31:29 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2DD54C433F5 for ; Mon, 10 Oct 2022 22:06:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229453AbiJJWF7 (ORCPT ); Mon, 10 Oct 2022 18:05:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229612AbiJJWFv (ORCPT ); Mon, 10 Oct 2022 18:05:51 -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 EB08C73C2C for ; Mon, 10 Oct 2022 15:05:46 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id r126-20020a632b84000000b004393806c06eso6774145pgr.4 for ; Mon, 10 Oct 2022 15:05:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=+m8/CnpnyvF/GMTtF6+sToX6YjEtcCxB1JvOB9LqxJw=; b=PholZ6LrpQEfu25226/v2UKnjcJGs/R7bxejmrFeiGkNU55JfdTr4D75MaSsyQyvZx wYfHbIaIwqm2IbRXTuLtlRMat9KesrHKkpqAWLSNHJiQICCEEGOT6G0rz95kqtCw/KF9 C/n30NajbKG/6Ke8KCKSdq0TSy6OPHA6pschqU/u78SL5j9HTPeWtgRObEh6dlRW32el RN17W70iHZyg3zemr7QFhWbtFWOQD6i1pJPspoJxkeSsCMwUokog5AGmWLtKP/4VeMzK QR+wx0Guj6LTZTvu/J7sG72WhW219IyNDElxD10++7q2r1fVxvfHXGaXI67kYiW/6oBY I5mA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+m8/CnpnyvF/GMTtF6+sToX6YjEtcCxB1JvOB9LqxJw=; b=UxbK4tfSy2SXaexsPE7cnthX+bFQ3eEitAi0lXcwJyaiW8GVgDee/zs7pZHMb1b2AO fWLWu1GGZMIq8GJkXPZ2MClvPNgoE3XW/N7FPPWmson8DV/i99CkQP0DV9TDZNok65PL rnMuPBa6W21z2clYqllvBbKh+Q0bpyZz0nGrDs+/+ObzeRximq1YXKl1LQqsIXiejBGW NgarJvo3jMVF/WjJyxYJAjr3fHTxIQFREiX/eM8wnpbYnzQkgFdWq4xsvDz+NCN21SF3 QE193QhOsZcIWqZgfmqtH8mJLlZwT9mTrCumMmgqIvoobgNTXJfXcyCt1D7sA7Rz+bxq ELtw== X-Gm-Message-State: ACrzQf172EmDB0MvcXjzKdk3caShINjBR7+SRG7/p/h52Z1SKvma7YfM 08kbQy5dsSjI9s/aA3p09T+SaKVmEYRQ X-Google-Smtp-Source: AMsMyM5LjSwU9NZziyHZ3eKQp48olOgBmxwhqstL09MA18f6jUGebiGPyyvh6iI3erGD5/XecKDtce8rNk3w X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a17:902:a70b:b0:181:d20e:6565 with SMTP id w11-20020a170902a70b00b00181d20e6565mr10525054plq.66.1665439546476; Mon, 10 Oct 2022 15:05:46 -0700 (PDT) Date: Mon, 10 Oct 2022 15:05:35 -0700 In-Reply-To: <20221010220538.1154054-1-vipinsh@google.com> Mime-Version: 1.0 References: <20221010220538.1154054-1-vipinsh@google.com> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog Message-ID: <20221010220538.1154054-3-vipinsh@google.com> Subject: [PATCH v5 2/5] KVM: selftests: Put command line options in alphabetical order in dirty_log_perf_test From: Vipin Sharma To: seanjc@google.com, pbonzini@redhat.com, dmatlack@google.com Cc: andrew.jones@linux.dev, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" There are 13 command line options and they are not in any order. Put them in alphabetical order to make it easy to add new options. No functional change intended. Signed-off-by: Vipin Sharma --- .../selftests/kvm/dirty_log_perf_test.c | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/tools/testing/selftests/kvm/dirty_log_perf_test.c b/tools/test= ing/selftests/kvm/dirty_log_perf_test.c index 56e08da3a87f..5bb6954b2358 100644 --- a/tools/testing/selftests/kvm/dirty_log_perf_test.c +++ b/tools/testing/selftests/kvm/dirty_log_perf_test.c @@ -406,50 +406,52 @@ int main(int argc, char *argv[]) =20 guest_modes_append_default(); =20 - while ((opt =3D getopt(argc, argv, "eghi:p:m:nb:f:v:os:x:")) !=3D -1) { + while ((opt =3D getopt(argc, argv, "b:ef:ghi:m:nop:s:v:x:")) !=3D -1) { switch (opt) { + case 'b': + guest_percpu_mem_size =3D parse_size(optarg); + break; case 'e': /* 'e' is for evil. */ run_vcpus_while_disabling_dirty_logging =3D true; break; + case 'f': + p.wr_fract =3D atoi(optarg); + TEST_ASSERT(p.wr_fract >=3D 1, + "Write fraction cannot be less than one"); + break; case 'g': dirty_log_manual_caps =3D 0; break; + case 'h': + help(argv[0]); + break; case 'i': p.iterations =3D atoi(optarg); break; - case 'p': - p.phys_offset =3D strtoull(optarg, NULL, 0); - break; case 'm': guest_modes_cmdline(optarg); break; case 'n': perf_test_args.nested =3D true; break; - case 'b': - guest_percpu_mem_size =3D parse_size(optarg); + case 'o': + p.partition_vcpu_memory_access =3D false; break; - case 'f': - p.wr_fract =3D atoi(optarg); - TEST_ASSERT(p.wr_fract >=3D 1, - "Write fraction cannot be less than one"); + case 'p': + p.phys_offset =3D strtoull(optarg, NULL, 0); + break; + case 's': + p.backing_src =3D parse_backing_src_type(optarg); break; case 'v': nr_vcpus =3D atoi(optarg); TEST_ASSERT(nr_vcpus > 0 && nr_vcpus <=3D max_vcpus, "Invalid number of vcpus, must be between 1 and %d", max_vcpus); break; - case 'o': - p.partition_vcpu_memory_access =3D false; - break; - case 's': - p.backing_src =3D parse_backing_src_type(optarg); - break; case 'x': p.slots =3D atoi(optarg); break; - case 'h': default: help(argv[0]); break; --=20 2.38.0.rc1.362.ged0d419d3c-goog From nobody Tue Apr 7 03:31:29 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C58D7C433F5 for ; Mon, 10 Oct 2022 22:06:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229738AbiJJWGE (ORCPT ); Mon, 10 Oct 2022 18:06:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229624AbiJJWFw (ORCPT ); Mon, 10 Oct 2022 18:05:52 -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 A6BFA74344 for ; Mon, 10 Oct 2022 15:05:48 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id q3-20020a17090311c300b0017898180dddso8595597plh.0 for ; Mon, 10 Oct 2022 15:05:48 -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=z3jRIXD9lwTYzr+JWqeLQZPmgSgqVzyfxqN0o++QVsg=; b=UykqGzMOD8JfWGr6Ca/0WAUukrcI8TghoKMsvc6ju1pt6PzWkoOVlEGZd4U2cOICp8 5f9HVM/YNz1icabSrRzOWaZ/X8nkJT5WrycDsZEttWChjt1MIwj5Jd4YIOwRDTsZiu7L wUj/qEh4RHVWvs8FwRLmhWk4PG/k0/VXJhm+gPMkEmNK4SD0rATp9w2W0ov6Kf2thIUH lturiECb83RF3giXl5x3mXvlhzru5kF6TGvA19tX4oX9JEuwrtvh8sZ3Q1ybISTrEN2n dKwwLqTTEsK7WPnQKx3vNFuoybg+Zhk5rywXEjPFQMqNYycNvr0/fwdKec3QBocwNkR+ Q7Ww== 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=z3jRIXD9lwTYzr+JWqeLQZPmgSgqVzyfxqN0o++QVsg=; b=P4db/wZZcNFCvWEJst+5vDPewB6IBCK0woqxfs75+bzSw7KaGNWWTHkYKILzqiPWl1 LyY2qbA7+5HRGUuFNzmlIM3GztzbUCCNGUuDa8QEjBMc0BPCTSxO4XQ0B+Yb0qcH/GJX dzqqOf2q6bAzRE/KFvjpqk6eWR/x6KmaqPxejeGpTZ2VfRko5jLEqsU9ZETO1q2tGpRl tLg7We5f9uAEdeU6ovLhS/6+xQL6DnDHuHxFWl1ai7NUwPXoMhSSM1E6g+KO5tn8tY72 wiyZes8ZuuhyJ2uKNCUh4zFeYPkrF/wzEljUHCJh+juBOMm6RIiFn+I20eDqU99Sz8rg ZTyw== X-Gm-Message-State: ACrzQf0VFc0WDKOVyfRqeUo1mkta56WuKB1xIx8RQC08A7kcuCA5Yga9 y1GX5n+KbOlr31qn/bjAWlPQNkr0I++j X-Google-Smtp-Source: AMsMyM6Ms8T3xARXypyuW8lo3WmvZvSj3RsFR6X1oSZOp9t/YfEvzr72+i12j3dlVcyUm1jgbwEG7pQ5xnQw X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a17:90b:3b45:b0:20c:2eae:e70 with SMTP id ot5-20020a17090b3b4500b0020c2eae0e70mr18135787pjb.240.1665439548242; Mon, 10 Oct 2022 15:05:48 -0700 (PDT) Date: Mon, 10 Oct 2022 15:05:36 -0700 In-Reply-To: <20221010220538.1154054-1-vipinsh@google.com> Mime-Version: 1.0 References: <20221010220538.1154054-1-vipinsh@google.com> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog Message-ID: <20221010220538.1154054-4-vipinsh@google.com> Subject: [PATCH v5 3/5] KVM: selftests: Add atoi_paranoid() to catch errors missed by atoi() From: Vipin Sharma To: seanjc@google.com, pbonzini@redhat.com, dmatlack@google.com Cc: andrew.jones@linux.dev, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" atoi() doesn't detect errors. There is no way to know that a 0 return is correct conversion or due to an error. Introduce atoi_paranoid() to detect errors and provide correct conversion. Replace all atoi() calls with atoi_paranoid(). Signed-off-by: Vipin Sharma --- .../selftests/kvm/aarch64/arch_timer.c | 8 ++++---- .../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 | 4 ++-- .../testing/selftests/kvm/memslot_perf_test.c | 10 +++++----- .../selftests/kvm/set_memory_region_test.c | 2 +- .../selftests/kvm/x86_64/nx_huge_pages_test.c | 4 ++-- 13 files changed, 48 insertions(+), 27 deletions(-) diff --git a/tools/testing/selftests/kvm/aarch64/arch_timer.c b/tools/testi= ng/selftests/kvm/aarch64/arch_timer.c index 574eb73f0e90..251e7ff04883 100644 --- a/tools/testing/selftests/kvm/aarch64/arch_timer.c +++ b/tools/testing/selftests/kvm/aarch64/arch_timer.c @@ -414,7 +414,7 @@ static bool parse_args(int argc, char *argv[]) while ((opt =3D getopt(argc, argv, "hn:i:p:m:")) !=3D -1) { switch (opt) { case 'n': - test_args.nr_vcpus =3D atoi(optarg); + test_args.nr_vcpus =3D atoi_paranoid(optarg); if (test_args.nr_vcpus <=3D 0) { pr_info("Positive value needed for -n\n"); goto err; @@ -425,21 +425,21 @@ static bool parse_args(int argc, char *argv[]) } break; case 'i': - test_args.nr_iter =3D atoi(optarg); + test_args.nr_iter =3D atoi_paranoid(optarg); if (test_args.nr_iter <=3D 0) { pr_info("Positive value needed for -i\n"); goto err; } break; case 'p': - test_args.timer_period_ms =3D atoi(optarg); + test_args.timer_period_ms =3D atoi_paranoid(optarg); if (test_args.timer_period_ms <=3D 0) { pr_info("Positive value needed for -p\n"); goto err; } break; case 'm': - test_args.migration_freq_ms =3D atoi(optarg); + test_args.migration_freq_ms =3D atoi_paranoid(optarg); if (test_args.migration_freq_ms < 0) { pr_info("0 or positive value needed for -m\n"); goto err; diff --git a/tools/testing/selftests/kvm/aarch64/vgic_irq.c b/tools/testing= /selftests/kvm/aarch64/vgic_irq.c index 17417220a083..ae90b718070a 100644 --- a/tools/testing/selftests/kvm/aarch64/vgic_irq.c +++ b/tools/testing/selftests/kvm/aarch64/vgic_irq.c @@ -824,16 +824,16 @@ int main(int argc, char **argv) while ((opt =3D getopt(argc, argv, "hn:e:l:")) !=3D -1) { switch (opt) { case 'n': - nr_irqs =3D atoi(optarg); + nr_irqs =3D atoi_paranoid(optarg); if (nr_irqs > 1024 || nr_irqs % 32) help(argv[0]); break; case 'e': - eoi_split =3D (bool)atoi(optarg); + eoi_split =3D (bool)atoi_paranoid(optarg); default_args =3D false; break; case 'l': - level_sensitive =3D (bool)atoi(optarg); + level_sensitive =3D (bool)atoi_paranoid(optarg); default_args =3D false; break; case 'h': diff --git a/tools/testing/selftests/kvm/access_tracking_perf_test.c b/tool= s/testing/selftests/kvm/access_tracking_perf_test.c index 76c583a07ea2..c6bcc5301e2c 100644 --- a/tools/testing/selftests/kvm/access_tracking_perf_test.c +++ b/tools/testing/selftests/kvm/access_tracking_perf_test.c @@ -368,7 +368,7 @@ int main(int argc, char *argv[]) params.vcpu_memory_bytes =3D parse_size(optarg); break; case 'v': - params.nr_vcpus =3D atoi(optarg); + params.nr_vcpus =3D atoi_paranoid(optarg); break; case 'o': overlap_memory_access =3D true; diff --git a/tools/testing/selftests/kvm/demand_paging_test.c b/tools/testi= ng/selftests/kvm/demand_paging_test.c index 779ae54f89c4..82597fb04146 100644 --- a/tools/testing/selftests/kvm/demand_paging_test.c +++ b/tools/testing/selftests/kvm/demand_paging_test.c @@ -427,7 +427,7 @@ int main(int argc, char *argv[]) p.src_type =3D parse_backing_src_type(optarg); break; case 'v': - nr_vcpus =3D atoi(optarg); + nr_vcpus =3D atoi_paranoid(optarg); TEST_ASSERT(nr_vcpus > 0 && nr_vcpus <=3D max_vcpus, "Invalid number of vcpus, must be between 1 and %d", max_vcpus); break; diff --git a/tools/testing/selftests/kvm/dirty_log_perf_test.c b/tools/test= ing/selftests/kvm/dirty_log_perf_test.c index 5bb6954b2358..ecda802b78ff 100644 --- a/tools/testing/selftests/kvm/dirty_log_perf_test.c +++ b/tools/testing/selftests/kvm/dirty_log_perf_test.c @@ -416,7 +416,7 @@ int main(int argc, char *argv[]) run_vcpus_while_disabling_dirty_logging =3D true; break; case 'f': - p.wr_fract =3D atoi(optarg); + p.wr_fract =3D atoi_paranoid(optarg); TEST_ASSERT(p.wr_fract >=3D 1, "Write fraction cannot be less than one"); break; @@ -427,7 +427,7 @@ int main(int argc, char *argv[]) help(argv[0]); break; case 'i': - p.iterations =3D atoi(optarg); + p.iterations =3D atoi_paranoid(optarg); break; case 'm': guest_modes_cmdline(optarg); @@ -445,12 +445,12 @@ int main(int argc, char *argv[]) p.backing_src =3D parse_backing_src_type(optarg); break; case 'v': - nr_vcpus =3D atoi(optarg); + nr_vcpus =3D atoi_paranoid(optarg); TEST_ASSERT(nr_vcpus > 0 && nr_vcpus <=3D max_vcpus, "Invalid number of vcpus, must be between 1 and %d", max_vcpus); break; case 'x': - p.slots =3D atoi(optarg); + p.slots =3D atoi_paranoid(optarg); break; default: help(argv[0]); diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testin= g/selftests/kvm/include/test_util.h index befc754ce9b3..feae42863759 100644 --- a/tools/testing/selftests/kvm/include/test_util.h +++ b/tools/testing/selftests/kvm/include/test_util.h @@ -152,4 +152,6 @@ static inline void *align_ptr_up(void *x, size_t size) return (void *)align_up((unsigned long)x, size); } =20 +int atoi_paranoid(const char *num_str); + #endif /* SELFTEST_KVM_TEST_UTIL_H */ diff --git a/tools/testing/selftests/kvm/kvm_page_table_test.c b/tools/test= ing/selftests/kvm/kvm_page_table_test.c index f42c6ac6d71d..ea7feb69bb88 100644 --- a/tools/testing/selftests/kvm/kvm_page_table_test.c +++ b/tools/testing/selftests/kvm/kvm_page_table_test.c @@ -461,7 +461,7 @@ int main(int argc, char *argv[]) p.test_mem_size =3D parse_size(optarg); break; case 'v': - nr_vcpus =3D atoi(optarg); + nr_vcpus =3D atoi_paranoid(optarg); TEST_ASSERT(nr_vcpus > 0 && nr_vcpus <=3D max_vcpus, "Invalid number of vcpus, must be between 1 and %d", max_vcpus); break; diff --git a/tools/testing/selftests/kvm/lib/test_util.c b/tools/testing/se= lftests/kvm/lib/test_util.c index 6d23878bbfe1..ec0f070a6f21 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) =20 return val[1]; } + +int atoi_paranoid(const char *num_str) +{ + char *end_ptr; + long num; + + errno =3D 0; + num =3D strtol(num_str, &end_ptr, 10); + TEST_ASSERT(!errno, "strtol(\"%s\") failed", num_str); + TEST_ASSERT(num_str !=3D end_ptr, + "strtol(\"%s\") didn't find a valid integer.\n", num_str); + TEST_ASSERT(*end_ptr =3D=3D '\0', + "strtol(\"%s\") failed to parse trailing characters \"%s\".\n", + num_str, end_ptr); + TEST_ASSERT(num >=3D INT_MIN && num <=3D 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/te= sting/selftests/kvm/max_guest_memory_test.c index 9a6e4f3ad6b5..1595b73dc09a 100644 --- a/tools/testing/selftests/kvm/max_guest_memory_test.c +++ b/tools/testing/selftests/kvm/max_guest_memory_test.c @@ -193,15 +193,15 @@ int main(int argc, char *argv[]) while ((opt =3D getopt(argc, argv, "c:h:m:s:H")) !=3D -1) { switch (opt) { case 'c': - nr_vcpus =3D atoi(optarg); + nr_vcpus =3D atoi_paranoid(optarg); TEST_ASSERT(nr_vcpus > 0, "number of vcpus must be >0"); break; case 'm': - max_mem =3D atoi(optarg) * size_1gb; + max_mem =3D atoi_paranoid(optarg) * size_1gb; TEST_ASSERT(max_mem > 0, "memory size must be >0"); break; case 's': - slot_size =3D atoi(optarg) * size_1gb; + slot_size =3D atoi_paranoid(optarg) * size_1gb; TEST_ASSERT(slot_size > 0, "slot size must be >0"); break; case 'H': diff --git a/tools/testing/selftests/kvm/memslot_modification_stress_test.c= b/tools/testing/selftests/kvm/memslot_modification_stress_test.c index 6ee7e1dde404..865276993ffb 100644 --- a/tools/testing/selftests/kvm/memslot_modification_stress_test.c +++ b/tools/testing/selftests/kvm/memslot_modification_stress_test.c @@ -166,7 +166,7 @@ int main(int argc, char *argv[]) guest_percpu_mem_size =3D parse_size(optarg); break; case 'v': - nr_vcpus =3D atoi(optarg); + nr_vcpus =3D atoi_paranoid(optarg); TEST_ASSERT(nr_vcpus > 0 && nr_vcpus <=3D max_vcpus, "Invalid number of vcpus, must be between 1 and %d", max_vcpus); @@ -175,7 +175,7 @@ int main(int argc, char *argv[]) p.partition_vcpu_memory_access =3D false; break; case 'i': - p.nr_memslot_modifications =3D atoi(optarg); + p.nr_memslot_modifications =3D atoi_paranoid(optarg); break; case 'h': default: diff --git a/tools/testing/selftests/kvm/memslot_perf_test.c b/tools/testin= g/selftests/kvm/memslot_perf_test.c index 44995446d942..4bae9e3f5ca1 100644 --- a/tools/testing/selftests/kvm/memslot_perf_test.c +++ b/tools/testing/selftests/kvm/memslot_perf_test.c @@ -885,21 +885,21 @@ static bool parse_args(int argc, char *argv[], map_unmap_verify =3D true; break; case 's': - targs->nslots =3D atoi(optarg); + targs->nslots =3D atoi_paranoid(optarg); if (targs->nslots <=3D 0 && targs->nslots !=3D -1) { pr_info("Slot count cap has to be positive or -1 for no cap\n"); return false; } break; case 'f': - targs->tfirst =3D atoi(optarg); + targs->tfirst =3D atoi_paranoid(optarg); if (targs->tfirst < 0) { pr_info("First test to run has to be non-negative\n"); return false; } break; case 'e': - targs->tlast =3D atoi(optarg); + targs->tlast =3D atoi_paranoid(optarg); if (targs->tlast < 0 || targs->tlast >=3D NTESTS) { pr_info("Last test to run has to be non-negative and less than %zu\n", NTESTS); @@ -907,14 +907,14 @@ static bool parse_args(int argc, char *argv[], } break; case 'l': - targs->seconds =3D atoi(optarg); + targs->seconds =3D atoi_paranoid(optarg); if (targs->seconds < 0) { pr_info("Test length in seconds has to be non-negative\n"); return false; } break; case 'r': - targs->runs =3D atoi(optarg); + targs->runs =3D atoi_paranoid(optarg); if (targs->runs <=3D 0) { pr_info("Runs per test has to be positive\n"); return false; diff --git a/tools/testing/selftests/kvm/set_memory_region_test.c b/tools/t= esting/selftests/kvm/set_memory_region_test.c index 0d55f508d595..c366949c8362 100644 --- a/tools/testing/selftests/kvm/set_memory_region_test.c +++ b/tools/testing/selftests/kvm/set_memory_region_test.c @@ -407,7 +407,7 @@ int main(int argc, char *argv[]) =20 #ifdef __x86_64__ if (argc > 1) - loops =3D atoi(argv[1]); + loops =3D atoi_paranoid(argv[1]); else loops =3D 10; =20 diff --git a/tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.c b/tool= s/testing/selftests/kvm/x86_64/nx_huge_pages_test.c index 59ffe7fd354f..354b6902849c 100644 --- a/tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.c +++ b/tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.c @@ -241,10 +241,10 @@ int main(int argc, char **argv) while ((opt =3D getopt(argc, argv, "hp:t:r")) !=3D -1) { switch (opt) { case 'p': - reclaim_period_ms =3D atoi(optarg); + reclaim_period_ms =3D atoi_paranoid(optarg); break; case 't': - token =3D atoi(optarg); + token =3D atoi_paranoid(optarg); break; case 'r': reboot_permissions =3D true; --=20 2.38.0.rc1.362.ged0d419d3c-goog From nobody Tue Apr 7 03:31:29 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C5F7C433F5 for ; Mon, 10 Oct 2022 22:06:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229785AbiJJWGN (ORCPT ); Mon, 10 Oct 2022 18:06:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229657AbiJJWFx (ORCPT ); Mon, 10 Oct 2022 18:05:53 -0400 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 202F7543C4 for ; Mon, 10 Oct 2022 15:05:50 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id nn14-20020a17090b38ce00b0020acfa1403bso18942pjb.1 for ; Mon, 10 Oct 2022 15:05:50 -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=Pu3l3OfjWm+NknT1HWc/AwH+C/OxT+Gby0UIFZe6Dq4=; b=M1tOpwpH8Y5gzSJTswaDu0uUgRXKCKD/6z5frSxGcp6xAE7fmL/xg4mgyJNVPhPPHJ OJiHsI5EWsgpKjeazzRKCt8RMvfNXPcuJewPBNwl0BkKYj7jF5vzVLxqLQvwH7vL5/1o dtSdfHnLmgftgmaAVnwUkmturLx5MEAZwF+mtKXDpPXerQ6vt+flZg95ogaKN0KFUx07 0NM0qqW76VNHHGtAgJZfqqRCA+Uyzxkw2hCCFJkP3pZWQyY9dQUAIXyHLSDa313qYz99 96W8sE6guP3A75K6GTOWWWqoDw743ix6YK+UhXxLpEUDBU9NpCFP0DZje3hjiEeau9Jq /L5g== 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=Pu3l3OfjWm+NknT1HWc/AwH+C/OxT+Gby0UIFZe6Dq4=; b=uLwaShVpCihdzjeIQBcakbWUcmmXgc/EzeeGFiMtrB/HrOfGKPg1NvvdQGkiJJnVLF X4FydrV/jprq210GXIvO+RoAOdCAPPw7GjTBC61TmkR8NE/Yq0kP2cHV/EC6QN+e5MZ1 zXRu85odUdz0SxJ7DD/ahUWfPC4Qd89GKyNCY3ZfL+LpByZord4KdMP0gwVqFvGthhk/ 5CbDDMfKbEogJfxTK4AgnS5qdIMQVQPyOfFCWz7WUcfT0Ytq5TKdbpC/4ZCQlVg+77l2 T5HjVilPtttavqAIzkJoq9MqzpCfqaA+77ukeg7CD1na4nvRhwfK0gOGyKVFDkN0qYp+ EF1g== X-Gm-Message-State: ACrzQf3WXaJtcUPtXtx9wMnxW6cYKhXIpD6uCvU6eKzvdM1U0QIHt2h4 dkGQmkh5omdf3aJkIr0rKmwXIpxM7xkn X-Google-Smtp-Source: AMsMyM4TEKfZUo24wOwpN3CaVf3HnsmbqW3hSuiewUKgoETK92bviutOwexvi6VxOR9qUqUvLX6TaNgw63kI X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a05:6a00:1ace:b0:546:94a3:b235 with SMTP id f14-20020a056a001ace00b0054694a3b235mr22123823pfv.50.1665439549888; Mon, 10 Oct 2022 15:05:49 -0700 (PDT) Date: Mon, 10 Oct 2022 15:05:37 -0700 In-Reply-To: <20221010220538.1154054-1-vipinsh@google.com> Mime-Version: 1.0 References: <20221010220538.1154054-1-vipinsh@google.com> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog Message-ID: <20221010220538.1154054-5-vipinsh@google.com> Subject: [PATCH v5 4/5] 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, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Many KVM selftests take command line arguments which are supposed to be positive (>0) or non-negative (>=3D0). 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 --- .../selftests/kvm/aarch64/arch_timer.c | 25 ++++--------------- .../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 | 2 ++ .../selftests/kvm/kvm_page_table_test.c | 4 +-- tools/testing/selftests/kvm/lib/test_util.c | 16 ++++++++++++ .../selftests/kvm/max_guest_memory_test.c | 7 +++--- .../kvm/memslot_modification_stress_test.c | 6 ++--- .../testing/selftests/kvm/memslot_perf_test.c | 22 ++++------------ .../selftests/kvm/set_memory_region_test.c | 2 +- 12 files changed, 46 insertions(+), 58 deletions(-) diff --git a/tools/testing/selftests/kvm/aarch64/arch_timer.c b/tools/testi= ng/selftests/kvm/aarch64/arch_timer.c index 251e7ff04883..24dffcaf7a9f 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 =3D getopt(argc, argv, "hn:i:p:m:")) !=3D -1) { switch (opt) { case 'n': - test_args.nr_vcpus =3D atoi_paranoid(optarg); - if (test_args.nr_vcpus <=3D 0) { - pr_info("Positive value needed for -n\n"); - goto err; - } else if (test_args.nr_vcpus > KVM_MAX_VCPUS) { + test_args.nr_vcpus =3D atoi_positive(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 =3D atoi_paranoid(optarg); - if (test_args.nr_iter <=3D 0) { - pr_info("Positive value needed for -i\n"); - goto err; - } + test_args.nr_iter =3D atoi_positive(optarg); break; case 'p': - test_args.timer_period_ms =3D atoi_paranoid(optarg); - if (test_args.timer_period_ms <=3D 0) { - pr_info("Positive value needed for -p\n"); - goto err; - } + test_args.timer_period_ms =3D atoi_positive(optarg); break; case 'm': - test_args.migration_freq_ms =3D atoi_paranoid(optarg); - if (test_args.migration_freq_ms < 0) { - pr_info("0 or positive value needed for -m\n"); - goto err; - } + test_args.migration_freq_ms =3D atoi_non_negative(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..d7da5f24db35 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 =3D getopt(argc, argv, "hn:e:l:")) !=3D -1) { switch (opt) { case 'n': - nr_irqs =3D atoi_paranoid(optarg); + nr_irqs =3D atoi_non_negative(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/tool= s/testing/selftests/kvm/access_tracking_perf_test.c index c6bcc5301e2c..b30500cc197e 100644 --- a/tools/testing/selftests/kvm/access_tracking_perf_test.c +++ b/tools/testing/selftests/kvm/access_tracking_perf_test.c @@ -368,7 +368,7 @@ int main(int argc, char *argv[]) params.vcpu_memory_bytes =3D parse_size(optarg); break; case 'v': - params.nr_vcpus =3D atoi_paranoid(optarg); + params.nr_vcpus =3D atoi_positive(optarg); break; case 'o': overlap_memory_access =3D true; diff --git a/tools/testing/selftests/kvm/demand_paging_test.c b/tools/testi= ng/selftests/kvm/demand_paging_test.c index 82597fb04146..dcdb6964b1dc 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 =3D parse_backing_src_type(optarg); break; case 'v': - nr_vcpus =3D atoi_paranoid(optarg); - TEST_ASSERT(nr_vcpus > 0 && nr_vcpus <=3D max_vcpus, + nr_vcpus =3D atoi_positive(optarg); + TEST_ASSERT(nr_vcpus <=3D 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/test= ing/selftests/kvm/dirty_log_perf_test.c index ecda802b78ff..618598ddd993 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 =3D true; break; case 'f': - p.wr_fract =3D atoi_paranoid(optarg); - TEST_ASSERT(p.wr_fract >=3D 1, - "Write fraction cannot be less than one"); + p.wr_fract =3D atoi_positive(optarg); break; case 'g': dirty_log_manual_caps =3D 0; @@ -427,7 +425,7 @@ int main(int argc, char *argv[]) help(argv[0]); break; case 'i': - p.iterations =3D atoi_paranoid(optarg); + p.iterations =3D atoi_positive(optarg); break; case 'm': guest_modes_cmdline(optarg); @@ -445,12 +443,12 @@ int main(int argc, char *argv[]) p.backing_src =3D parse_backing_src_type(optarg); break; case 'v': - nr_vcpus =3D atoi_paranoid(optarg); - TEST_ASSERT(nr_vcpus > 0 && nr_vcpus <=3D max_vcpus, + nr_vcpus =3D atoi_positive(optarg); + TEST_ASSERT(nr_vcpus <=3D max_vcpus, "Invalid number of vcpus, must be between 1 and %d", max_vcpus); break; case 'x': - p.slots =3D atoi_paranoid(optarg); + p.slots =3D atoi_positive(optarg); break; default: help(argv[0]); diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testin= g/selftests/kvm/include/test_util.h index feae42863759..9c7b2c186a48 100644 --- a/tools/testing/selftests/kvm/include/test_util.h +++ b/tools/testing/selftests/kvm/include/test_util.h @@ -153,5 +153,7 @@ static inline void *align_ptr_up(void *x, size_t size) } =20 int atoi_paranoid(const char *num_str); +uint32_t atoi_positive(const char *num_str); +uint32_t atoi_non_negative(const char *num_str); =20 #endif /* SELFTEST_KVM_TEST_UTIL_H */ diff --git a/tools/testing/selftests/kvm/kvm_page_table_test.c b/tools/test= ing/selftests/kvm/kvm_page_table_test.c index ea7feb69bb88..2f62e19976fd 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 =3D parse_size(optarg); break; case 'v': - nr_vcpus =3D atoi_paranoid(optarg); - TEST_ASSERT(nr_vcpus > 0 && nr_vcpus <=3D max_vcpus, + nr_vcpus =3D atoi_positive(optarg); + TEST_ASSERT(nr_vcpus <=3D max_vcpus, "Invalid number of vcpus, must be between 1 and %d", max_vcpus); break; case 's': diff --git a/tools/testing/selftests/kvm/lib/test_util.c b/tools/testing/se= lftests/kvm/lib/test_util.c index ec0f070a6f21..210e98a49a83 100644 --- a/tools/testing/selftests/kvm/lib/test_util.c +++ b/tools/testing/selftests/kvm/lib/test_util.c @@ -353,3 +353,19 @@ int atoi_paranoid(const char *num_str) =20 return num; } + +uint32_t atoi_positive(const char *num_str) +{ + int num =3D atoi_paranoid(num_str); + + TEST_ASSERT(num > 0, "%s is not a positive integer.\n", num_str); + return num; +} + +uint32_t atoi_non_negative(const char *num_str) +{ + int num =3D atoi_paranoid(num_str); + + TEST_ASSERT(num >=3D 0, "%s is not a non-negative integer.\n", num_str); + return num; +} diff --git a/tools/testing/selftests/kvm/max_guest_memory_test.c b/tools/te= sting/selftests/kvm/max_guest_memory_test.c index 1595b73dc09a..20015de3b91c 100644 --- a/tools/testing/selftests/kvm/max_guest_memory_test.c +++ b/tools/testing/selftests/kvm/max_guest_memory_test.c @@ -193,15 +193,14 @@ int main(int argc, char *argv[]) while ((opt =3D getopt(argc, argv, "c:h:m:s:H")) !=3D -1) { switch (opt) { case 'c': - nr_vcpus =3D atoi_paranoid(optarg); - TEST_ASSERT(nr_vcpus > 0, "number of vcpus must be >0"); + nr_vcpus =3D atoi_positive(optarg); break; case 'm': - max_mem =3D atoi_paranoid(optarg) * size_1gb; + max_mem =3D atoi_positive(optarg) * size_1gb; TEST_ASSERT(max_mem > 0, "memory size must be >0"); break; case 's': - slot_size =3D atoi_paranoid(optarg) * size_1gb; + slot_size =3D atoi_positive(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 865276993ffb..7539ee7b6e95 100644 --- a/tools/testing/selftests/kvm/memslot_modification_stress_test.c +++ b/tools/testing/selftests/kvm/memslot_modification_stress_test.c @@ -166,8 +166,8 @@ int main(int argc, char *argv[]) guest_percpu_mem_size =3D parse_size(optarg); break; case 'v': - nr_vcpus =3D atoi_paranoid(optarg); - TEST_ASSERT(nr_vcpus > 0 && nr_vcpus <=3D max_vcpus, + nr_vcpus =3D atoi_positive(optarg); + TEST_ASSERT(nr_vcpus <=3D max_vcpus, "Invalid number of vcpus, must be between 1 and %d", max_vcpus); break; @@ -175,7 +175,7 @@ int main(int argc, char *argv[]) p.partition_vcpu_memory_access =3D false; break; case 'i': - p.nr_memslot_modifications =3D atoi_paranoid(optarg); + p.nr_memslot_modifications =3D atoi_positive(optarg); break; case 'h': default: diff --git a/tools/testing/selftests/kvm/memslot_perf_test.c b/tools/testin= g/selftests/kvm/memslot_perf_test.c index 4bae9e3f5ca1..8e6e2d44d002 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 =3D atoi_paranoid(optarg); - if (targs->tfirst < 0) { - pr_info("First test to run has to be non-negative\n"); - return false; - } + targs->tfirst =3D atoi_non_negative(optarg); break; case 'e': - targs->tlast =3D atoi_paranoid(optarg); - if (targs->tlast < 0 || targs->tlast >=3D NTESTS) { + targs->tlast =3D atoi_non_negative(optarg); + if (targs->tlast >=3D 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 =3D atoi_paranoid(optarg); - if (targs->seconds < 0) { - pr_info("Test length in seconds has to be non-negative\n"); - return false; - } + targs->seconds =3D atoi_non_negative(optarg); break; case 'r': - targs->runs =3D atoi_paranoid(optarg); - if (targs->runs <=3D 0) { - pr_info("Runs per test has to be positive\n"); - return false; - } + targs->runs =3D atoi_positive(optarg); break; } } diff --git a/tools/testing/selftests/kvm/set_memory_region_test.c b/tools/t= esting/selftests/kvm/set_memory_region_test.c index c366949c8362..e09092110121 100644 --- a/tools/testing/selftests/kvm/set_memory_region_test.c +++ b/tools/testing/selftests/kvm/set_memory_region_test.c @@ -407,7 +407,7 @@ int main(int argc, char *argv[]) =20 #ifdef __x86_64__ if (argc > 1) - loops =3D atoi_paranoid(argv[1]); + loops =3D atoi_positive(argv[1]); else loops =3D 10; =20 --=20 2.38.0.rc1.362.ged0d419d3c-goog From nobody Tue Apr 7 03:31:29 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F38ECC433FE for ; Mon, 10 Oct 2022 22:06:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229710AbiJJWGV (ORCPT ); Mon, 10 Oct 2022 18:06:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229689AbiJJWF4 (ORCPT ); Mon, 10 Oct 2022 18:05:56 -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 CB346792D3 for ; Mon, 10 Oct 2022 15:05:52 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id f18-20020a170902ce9200b0017f9ac4cfb5so7671425plg.22 for ; Mon, 10 Oct 2022 15:05:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=FgyttR4VJGAchDQGcZyWgbJJNjgu5qWpEpTzk8jIr08=; b=k8XoSIdChcW2X1gTOiIsNERb9YP1g9WZ5uQQwYNbanEzzG0C4erA3tm6ArBjeMRbsd gJwKFYWsjKpgnBbbem2nBzM4K+yphE9EiKyeZlR9zvFNCDVGmGCj8COK5GYTkxEa+bgY i1NFyfOwTR6wMDYXzHl/1hNAT12f2dsSqy6Wpw9Hu93fHzdV9NU4tpSFrm6o5PG7WsYY i/NNTrFEg2S6+wjA8bMjO1EzdiB8bC815/nhMD+duXmFJMev70FTwqZI3yfuM+ssgm7P A8qqFHfAvkgkzHR9PAhL2anZOTzlBe1ssitSLACQvX7WEB02VOIinZsS9YjCq3hP/2Ds EnEQ== 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=FgyttR4VJGAchDQGcZyWgbJJNjgu5qWpEpTzk8jIr08=; b=OkqUxB0wSK1lAiP0sxR+Hguo4omQuOha4RsXXuvc7pmNYObLyLI0VXzUbgSZHrq0ao zWioiI1iqhkfbUEAvsd0pisCfGid5BQTU8s9fD03WXFFHegVSwJzyAH/dEUA+q41uNgB hZD0oBLULwyYn+RTjSLF/mzdN+GBubxihD200xorDC5oFI4z3RABo6EZy5qJATwvZr2j iKHfEWJNxJ0PByDRg5wmlDkLjG7E61qdK2iNa5LPFp8pRKU8RzoP3yrxB079kiY5X1gt Mvp1Iw30raRBtkLzEwH6Nz5trC3BRX/srfm4z/HfNuHOkM2monD5qDBLD2sHzBB7crWP jSJg== X-Gm-Message-State: ACrzQf081K3KdOojMSR/TTJOeEDn5qdC5x5IkUTtpioo5k0tEqFQl1uU MfD2mgXIWpwmf3nIXWvkyhWvJ/fK5kaE X-Google-Smtp-Source: AMsMyM7DHexzB1rERbya1dLxjD1w0YQjOGFSjai0D1+EC8vtfXcH7AQFfRkWgV2O3sYT/AOvp8IXAFRyIMEJ X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a17:90a:dc05:b0:20a:d73b:53a3 with SMTP id i5-20020a17090adc0500b0020ad73b53a3mr23645069pjv.67.1665439551654; Mon, 10 Oct 2022 15:05:51 -0700 (PDT) Date: Mon, 10 Oct 2022 15:05:38 -0700 In-Reply-To: <20221010220538.1154054-1-vipinsh@google.com> Mime-Version: 1.0 References: <20221010220538.1154054-1-vipinsh@google.com> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog Message-ID: <20221010220538.1154054-6-vipinsh@google.com> Subject: [PATCH v5 5/5] KVM: selftests: Run dirty_log_perf_test on specific CPUs From: Vipin Sharma To: seanjc@google.com, pbonzini@redhat.com, dmatlack@google.com Cc: andrew.jones@linux.dev, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add 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 --- .../selftests/kvm/dirty_log_perf_test.c | 23 ++++++- .../selftests/kvm/include/perf_test_util.h | 6 ++ .../selftests/kvm/lib/perf_test_util.c | 65 ++++++++++++++++++- 3 files changed, 91 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/kvm/dirty_log_perf_test.c b/tools/test= ing/selftests/kvm/dirty_log_perf_test.c index 618598ddd993..eec8bff77767 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: 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" + " Example: ./dirty_log_perf_test -v 3 -c 22,23,24,50\n" + " will create 3 vCPUs, and pin vCPU0=3D>pCPU22, vCPU1=3D>pCPU2= 3\n" + " vCPU2=3D>pCPU24, and pin the application task to pCPU50.\n" + " To leave the application task unpinned, drop the final\n" + " entry:\n" + " ./dirty_log_perf_test -v 3 -c 22,23,24\n\n" + " (default: no pinning)\n"); puts(""); exit(0); } @@ -398,6 +410,7 @@ int main(int argc, char *argv[]) .slots =3D 1, }; int opt; + const char *pcpu_list =3D NULL; =20 dirty_log_manual_caps =3D kvm_check_cap(KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2); @@ -406,11 +419,14 @@ int main(int argc, char *argv[]) =20 guest_modes_append_default(); =20 - while ((opt =3D getopt(argc, argv, "b:ef:ghi:m:nop:s:v:x:")) !=3D -1) { + while ((opt =3D getopt(argc, argv, "b:c:ef:ghi:m:nop:s:v:x:")) !=3D -1) { switch (opt) { case 'b': guest_percpu_mem_size =3D parse_size(optarg); break; + case 'c': + pcpu_list =3D optarg; + break; case 'e': /* 'e' is for evil. */ run_vcpus_while_disabling_dirty_logging =3D true; @@ -456,6 +472,9 @@ int main(int argc, char *argv[]) } } =20 + if (pcpu_list) + perf_test_setup_pinning(pcpu_list, nr_vcpus); + TEST_ASSERT(p.iterations >=3D 2, "The test should have at least two itera= tions"); =20 pr_info("Test iterations: %"PRIu64"\n", p.iterations); diff --git a/tools/testing/selftests/kvm/include/perf_test_util.h b/tools/t= esting/selftests/kvm/include/perf_test_util.h index eaa88df0555a..ccfe3b9dc6bd 100644 --- a/tools/testing/selftests/kvm/include/perf_test_util.h +++ b/tools/testing/selftests/kvm/include/perf_test_util.h @@ -27,6 +27,8 @@ struct perf_test_vcpu_args { /* Only used by the host userspace part of the vCPU thread */ struct kvm_vcpu *vcpu; int vcpu_idx; + /* The pCPU to which this vCPU is pinned. Only valid if pin_vcpus is true= . */ + uint32_t pcpu; }; =20 struct perf_test_args { @@ -39,6 +41,8 @@ struct perf_test_args { =20 /* Run vCPUs in L2 instead of L1, if the architecture supports it. */ bool nested; + /* True if all vCPUs are pinned to pCPUs */ + bool pin_vcpus; =20 struct perf_test_vcpu_args vcpu_args[KVM_MAX_VCPUS]; }; @@ -60,4 +64,6 @@ void perf_test_guest_code(uint32_t vcpu_id); uint64_t perf_test_nested_pages(int nr_vcpus); void perf_test_setup_nested(struct kvm_vm *vm, int nr_vcpus, struct kvm_vc= pu *vcpus[]); =20 +void perf_test_setup_pinning(const char *pcpus_string, int nr_vcpus); + #endif /* SELFTEST_KVM_PERF_TEST_UTIL_H */ diff --git a/tools/testing/selftests/kvm/lib/perf_test_util.c b/tools/testi= ng/selftests/kvm/lib/perf_test_util.c index 9618b37c66f7..520d1f896d61 100644 --- a/tools/testing/selftests/kvm/lib/perf_test_util.c +++ b/tools/testing/selftests/kvm/lib/perf_test_util.c @@ -2,7 +2,10 @@ /* * Copyright (C) 2020, Google LLC. */ +#define _GNU_SOURCE + #include +#include =20 #include "kvm_util.h" #include "perf_test_util.h" @@ -240,10 +243,27 @@ void __weak perf_test_setup_nested(struct kvm_vm *vm,= int nr_vcpus, struct kvm_v exit(KSFT_SKIP); } =20 +static void pin_this_task_to_pcpu(uint32_t pcpu) +{ + cpu_set_t mask; + int r; + + CPU_ZERO(&mask); + CPU_SET(pcpu, &mask); + r =3D sched_setaffinity(0, sizeof(mask), &mask); + TEST_ASSERT(!r, "sched_setaffinity() failed for pCPU '%u'.\n", pcpu); +} + static void *vcpu_thread_main(void *data) { + struct perf_test_vcpu_args *vcpu_args; struct vcpu_thread *vcpu =3D data; =20 + vcpu_args =3D &perf_test_args.vcpu_args[vcpu->vcpu_idx]; + + if (perf_test_args.pin_vcpus) + pin_this_task_to_pcpu(vcpu_args->pcpu); + WRITE_ONCE(vcpu->running, true); =20 /* @@ -255,7 +275,7 @@ static void *vcpu_thread_main(void *data) while (!READ_ONCE(all_vcpu_threads_running)) ; =20 - vcpu_thread_fn(&perf_test_args.vcpu_args[vcpu->vcpu_idx]); + vcpu_thread_fn(vcpu_args); =20 return NULL; } @@ -292,3 +312,46 @@ void perf_test_join_vcpu_threads(int nr_vcpus) for (i =3D 0; i < nr_vcpus; i++) pthread_join(vcpu_threads[i].thread, NULL); } + +static uint32_t parse_pcpu(const char *cpu_str, const cpu_set_t *allowed_m= ask) +{ + uint32_t pcpu =3D atoi_non_negative(cpu_str); + + TEST_ASSERT(CPU_ISSET(pcpu, allowed_mask), + "Not allowed to run on pCPU '%d', check cgroups?\n", pcpu); + return pcpu; +} + +void perf_test_setup_pinning(const char *pcpus_string, int nr_vcpus) +{ + cpu_set_t allowed_mask; + char *cpu, *cpu_list; + char delim[2] =3D ","; + int i, r; + + cpu_list =3D strdup(pcpus_string); + TEST_ASSERT(cpu_list, "strdup() allocation failed.\n"); + + r =3D sched_getaffinity(0, sizeof(allowed_mask), &allowed_mask); + TEST_ASSERT(!r, "sched_getaffinity() failed"); + + cpu =3D strtok(cpu_list, delim); + + /* 1. Get all pcpus for vcpus. */ + for (i =3D 0; i < nr_vcpus; i++) { + TEST_ASSERT(cpu, "pCPU not provided for vCPU '%d'\n", i); + perf_test_args.vcpu_args[i].pcpu =3D parse_pcpu(cpu, &allowed_mask); + cpu =3D strtok(NULL, delim); + } + + perf_test_args.pin_vcpus =3D true; + + /* 2. Check if the main worker needs to be pinned. */ + if (cpu) { + pin_this_task_to_pcpu(parse_pcpu(cpu, &allowed_mask)); + cpu =3D strtok(NULL, delim); + } + + TEST_ASSERT(!cpu, "pCPU list contains trailing garbage characters '%s'", = cpu); + free(cpu_list); +} --=20 2.38.0.rc1.362.ged0d419d3c-goog