Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp795547pxp; Fri, 11 Mar 2022 15:21:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJzTr178/7Yngoz3doAJGvXE0iaX1PSVbBcHTNbPkUf9EsAtzCRhbtyWyrz2lt9VvOS+PDbQ X-Received: by 2002:a63:447:0:b0:37d:b683:2c06 with SMTP id 68-20020a630447000000b0037db6832c06mr10452055pge.16.1647040870965; Fri, 11 Mar 2022 15:21:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1647040870; cv=none; d=google.com; s=arc-20160816; b=WW/Bnvorqc9iz6XuLSS4nbYx1rFBRsQA+7LfgGagODNFqbhyXUci47F62SACWqqi3o W5TDaQ5t7IiyCkAW+8vhGwcefAvC7/Zr8U4W6R6b0Tjr+Xbk/3itk2x3N+/qDnTjvYCZ 0PaGJpYGc7WTEEsTz6VTv69rR0YwAYRzYnxNqDzaerC2C6m9ZNiQCgyfg7CddYtsZBaT HAVOWrMimT6yldTSWt0IgjMdLvC+dQYE4p5FX3cONvJco6FLQPFD1yppH94/SDj/xKwn 0kfm4hAQ25vHf58+V3Fr+aRvLJrEd+5ULO6eRR6+el+fEo20rsfUM8/u6Gl6vNA2EOYE xxgA== 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:references:mime-version :message-id:in-reply-to:date:reply-to:dkim-signature; bh=ik8aZKQiVh0KHQbr87ubLxwNVrAP3Y5BKOg9RURF8F4=; b=CHs+USITGBv8tODSNsPc927Br6/Z+lx9DtCLC/dgBaS7rDUTHxYXh0Xo+AD7b9RJmy MG4N4beQzZ/0AAicZOAHgRadmPpEAnVozBub2HngHDsoQ+xzCrD3AS0rJG+ZcwklS06E RUXtOsUqMOkv+2krv8s1xCy8iBtwvM++BuNZ1vxS9KB90+Ib1j4trI2hxTa/3VXjkrhp YeZAyOq5V9NOjVFMfqcA8ssu2lcH23Gt/LtMn/dxcvzYZVXXmKM4eZBuUzlMZ9KdBw5S 9OE0Nud1Y/AapJj8VV5KWZ/U61yKoaQrBnJaek3zPeZnh1Oqt1WdYGrDd0yuIQVLMyjE 4oqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=mjOO+xp7; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id l184-20020a6388c1000000b0037c9021a3desi8561040pgd.211.2022.03.11.15.21.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Mar 2022 15:21:10 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=mjOO+xp7; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CDDA43A4412; Fri, 11 Mar 2022 14:07:40 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233182AbiCKGCs (ORCPT + 99 others); Fri, 11 Mar 2022 01:02:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346768AbiCKFzJ (ORCPT ); Fri, 11 Mar 2022 00:55:09 -0500 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 AF0331017F9 for ; Thu, 10 Mar 2022 21:53:48 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id h69-20020a628348000000b004f769e5b4bdso2827815pfe.10 for ; Thu, 10 Mar 2022 21:53:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=ik8aZKQiVh0KHQbr87ubLxwNVrAP3Y5BKOg9RURF8F4=; b=mjOO+xp7DwVMQPq2fKDbBmtTDW/Bu8dUEwPrLqBds1noEDa77ZKAOxw4n/6SUHgQ41 IQxOaaif25LQJyrs2bsPHXUfYw5fXnVlcQaOiAfZoKhGdUcrm4RRo8wlim5uWctAbB2d Qn3UvwwBk0jpNeOVOF+hOHppV9aXbyJ2fOybhpJIx63rvHp2BXBcxeo8ONHoE+fLal7C WIABNrIPxhIeavnq+yNl1H2XAaumNq82Ze6GQsyCjm1Z/qEl3bF3N0A8DGwW7+Dui/+i Xt5eAMJER7cPeZNB+Msp2l92bybEsST7KkeSKQOAmtgOjYwFNelr4P5Q75Z+k4MqiIVt d+Yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=ik8aZKQiVh0KHQbr87ubLxwNVrAP3Y5BKOg9RURF8F4=; b=Jb271hf4GLwTfwdniRIVY17Tr/xomEQ6zvxciRLBqZ7Yj4FrKNXxuQWKeXR+2nxAxq 3QGkvD2J+qD5E6Yv4KALCd0YdNj3Box44Ec3JxNmhGKlTQXlb4L8k9EWorbAtvUJoUiX fdGSsAk5QQZ3QkJysW6SKlS4aZEuMro1wjuQoyypLgzU38zXzNuvZccu7ZSIWtdmYWoF kCglV1z6S2UJ4ZGzT+0ztYUIjGOYQGhC1G8MQPvm/3ckD4WThMe+mixHt1Uc/EBuv+44 EB7AF7s7GGhAc13SGOmZVaCbO8BcZIKsn/2Q5yFfKCWGSc85ZaMqRMVvPEtS0OgvPg5r FjjQ== X-Gm-Message-State: AOAM530A5ZugmVhU7OEn/0P5UkzMjtORc77vxSxWq+Hle1kIRrc5v8RB dloDrembHbf7wiRHaiVqv+bs2ya+/ZRQMWc3OUhJhzMfNBEW+4Y6OyidajVP+l0Dpkk9nZKopLM v+fGmQbyl6K6yXmJ6R4GUI327lxTcTrBT3LaX46WTdnWGDrjR3QeUcUyNiFQ1SYq+OjeJqw== X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:90b:4d81:b0:1bf:8ce4:4f51 with SMTP id oj1-20020a17090b4d8100b001bf8ce44f51mr461891pjb.0.1646978027765; Thu, 10 Mar 2022 21:53:47 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 11 Mar 2022 05:50:47 +0000 In-Reply-To: <20220311055056.57265-1-seanjc@google.com> Message-Id: <20220311055056.57265-97-seanjc@google.com> Mime-Version: 1.0 References: <20220311055056.57265-1-seanjc@google.com> X-Mailer: git-send-email 2.35.1.723.g4982287a31-goog Subject: [RFC PATCH 096/105] KVM: selftests: Convert kvm_page_table_test away from reliance on vcpu_id From: Sean Christopherson To: linux-kernel@vger.kernel.org Cc: Sean Christopherson Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no 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 Signed-off-by: Sean Christopherson --- .../selftests/kvm/kvm_page_table_test.c | 61 +++++++------------ 1 file changed, 21 insertions(+), 40 deletions(-) diff --git a/tools/testing/selftests/kvm/kvm_page_table_test.c b/tools/testing/selftests/kvm/kvm_page_table_test.c index a3e3957f67fa..2c92aef163f9 100644 --- a/tools/testing/selftests/kvm/kvm_page_table_test.c +++ b/tools/testing/selftests/kvm/kvm_page_table_test.c @@ -46,11 +46,6 @@ static const char * const test_stage_string[] = { "KVM_ADJUST_MAPPINGS", }; -struct vcpu_args { - int vcpu_id; - bool vcpu_write; -}; - struct test_args { struct kvm_vm *vm; uint64_t guest_test_virt_mem; @@ -60,7 +55,7 @@ struct test_args { uint64_t large_num_pages; uint64_t host_pages_per_lpage; enum vm_mem_backing_src_type src_type; - struct vcpu_args vcpu_args[KVM_MAX_VCPUS]; + struct kvm_vcpu *vcpus[KVM_MAX_VCPUS]; }; /* @@ -92,17 +87,13 @@ static uint64_t guest_test_phys_mem; */ static uint64_t guest_test_virt_mem = DEFAULT_GUEST_TEST_MEM; -static void guest_code(int vcpu_id) +static void guest_code(bool do_write) { struct test_args *p = &test_args; - struct vcpu_args *vcpu_args = &p->vcpu_args[vcpu_id]; enum test_stage *current_stage = &guest_test_stage; uint64_t addr; int i, j; - /* Make sure vCPU args data structure is not corrupt */ - GUEST_ASSERT(vcpu_args->vcpu_id == vcpu_id); - while (true) { addr = p->guest_test_virt_mem; @@ -123,7 +114,7 @@ static void guest_code(int vcpu_id) */ case KVM_CREATE_MAPPINGS: for (i = 0; i < p->large_num_pages; i++) { - if (vcpu_args->vcpu_write) + if (do_write) *(uint64_t *)addr = 0x0123456789ABCDEF; else READ_ONCE(*(uint64_t *)addr); @@ -193,17 +184,15 @@ static void guest_code(int vcpu_id) static void *vcpu_worker(void *data) { - int ret; - struct vcpu_args *vcpu_args = data; struct kvm_vm *vm = test_args.vm; - int vcpu_id = vcpu_args->vcpu_id; - struct kvm_run *run; + struct kvm_vcpu *vcpu = data; + bool do_write = !(vcpu->id % 2); struct timespec start; struct timespec ts_diff; enum test_stage stage; + int ret; - vcpu_args_set(vm, vcpu_id, 1, vcpu_id); - run = vcpu_state(vm, vcpu_id); + vcpu_args_set(vm, vcpu->id, 1, do_write); while (!READ_ONCE(host_quit)) { ret = sem_wait(&test_stage_updated); @@ -213,15 +202,15 @@ static void *vcpu_worker(void *data) return NULL; clock_gettime(CLOCK_MONOTONIC_RAW, &start); - ret = _vcpu_run(vm, vcpu_id); + ret = _vcpu_run(vm, vcpu->id); ts_diff = timespec_elapsed(start); TEST_ASSERT(ret == 0, "vcpu_run failed: %d\n", ret); - TEST_ASSERT(get_ucall(vm, vcpu_id, NULL) == UCALL_SYNC, + TEST_ASSERT(get_ucall(vm, vcpu->id, NULL) == UCALL_SYNC, "Invalid guest sync status: exit_reason=%s\n", - exit_reason_str(run->exit_reason)); + exit_reason_str(vcpu->run->exit_reason)); - pr_debug("Got sync event from vCPU %d\n", vcpu_id); + pr_debug("Got sync event from vCPU %d\n", vcpu->id); stage = READ_ONCE(*current_stage); /* @@ -230,7 +219,7 @@ static void *vcpu_worker(void *data) */ pr_debug("vCPU %d has completed stage %s\n" "execution time is: %ld.%.9lds\n\n", - vcpu_id, test_stage_string[stage], + vcpu->id, test_stage_string[stage], ts_diff.tv_sec, ts_diff.tv_nsec); ret = sem_post(&test_stage_completed); @@ -250,7 +239,6 @@ static struct kvm_vm *pre_init_before_test(enum vm_guest_mode mode, void *arg) { int ret; struct test_params *p = arg; - struct vcpu_args *vcpu_args; enum vm_mem_backing_src_type src_type = p->src_type; uint64_t large_page_size = get_backing_src_pagesz(src_type); uint64_t guest_page_size = vm_guest_mode_params[mode].page_size; @@ -260,7 +248,6 @@ static struct kvm_vm *pre_init_before_test(enum vm_guest_mode mode, void *arg) uint64_t alignment; void *host_test_mem; struct kvm_vm *vm; - int vcpu_id; /* Align up the test memory size */ alignment = max(large_page_size, guest_page_size); @@ -269,7 +256,8 @@ static struct kvm_vm *pre_init_before_test(enum vm_guest_mode mode, void *arg) /* Create a VM with enough guest pages */ guest_num_pages = test_mem_size / guest_page_size; vm = __vm_create_with_vcpus(mode, nr_vcpus, DEFAULT_GUEST_PHY_PAGES, - guest_num_pages, 0, guest_code, NULL); + guest_num_pages, 0, guest_code, + test_args.vcpus); /* Align down GPA of the testing memslot */ if (!p->phys_offset) @@ -292,12 +280,6 @@ static struct kvm_vm *pre_init_before_test(enum vm_guest_mode mode, void *arg) test_args.host_pages_per_lpage = large_page_size / host_page_size; test_args.src_type = src_type; - for (vcpu_id = 0; vcpu_id < KVM_MAX_VCPUS; vcpu_id++) { - vcpu_args = &test_args.vcpu_args[vcpu_id]; - vcpu_args->vcpu_id = vcpu_id; - vcpu_args->vcpu_write = !(vcpu_id % 2); - } - /* Add an extra memory slot with specified backing src type */ vm_userspace_mem_region_add(vm, src_type, guest_test_phys_mem, TEST_MEM_SLOT_INDEX, guest_num_pages, 0); @@ -363,12 +345,11 @@ static void vcpus_complete_new_stage(enum test_stage stage) static void run_test(enum vm_guest_mode mode, void *arg) { - int ret; pthread_t *vcpu_threads; struct kvm_vm *vm; - int vcpu_id; struct timespec start; struct timespec ts_diff; + int ret, i; /* Create VM with vCPUs and make some pre-initialization */ vm = pre_init_before_test(mode, arg); @@ -379,9 +360,9 @@ static void run_test(enum vm_guest_mode mode, void *arg) host_quit = false; *current_stage = KVM_BEFORE_MAPPINGS; - for (vcpu_id = 0; vcpu_id < nr_vcpus; vcpu_id++) { - pthread_create(&vcpu_threads[vcpu_id], NULL, vcpu_worker, - &test_args.vcpu_args[vcpu_id]); + for (i = 0; i < nr_vcpus; i++) { + pthread_create(&vcpu_threads[i], NULL, vcpu_worker, + &test_args.vcpus[i]); } vcpus_complete_new_stage(*current_stage); @@ -424,13 +405,13 @@ static void run_test(enum vm_guest_mode mode, void *arg) /* Tell the vcpu thread to quit */ host_quit = true; - for (vcpu_id = 0; vcpu_id < nr_vcpus; vcpu_id++) { + for (i = 0; i < nr_vcpus; i++) { ret = sem_post(&test_stage_updated); TEST_ASSERT(ret == 0, "Error in sem_post"); } - for (vcpu_id = 0; vcpu_id < nr_vcpus; vcpu_id++) - pthread_join(vcpu_threads[vcpu_id], NULL); + for (i = 0; i < nr_vcpus; i++) + pthread_join(vcpu_threads[i], NULL); ret = sem_destroy(&test_stage_updated); TEST_ASSERT(ret == 0, "Error in sem_destroy"); -- 2.35.1.723.g4982287a31-goog