From patchwork Mon Oct 24 11:34:35 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: 8379 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp394061wru; Mon, 24 Oct 2022 04:39:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6+dczzzOREjYzI5dcjiiOPPn+w5SqTGqdCohOMvAtjgyG6UtwX68ds5aKf/xlN1lcfnnxQ X-Received: by 2002:a17:906:dc93:b0:791:95dd:aaf6 with SMTP id cs19-20020a170906dc9300b0079195ddaaf6mr26557905ejc.456.1666611553198; Mon, 24 Oct 2022 04:39:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666611553; cv=none; d=google.com; s=arc-20160816; b=h0ZrcRMFrYPFhzJ9X8zSaNY0dY30jhB86GlATs+GqTYOZ6SNVKoZGAoDoY0A0pKPwp /ropaOKnSVhqwCd1qxr4mYhKfEpexKDoGuJZ2aoZpVL6/PemI7JJJPvCsWOz63nNvf6p buTj9+/ZhfpV62lKfRzvKpOdwMVWIHT93EU6+vCS7THkVioUTESGKmg+IU96hdTVCArw er1km3fBQXQ/423O3W/2+BEjulVjpKXKzDKy1rOglDl54ZMlwTMmsRoSpfhYJfNMAQ77 H67lVwWcu9wHH+eeNKAlnHsdXNsNTvyKp23o13sINWYdW+n+UwBcfhHvQHfdPXo61J+9 ivgQ== 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=gPbibfZbomSx7Cn2HL6z8qN+ICCXTEw8tsJaaVP2O30=; b=Cipe40la5pHoNPus8cL4TgthPJwF9K+/2lwG5rIBk2S1Ke8Ul7qBVeuRf1c7UZ3pP8 nzHlIi1elzwmY+gMeNLqabTp3ExzPK0o3gAAFYKaEY9nVyOAygLCDViVlDuBhGQd9BCs kSsgKOl4QCwoagTv5rZ1uoHzQ2x1mJeM9GVyRJf0R0aGWdslUhSMqOhDvtishDlzLKj5 vy/2qHmVIGVBwz0oyFpmsNmZYG0DlfhIqTF6R2HrhxPFEf7kw3vlor/OH1xlbXw5F84m s1obHdk2SsCWFlZNDtAyrFBsWgmC7cgu4I2ePoh4ReNNUyHjChuaqadzZcN8B5OdyDSn 4OUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WrOgQsMI; 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 c12-20020aa7df0c000000b00459fc3fcf3csi24989683edy.102.2022.10.24.04.38.47; Mon, 24 Oct 2022 04:39:13 -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=WrOgQsMI; 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 S231174AbiJXLiT (ORCPT + 99 others); Mon, 24 Oct 2022 07:38:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230397AbiJXLhp (ORCPT ); Mon, 24 Oct 2022 07:37:45 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF09263AC; Mon, 24 Oct 2022 04:37:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666611452; x=1698147452; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DB1bYR1A7NeiADV6itewTi7E2/TdqRod02cjfT4etd0=; b=WrOgQsMIS3pkJnbunaNVVDYbr44SrfyC70DZPCvFsz/DBSfgOI/z2qiF TsXaiQnySQfxYtKwU8lNN46MWAKSnCQPCcv45usw8MQr86bm+NWJema+v 2OB6sVu1jnyPYJq2q2Vgk7U1WtWeJlzw2yHk9jdIoFYb2krErdQwwUGk9 7X++9cInskc5/1KL4zwo3FP77Vc94aIhnM1XuFIHXUTO9kcM3iV4HhzYm vLtJyWi4iqgfnq6ihX0YVNz00c7d1Cx/TjkxBXekeJALy6mJjXjxMABvr ENJtXeh7JaXYXvQ6Rzft5x/2iM9SpOyqoZBe0JUVw3+4v+UirH6JWyfog A==; X-IronPort-AV: E=McAfee;i="6500,9779,10509"; a="369462433" X-IronPort-AV: E=Sophos;i="5.95,209,1661842800"; d="scan'208";a="369462433" 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:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10509"; a="773784858" X-IronPort-AV: E=Sophos;i="5.95,209,1661842800"; d="scan'208";a="773784858" Received: from tdx-lm.sh.intel.com ([10.239.53.27]) by fmsmga001.fm.intel.com with ESMTP; 24 Oct 2022 04:35:08 -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 08/18] KVM: selftests/set_memory_region_test: vcpu related code consolidation Date: Mon, 24 Oct 2022 19:34:35 +0800 Message-Id: <20221024113445.1022147-9-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?1747568876090390724?= X-GMAIL-MSGID: =?utf-8?q?1747568876090390724?= Remove the unnecessary vcpu_thread definition and remove it from the related funtions' input as it can be referenced from the kvm_vcpu struct. Also use the helper functinos to create and join the vcpu thread. Signed-off-by: Wei Wang --- .../selftests/kvm/set_memory_region_test.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/kvm/set_memory_region_test.c b/tools/testing/selftests/kvm/set_memory_region_test.c index 0d55f508d595..d233668957da 100644 --- a/tools/testing/selftests/kvm/set_memory_region_test.c +++ b/tools/testing/selftests/kvm/set_memory_region_test.c @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #define _GNU_SOURCE /* for program_invocation_short_name */ #include -#include #include #include #include @@ -108,8 +107,7 @@ static void wait_for_vcpu(void) usleep(100000); } -static struct kvm_vm *spawn_vm(struct kvm_vcpu **vcpu, pthread_t *vcpu_thread, - void *guest_code) +static struct kvm_vm *spawn_vm(struct kvm_vcpu **vcpu, void *guest_code) { struct kvm_vm *vm; uint64_t *hva; @@ -134,7 +132,7 @@ static struct kvm_vm *spawn_vm(struct kvm_vcpu **vcpu, pthread_t *vcpu_thread, hva = addr_gpa2hva(vm, MEM_REGION_GPA); memset(hva, 0, 2 * 4096); - pthread_create(vcpu_thread, NULL, vcpu_worker, *vcpu); + vm_vcpu_threads_create(vm, vcpu_worker, 0); /* Ensure the guest thread is spun up. */ wait_for_vcpu(); @@ -175,12 +173,11 @@ static void guest_code_move_memory_region(void) static void test_move_memory_region(void) { - pthread_t vcpu_thread; struct kvm_vcpu *vcpu; struct kvm_vm *vm; uint64_t *hva; - vm = spawn_vm(&vcpu, &vcpu_thread, guest_code_move_memory_region); + vm = spawn_vm(&vcpu, guest_code_move_memory_region); hva = addr_gpa2hva(vm, MEM_REGION_GPA); @@ -211,7 +208,7 @@ static void test_move_memory_region(void) /* Defered sync from when the memslot was misaligned (above). */ wait_for_vcpu(); - pthread_join(vcpu_thread, NULL); + vm_vcpu_threads_join(vm); kvm_vm_free(vm); } @@ -254,13 +251,12 @@ static void guest_code_delete_memory_region(void) static void test_delete_memory_region(void) { - pthread_t vcpu_thread; struct kvm_vcpu *vcpu; struct kvm_regs regs; struct kvm_run *run; struct kvm_vm *vm; - vm = spawn_vm(&vcpu, &vcpu_thread, guest_code_delete_memory_region); + vm = spawn_vm(&vcpu, guest_code_delete_memory_region); /* Delete the memory region, the guest should not die. */ vm_mem_region_delete(vm, MEM_REGION_SLOT); @@ -282,7 +278,7 @@ static void test_delete_memory_region(void) */ vm_mem_region_delete(vm, 0); - pthread_join(vcpu_thread, NULL); + vm_vcpu_threads_join(vm); run = vcpu->run;