From patchwork Tue Oct 18 04:04:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 3927 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1768196wrs; Mon, 17 Oct 2022 21:17:56 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5siMCjJDxFeo2/PXejoxvYvD5oZP6c5vTzy5gWN0RXRPCe0qtUgJxJDebvVAaXUEo6KHgq X-Received: by 2002:a63:250:0:b0:43c:1f18:a471 with SMTP id 77-20020a630250000000b0043c1f18a471mr1035054pgc.373.1666066676378; Mon, 17 Oct 2022 21:17:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666066676; cv=none; d=google.com; s=arc-20160816; b=Fvt+v1kTsMR2qWdOa+ZUizgBbzac3Um+sxKX9i7E82ux1UYAXtig6U+k89P8V8PMsA UUFD3cUZgB4nvL8jEAPm7L3VAMTGFr0Mb3fbyCw+9PyJN9ibF8+xDrq17hAHwOUqa4st 5+lHh1fDh+FcTYFtak/aQMPDv4iHNVxMgL4nvVjF3QfZEYL9RDnqsqVO4rl999mlINYE OeDxFEcVFRXyx42rnwixTBevADs7R4RABolZmr9s/ZnUB/JgmdYuu2b9iEhSoN0VYvac DZP71ZdXeM5zSKvntBEvV/W04YZLqadwjfuvbh1GaV/uUk7M8WXb6YfzCEb9gYiggAem aKWA== 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=2JseUvCnBtDKpXX2u+0xKEawSnwnBYCh4Pw+SGrWbXc=; b=mKjjGthwR0DNYeMPvWsrZaCQHhHtrS97zFgW0/IoOJHehffHHVHkNDkYOsBeYiMfxT j00o2DKuGRtsxJrZkjZXIYf3okC471Ur7Sr7vlQNwF0KPJY3Fzg64A/O4vwQLhJkgA5S tUynoTz/pxbR5rxr6tBjxW16oqzjLST/kICE4Iy89t1PjqO6vZl/JB7MwCTNjmPSG+Xc kphSmP3mhq1bcDwoddHa2KcJgdkK0a5qc32K72IPtmVWmL0AZML5LZMq0Lk/VRtqmP4c eMm0XLzSNf3sFHjhtuNd0EyWmd9zNMFdVDlvCYdt5bYZerSHYI0qQTRh9BanvYxajGLH T9Iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OyKuXYsU; 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=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d19-20020a056a0024d300b0056362152f8fsi13989980pfv.253.2022.10.17.21.17.43; Mon, 17 Oct 2022 21:17:56 -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=@redhat.com header.s=mimecast20190719 header.b=OyKuXYsU; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230325AbiJREGC (ORCPT + 99 others); Tue, 18 Oct 2022 00:06:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230384AbiJREFu (ORCPT ); Tue, 18 Oct 2022 00:05:50 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAD2087FB4 for ; Mon, 17 Oct 2022 21:05:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666065940; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2JseUvCnBtDKpXX2u+0xKEawSnwnBYCh4Pw+SGrWbXc=; b=OyKuXYsUkOszeEt9CFC1lrD/Mk83aqRBekVIgkv5ZkK212dbDHGa0O78pAyHHK8461PpbY gPCYQFDtGJ95fEObkokTO9eF0ieVHkBRXVKFI2BQ6TS+7McfeCZirXWtDrjPTesnyUTdQs tw/RrFgo1YpG/buzS8DhWlwTn7DOG0c= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-352-YA2M8vYJOtKYrLvyIt9skQ-1; Tue, 18 Oct 2022 00:05:37 -0400 X-MC-Unique: YA2M8vYJOtKYrLvyIt9skQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6EA953C3C964; Tue, 18 Oct 2022 04:05:36 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-70.bne.redhat.com [10.64.54.70]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7188B2166B41; Tue, 18 Oct 2022 04:05:30 +0000 (UTC) From: Gavin Shan To: kvmarm@lists.linux.dev Cc: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, ajones@ventanamicro.com, pbonzini@redhat.com, maz@kernel.org, shuah@kernel.org, oliver.upton@linux.dev, mail@maciej.szmigiero.name, maciej.szmigiero@oracle.com, seanjc@google.com, peterx@redhat.com, ricarkol@google.com, zhenyzha@redhat.com, shan.gavin@gmail.com Subject: [PATCH v2 5/6] KVM: selftests: memslot_perf_test: Consolidate memory sizes Date: Tue, 18 Oct 2022 12:04:53 +0800 Message-Id: <20221018040454.405719-6-gshan@redhat.com> In-Reply-To: <20221018040454.405719-1-gshan@redhat.com> References: <20221018040454.405719-1-gshan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,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?1746997531318454907?= X-GMAIL-MSGID: =?utf-8?q?1746997531318454907?= The addresses and sizes passed to vm_userspace_mem_region_add() and madvise() should be aligned to host page size, which can be 64KB on aarch64. So it's wrong by passing additional fixed 4KB memory area to various tests. Fix it by passing additional fixed 64KB memory area to various tests. We also add checks to ensure that none of host/guest page size exceeds 64KB. After it's applied, the following command works fine on 64KB-page-size-host and 4KB-page-size-guest. # ./memslot_perf_test -v -s 512 Signed-off-by: Gavin Shan --- .../selftests/kvm/include/kvm_util_base.h | 15 ++++++++++ .../testing/selftests/kvm/memslot_perf_test.c | 30 ++++++++++++------- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h index e42a09cd24a0..bd9a19b9054b 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -26,6 +26,21 @@ #define NSEC_PER_SEC 1000000000L +#define SIZE_KiB (1UL << 10) +#define SIZE_MiB (1UL << 20) +#define SIZE_GiB (1UL << 30) +#define SIZE_TiB (1UL << 40) + +/* Base and huge page size */ +#define SIZE_4KiB (4 * SIZE_KiB) +#define SIZE_16KiB (16 * SIZE_KiB) +#define SIZE_64KiB (64 * SIZE_KiB) +#define SIZE_2MiB (2 * SIZE_MiB) +#define SIZE_32MiB (32 * SIZE_MiB) +#define SIZE_512MiB (512 * SIZE_MiB) +#define SIZE_1GiB (1 * SIZE_GiB) +#define SIZE_16GiB (16 * SIZE_GiB) + typedef uint64_t vm_paddr_t; /* Virtual Machine (Guest) physical address */ typedef uint64_t vm_vaddr_t; /* Virtual Machine (Guest) virtual address */ diff --git a/tools/testing/selftests/kvm/memslot_perf_test.c b/tools/testing/selftests/kvm/memslot_perf_test.c index 78a481501ec4..3ab385e40bc0 100644 --- a/tools/testing/selftests/kvm/memslot_perf_test.c +++ b/tools/testing/selftests/kvm/memslot_perf_test.c @@ -25,12 +25,14 @@ #include #include -#define MEM_SIZE ((512U << 20) + 4096) -#define MEM_GPA 0x10000000UL +#define MEM_EXTRA_SIZE SIZE_64KiB + +#define MEM_SIZE (SIZE_512MiB + MEM_EXTRA_SIZE) +#define MEM_GPA (256 * SIZE_MiB) #define MEM_AUX_GPA MEM_GPA #define MEM_SYNC_GPA MEM_AUX_GPA -#define MEM_TEST_GPA (MEM_AUX_GPA + 4096) -#define MEM_TEST_SIZE (MEM_SIZE - 4096) +#define MEM_TEST_GPA (MEM_AUX_GPA + MEM_EXTRA_SIZE) +#define MEM_TEST_SIZE (MEM_SIZE - MEM_EXTRA_SIZE) /* * 32 MiB is max size that gets well over 100 iterations on 509 slots. @@ -38,8 +40,8 @@ * 8194 slots in use can then be tested (although with slightly * limited resolution). */ -#define MEM_SIZE_MAP ((32U << 20) + 4096) -#define MEM_TEST_MAP_SIZE (MEM_SIZE_MAP - 4096) +#define MEM_SIZE_MAP (SIZE_32MiB + MEM_EXTRA_SIZE) +#define MEM_TEST_MAP_SIZE (MEM_SIZE_MAP - MEM_EXTRA_SIZE) /* * 128 MiB is min size that fills 32k slots with at least one page in each @@ -47,8 +49,8 @@ * * 2 MiB chunk size like a typical huge page */ -#define MEM_TEST_UNMAP_SIZE (128U << 20) -#define MEM_TEST_UNMAP_CHUNK_SIZE (2U << 20) +#define MEM_TEST_UNMAP_SIZE (128 * SIZE_MiB) +#define MEM_TEST_UNMAP_CHUNK_SIZE SIZE_2MiB /* * For the move active test the middle of the test area is placed on @@ -60,7 +62,7 @@ * last slot contains 100KB memory with the remaining 84KB. Hence, * the maximum size is double of that (200KB) */ -#define MEM_TEST_MOVE_SIZE 0x32000 +#define MEM_TEST_MOVE_SIZE (200 * SIZE_KiB) #define MEM_TEST_MOVE_GPA_DEST (MEM_GPA + MEM_SIZE) static_assert(MEM_TEST_MOVE_SIZE <= MEM_TEST_SIZE, "invalid move test region size"); @@ -799,13 +801,13 @@ static const struct test_data tests[] = { }, { .name = "unmap", - .mem_size = MEM_TEST_UNMAP_SIZE + 4096, + .mem_size = MEM_TEST_UNMAP_SIZE + MEM_EXTRA_SIZE, .guest_code = guest_code_test_memslot_unmap, .loop = test_memslot_unmap_loop, }, { .name = "unmap chunked", - .mem_size = MEM_TEST_UNMAP_SIZE + 4096, + .mem_size = MEM_TEST_UNMAP_SIZE + MEM_EXTRA_SIZE, .guest_code = guest_code_test_memslot_unmap, .loop = test_memslot_unmap_loop_chunked, }, @@ -865,8 +867,14 @@ static void help(char *name, struct test_args *targs) static bool check_memory_sizes(void) { + uint32_t host_page_size = getpagesize(); uint32_t guest_page_size = vm_guest_mode_params[VM_MODE_DEFAULT].page_size; + if (host_page_size > SIZE_64KiB || guest_page_size > SIZE_64KiB) { + pr_info("Unsupported page size on host (0x%x) or guest (0x%x)\n", + host_page_size, guest_page_size); + } + if (MEM_SIZE % guest_page_size || MEM_TEST_SIZE % guest_page_size) { pr_info("invalid MEM_SIZE or MEM_TEST_SIZE\n");