From patchwork Mon Oct 24 11:34:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Wei W" X-Patchwork-Id: 8382 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp394326wru; Mon, 24 Oct 2022 04:39:54 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7MSvM9WYbPoyRvYEWzoOVi3kDWQmoc1GvZCpVxnO2O3L7ifemd5etySKHB7z05UJ3YCBfx X-Received: by 2002:aa7:d9d1:0:b0:461:9556:23e6 with SMTP id v17-20020aa7d9d1000000b00461955623e6mr8759469eds.25.1666611594242; Mon, 24 Oct 2022 04:39:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666611594; cv=none; d=google.com; s=arc-20160816; b=zMJ3mRqJ0PniN2I5LSASNHYy/Q4W1IVeDtEz7Qo+vytarHYPm4kTG2JVukIITDmXeY hygldVV2kwgK8SCIPkHHz8z/eCQLdoF5faavpl89n2EmrtGoQgpZBOu0I8036A9ts46o udKf2mwVFhv/F7rulm06rDdt8lUYygqc9Qnlh2Y5K9+rEtJU9Jt50i6RUFJKlRXno3Nt ogvipAZaeAwPnSHOfIl/PBpYTwAeuBH2+HDN4jZyrpyzpZfx/mhXYSEVt1RYyZ79rdrK znocs5yjMdXcWNuhU3Unhbj4SZTk7QtV0knis5SrpeC98icIoAnKEAoOHjy/RM7v1Koe NGDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8I4b7T/weYstRqTwkVZmmDu1hXioH06mbThBj7/W1WA=; b=odT0ejyMD7SwSIgggHfKx1IZxig+e4MeeP0LqBmIRG6EqpLOA0RfjcTnHuYypJQKFT xwhRDir9ZFkS2Oqh8cJQA9H5Qx1y6uxEs4OBvYwubNwyC4g16Pi6dq+vuOMnbNnWzQbd KUcSlJIm3lMnRx5qC2e6E6FiVwyUCJln1SpcpzYDPakAi72uwFJRd8SGURjkIzC5SeNU le7xA9oq8a0sgN0ILVgo1F/diam+SGZJWg0oKfjpbvWNrf+axurslOgrBNnlu5E+hO1r w6h6QecGGv3WdkD8xhFi68cIE8iipm/ILoADLHsCv9zeqsPbglgFD1ho7LKvCe+ThgyT 9d9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=aU7daYoW; 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=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 20-20020a170906309400b00780b09a67dcsi23401853ejv.706.2022.10.24.04.39.30; Mon, 24 Oct 2022 04:39:54 -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=@intel.com header.s=Intel header.b=aU7daYoW; 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=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231224AbiJXLim (ORCPT + 99 others); Mon, 24 Oct 2022 07:38:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230527AbiJXLhz (ORCPT ); Mon, 24 Oct 2022 07:37:55 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6C2A67048; Mon, 24 Oct 2022 04:37:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666611465; x=1698147465; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=E0BMcyV5C3nvC2wXZ/MmiAw+7vmFX/E/IWaLJ0N1vZg=; b=aU7daYoWeQYawRd1J5WKd+xG4qhd2jXD6p785+ppy4AYuP6NB08qPnVf Wk+4IWAf79hSzMZz7FWjZucm92yWHdcF9KRvLumJX7cZXXPptsfkaj+SM am2HBb9uZoO3b1Gh5478bUvWpX7adYxrn5yGeEN7YY8LCEdJknd7QqHFT fN99x8uGxsSof9TFovmYjjGX5Sx4ATPXnLg+lVwEfq7UztffpPrOGeHZM KL1EvE+2HmB+jocrdhTS7kfV0rwJLnOvy570fnC1SOJrSq6FcvigdPpVr HNy7DaeUaBb+u8UVDG8GW85OfREa/PPuwc6DwOeGx4PVCrNhKJd/L8iBH w==; X-IronPort-AV: E=McAfee;i="6500,9779,10509"; a="369462448" X-IronPort-AV: E=Sophos;i="5.95,209,1661842800"; d="scan'208";a="369462448" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2022 04:35:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10509"; a="773784995" X-IronPort-AV: E=Sophos;i="5.95,209,1661842800"; d="scan'208";a="773784995" Received: from tdx-lm.sh.intel.com ([10.239.53.27]) by fmsmga001.fm.intel.com with ESMTP; 24 Oct 2022 04:35:15 -0700 From: Wei Wang To: seanjc@google.com, pbonzini@redhat.com Cc: dmatlack@google.com, vipinsh@google.com, ajones@ventanamicro.com, eric.auger@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Wei Wang Subject: [PATCH v1 11/18] KVM: selftest/xapic_ipi_test: vcpu related code consolidation Date: Mon, 24 Oct 2022 19:34:38 +0800 Message-Id: <20221024113445.1022147-12-wei.w.wang@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20221024113445.1022147-1-wei.w.wang@intel.com> References: <20221024113445.1022147-1-wei.w.wang@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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?1747568918683257386?= X-GMAIL-MSGID: =?utf-8?q?1747568918683257386?= Remove the unnecessary definition of the theads[] array, and change thread_params to be the vcpu's private data. Use the helper function to create the threads. Signed-off-by: Wei Wang --- .../selftests/kvm/x86_64/xapic_ipi_test.c | 54 +++++++++---------- 1 file changed, 24 insertions(+), 30 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/xapic_ipi_test.c b/tools/testing/selftests/kvm/x86_64/xapic_ipi_test.c index 3d272d7f961e..cc2630429067 100644 --- a/tools/testing/selftests/kvm/x86_64/xapic_ipi_test.c +++ b/tools/testing/selftests/kvm/x86_64/xapic_ipi_test.c @@ -22,7 +22,6 @@ #define _GNU_SOURCE /* for program_invocation_short_name */ #include -#include #include #include #include @@ -76,7 +75,6 @@ struct test_data_page { struct thread_params { struct test_data_page *data; - struct kvm_vcpu *vcpu; uint64_t *pipis_rcvd; /* host address of ipis_rcvd global */ }; @@ -193,8 +191,9 @@ static void sender_guest_code(struct test_data_page *data) static void *vcpu_thread(void *arg) { - struct thread_params *params = (struct thread_params *)arg; - struct kvm_vcpu *vcpu = params->vcpu; + struct kvm_vcpu *vcpu = (struct kvm_vcpu *)arg; + struct thread_params *params = + (struct thread_params *)vcpu->private_data; struct ucall uc; int old; int r; @@ -233,17 +232,17 @@ static void *vcpu_thread(void *arg) return NULL; } -static void cancel_join_vcpu_thread(pthread_t thread, struct kvm_vcpu *vcpu) +static void cancel_join_vcpu_thread(struct kvm_vcpu *vcpu) { void *retval; int r; - r = pthread_cancel(thread); + r = pthread_cancel(vcpu->thread); TEST_ASSERT(r == 0, "pthread_cancel on vcpu_id=%d failed with errno=%d", vcpu->id, r); - r = pthread_join(thread, &retval); + r = pthread_join(vcpu->thread, &retval); TEST_ASSERT(r == 0, "pthread_join on vcpu_id=%d failed with errno=%d", vcpu->id, r); @@ -393,17 +392,16 @@ void get_cmdline_args(int argc, char *argv[], int *run_secs, int main(int argc, char *argv[]) { - int r; - int wait_secs; + int i, wait_secs; const int max_halter_wait = 10; int run_secs = 0; int delay_usecs = 0; struct test_data_page *data; vm_vaddr_t test_data_page_vaddr; bool migrate = false; - pthread_t threads[2]; - struct thread_params params[2]; + struct thread_params *params; struct kvm_vm *vm; + struct kvm_vcpu *vcpu; uint64_t *pipis_rcvd; get_cmdline_args(argc, argv, &run_secs, &migrate, &delay_usecs); @@ -412,33 +410,31 @@ int main(int argc, char *argv[]) if (delay_usecs <= 0) delay_usecs = DEFAULT_DELAY_USECS; - vm = vm_create_with_one_vcpu(¶ms[0].vcpu, halter_guest_code); + vm = vm_create_with_one_vcpu(&vcpu, halter_guest_code); vm_init_descriptor_tables(vm); - vcpu_init_descriptor_tables(params[0].vcpu); + vcpu_init_descriptor_tables(vcpu); vm_install_exception_handler(vm, IPI_VECTOR, guest_ipi_handler); virt_pg_map(vm, APIC_DEFAULT_GPA, APIC_DEFAULT_GPA); - params[1].vcpu = vm_vcpu_add(vm, 1, sender_guest_code); + vcpu = vm_vcpu_add(vm, 1, sender_guest_code); + vm_vcpu_threads_private_data_alloc(vm, sizeof(struct thread_params)); test_data_page_vaddr = vm_vaddr_alloc_page(vm); data = addr_gva2hva(vm, test_data_page_vaddr); memset(data, 0, sizeof(*data)); - params[0].data = data; - params[1].data = data; - - vcpu_args_set(params[0].vcpu, 1, test_data_page_vaddr); - vcpu_args_set(params[1].vcpu, 1, test_data_page_vaddr); - pipis_rcvd = (uint64_t *)addr_gva2hva(vm, (uint64_t)&ipis_rcvd); - params[0].pipis_rcvd = pipis_rcvd; - params[1].pipis_rcvd = pipis_rcvd; + + vm_iterate_over_vcpus(vm, vcpu, i) { + params = (struct thread_params *)vcpu->private_data; + params->data = data; + params->pipis_rcvd = pipis_rcvd; + vcpu_args_set(vcpu, 1, test_data_page_vaddr); + } /* Start halter vCPU thread and wait for it to execute first HLT. */ - r = pthread_create(&threads[0], NULL, vcpu_thread, ¶ms[0]); - TEST_ASSERT(r == 0, - "pthread_create halter failed errno=%d", errno); + vcpu_thread_create(vm->vcpus[0], vcpu_thread, 0); fprintf(stderr, "Halter vCPU thread started\n"); wait_secs = 0; @@ -455,9 +451,7 @@ int main(int argc, char *argv[]) "Halter vCPU thread reported its APIC ID: %u after %d seconds.\n", data->halter_apic_id, wait_secs); - r = pthread_create(&threads[1], NULL, vcpu_thread, ¶ms[1]); - TEST_ASSERT(r == 0, "pthread_create sender failed errno=%d", errno); - + vcpu_thread_create(vm->vcpus[1], vcpu_thread, 0); fprintf(stderr, "IPI sender vCPU thread started. Letting vCPUs run for %d seconds.\n", run_secs); @@ -470,8 +464,8 @@ int main(int argc, char *argv[]) /* * Cancel threads and wait for them to stop. */ - cancel_join_vcpu_thread(threads[0], params[0].vcpu); - cancel_join_vcpu_thread(threads[1], params[1].vcpu); + cancel_join_vcpu_thread(vm->vcpus[0]); + cancel_join_vcpu_thread(vm->vcpus[1]); fprintf(stderr, "Test successful after running for %d seconds.\n"