From patchwork Wed Nov 8 02:51:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhaotianrui X-Patchwork-Id: 16362 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:aa0b:0:b0:403:3b70:6f57 with SMTP id k11csp657833vqo; Tue, 7 Nov 2023 18:52:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IHL6IwahQPCGmZTHQsPds4seWYrlobUK/7Go/z4GBpXqTNFRCu8kp+YZfKRykJwH+fmU9S9 X-Received: by 2002:a05:6871:d301:b0:1e9:b599:1aab with SMTP id pn1-20020a056871d30100b001e9b5991aabmr546253oac.58.1699411925325; Tue, 07 Nov 2023 18:52:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699411925; cv=none; d=google.com; s=arc-20160816; b=kr4a0X6lzedALfH0dMftV4CRKPxOI0VXdzMZOVAI/JJf7MGmdrHfrEfaBf6HLTUNVK y2F+RPwocM7te9YxEHw/q9+lSNF7CFessgPsA5DajtO9cAZsC/VO6f6fiPUSEXsUvHIo pG51kQi6V6J2fVNxXrOOi41NT7gP/q683vfWkEOkAcoLCv9LUgGNOsPtozhXoWxC3aUB /ZMX1dfaXhcbuo6xSzp24K42u/yh8L2N7Yv5+dC5RNhrejy7YU3Ol57ofmwuPNSzGHA2 YMsEHlayboqQIYCpoDWDIvtgJ7HIBJL/0k2wDEaqZ+KozjKi8YepBmCNAA8BtQuXJJrX kAlg== 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 :message-id:date:subject:cc:to:from; bh=2CnAvbdPfb15VtC8xaZTyvV9RWkXJJbqm1Pps680gs4=; fh=nMfjIhEjRr3TY5wbPhfmwv04cfhnjdjQ3fRbSHuEkVo=; b=IUSVVUwIuoTmjXS6ToTFbWRe5NehwA/zOqcPfk/DIuEvoaRY3ZzKhBcY9rrrCYl8cL cCeRL2TqOnTMuFXSTMXbzYHn21aNlFPobhRkDUadimA/wWzxdbqs3WDD0PwALApI7JYQ KkxrDjsq9pSOAjGGN/sLQmLudqcO4JvcJFqJO/aW0/SaaP0bIZXmwyVSmZizmMpvX7u7 b+hTfZuQUHhRtiqIj6b06zYQoGgp+yaN3hWBgp3nk68U/POwxF6CFOktWYxy1INp33fy hVt+65BjgyckES50vNfXiWGxmJ8wIx3ZI3SqJCbsdDlz8KQppgxso7fqmeNTc4IQDjQD uB+w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id v20-20020a63f854000000b00577616e3ad9si3341856pgj.871.2023.11.07.18.52.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Nov 2023 18:52:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id C06448337083; Tue, 7 Nov 2023 18:51:56 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343932AbjKHCvn (ORCPT + 32 others); Tue, 7 Nov 2023 21:51:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229503AbjKHCvi (ORCPT ); Tue, 7 Nov 2023 21:51:38 -0500 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AF1F310EC; Tue, 7 Nov 2023 18:51:35 -0800 (PST) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8BxNui190pljuc3AA--.56195S3; Wed, 08 Nov 2023 10:51:33 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Ax3tyy90plX7U7AA--.63786S2; Wed, 08 Nov 2023 10:51:30 +0800 (CST) From: Tianrui Zhao To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Shuah Khan , Paolo Bonzini , Vishal Annapurve , Huacai Chen , loongarch@lists.linux.dev, Peter Xu , Vipin Sharma , maobibo@loongson.cn, zhaotianrui@loongson.cn, Sean Christopherson Subject: [PATCH v4 0/4] KVM: selftests: Add LoongArch support Date: Wed, 8 Nov 2023 10:51:30 +0800 Message-Id: <20231108025134.2592663-1-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Ax3tyy90plX7U7AA--.63786S2 X-CM-SenderInfo: p2kd03xldq233l6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 07 Nov 2023 18:51:56 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781962558695413963 X-GMAIL-MSGID: 1781962558695413963 We add LoongArch support into KVM selftests and there are some KVM test cases we have passed: demand_paging_test dirty_log_perf_test dirty_log_test guest_print_test kvm_binary_stats_test kvm_create_max_vcpus kvm_page_table_test memslot_modification_stress_test memslot_perf_test set_memory_region_test Changes for v4: 1. Remove the based-on flag, as the LoongArch KVM patch series have been accepted by Linux kernel, so this can be applied directly in kernel. Changes for v3: 1. Improve implementation of LoongArch VM page walk. 2. Add exception handler for LoongArch. 3. Add dirty_log_test, dirty_log_perf_test, guest_print_test test cases for LoongArch. 4. Add __ASSEMBLER__ macro to distinguish asm file and c file. 5. Move ucall_arch_do_ucall to the header file and make it as static inline to avoid function calls. 6. Change the DEFAULT_GUEST_TEST_MEM base addr for LoongArch. Changes for v2: 1. We should use ".balign 4096" to align the assemble code with 4K in exception.S instead of "align 12". 2. LoongArch only supports 3 or 4 levels page tables, so we remove the hanlders for 2-levels page table. 3. Remove the DEFAULT_LOONGARCH_GUEST_STACK_VADDR_MIN and use the common DEFAULT_GUEST_STACK_VADDR_MIN to allocate stack memory in guest. 4. Reorganize the test cases supported by LoongArch. 5. Fix some code comments. 6. Add kvm_binary_stats_test test case into LoongArch KVM selftests. changes for v1: 1. Add kvm selftests header files for LoongArch. 2. Add processor tests for LoongArch KVM. 3. Add ucall tests for LoongArch KVM. 4. Add LoongArch tests into makefile. All of the test cases results: 1..10 # timeout set to 120 # selftests: kvm: demand_paging_test # Testing guest mode: PA-bits:36, VA-bits:47, 16K pages # guest physical test memory: [0xfbfffc000, 0xfffffc000) # Finished creating vCPUs and starting uffd threads # Started all vCPUs # All vCPU threads joined # Total guest execution time: 0.200804700s # Overall demand paging rate: 326366.862927 pgs/sec ok 1 selftests: kvm: demand_paging_test # timeout set to 120 # selftests: kvm: dirty_log_perf_test # Test iterations: 2 # Testing guest mode: PA-bits:36, VA-bits:47, 16K pages # guest physical test memory: [0xfbfffc000, 0xfffffc000) # Random seed: 1 # Populate memory time: 0.201452560s # Enabling dirty logging time: 0.000451670s # # Iteration 1 dirty memory time: 0.051582140s # Iteration 1 get dirty log time: 0.000010510s # Iteration 1 clear dirty log time: 0.000421730s # Iteration 2 dirty memory time: 0.046593760s # Iteration 2 get dirty log time: 0.000002110s # Iteration 2 clear dirty log time: 0.000418020s # Disabling dirty logging time: 0.002948490s # Get dirty log over 2 iterations took 0.000012620s. (Avg 0.000006310s/iteration) # Clear dirty log over 2 iterations took 0.000839750s. (Avg 0.000419875s/iteration) ok 2 selftests: kvm: dirty_log_perf_test # timeout set to 120 # selftests: kvm: dirty_log_test # Test iterations: 32, interval: 10 (ms) # Testing Log Mode 'dirty-log' # Testing guest mode: PA-bits:36, VA-bits:47, 16K pages # guest physical test memory offset: 0xfbfff0000 # Dirtied 453632 pages # Total bits checked: dirty (436564), clear (1595145), track_next (70002) # Testing Log Mode 'clear-log' # Testing guest mode: PA-bits:36, VA-bits:47, 16K pages # guest physical test memory offset: 0xfbfff0000 # Dirtied 425984 pages # Total bits checked: dirty (414397), clear (1617312), track_next (68152) # Testing Log Mode 'dirty-ring' # Testing guest mode: PA-bits:36, VA-bits:47, 16K pages # dirty ring count: 0x10000 # guest physical test memory offset: 0xfbfff0000 # vcpu stops because vcpu is kicked out... # Notifying vcpu to continue # vcpu continues now. # Iteration 1 collected 3201 pages # vcpu stops because dirty ring is full... # vcpu continues now. # vcpu stops because dirty ring is full... # Notifying vcpu to continue # Iteration 2 collected 65472 pages # ...... # vcpu continues now. # vcpu stops because vcpu is kicked out... # vcpu continues now. # vcpu stops because vcpu is kicked out... # Notifying vcpu to continue # vcpu continues now. # Iteration 31 collected 12642 pages # vcpu stops because dirty ring is full... # vcpu continues now. # Dirtied 7275520 pages # Total bits checked: dirty (1165675), clear (866034), track_next (811358) ok 3 selftests: kvm: dirty_log_test # timeout set to 120 # selftests: kvm: guest_print_test ok 4 selftests: kvm: guest_print_test # timeout set to 120 # selftests: kvm: kvm_binary_stats_test # TAP version 13 # 1..4 # ok 1 vm0 # ok 2 vm1 # ok 3 vm2 # ok 4 vm3 # # Totals: pass:4 fail:0 xfail:0 xpass:0 skip:0 error:0 ok 5 selftests: kvm: kvm_binary_stats_test # timeout set to 120 # selftests: kvm: kvm_create_max_vcpus # KVM_CAP_MAX_VCPU_ID: 256 # KVM_CAP_MAX_VCPUS: 256 # Testing creating 256 vCPUs, with IDs 0...255. ok 6 selftests: kvm: kvm_create_max_vcpus # timeout set to 120 # selftests: kvm: kvm_page_table_test # Testing guest mode: PA-bits:36, VA-bits:47, 16K pages # Testing memory backing src type: anonymous # Testing memory backing src granularity: 0x4000 # Testing memory size(aligned): 0x40000000 # Guest physical test memory offset: 0xfbfffc000 # Host virtual test memory offset: 0x7fffb0860000 # Number of testing vCPUs: 1 # Started all vCPUs successfully # KVM_CREATE_MAPPINGS: total execution time: 0.200919330s # # KVM_UPDATE_MAPPINGS: total execution time: 0.051182930s # # KVM_ADJUST_MAPPINGS: total execution time: 0.010083590s # ok 7 selftests: kvm: kvm_page_table_test # timeout set to 120 # selftests: kvm: memslot_modification_stress_test # Testing guest mode: PA-bits:36, VA-bits:47, 16K pages # guest physical test memory: [0xfbfffc000, 0xfffffc000) # Finished creating vCPUs # Started all vCPUs # All vCPU threads joined ok 8 selftests: kvm: memslot_modification_stress_test # timeout set to 120 # selftests: kvm: memslot_perf_test # Testing map performance with 1 runs, 5 seconds each # Memslot count too high for this test, decrease the cap (max is 2053) # # Testing unmap performance with 1 runs, 5 seconds each # Memslot count too high for this test, decrease the cap (max is 8197) # # Testing unmap chunked performance with 1 runs, 5 seconds each # Memslot count too high for this test, decrease the cap (max is 8197) # # Testing move active area performance with 1 runs, 5 seconds each # Test took 0.761678900s for slot setup + 5.000014460s all iterations # Done 120167 iterations, avg 0.000041608s each # Best runtime result was 0.000041608s per iteration (with 120167 iterations) # # Testing move inactive area performance with 1 runs, 5 seconds each # Test took 0.771796550s for slot setup + 5.000018520s all iterations # Done 136354 iterations, avg 0.000036669s each # Best runtime result was 0.000036669s per iteration (with 136354 iterations) # # Testing RW performance with 1 runs, 5 seconds each # Test took 0.763568840s for slot setup + 5.002233800s all iterations # Done 649 iterations, avg 0.007707602s each # Best runtime result was 0.007707602s per iteration (with 649 iterations) # Best slot setup time for the whole test area was 0.761678900s ok 9 selftests: kvm: memslot_perf_test # timeout set to 120 # selftests: kvm: set_memory_region_test # Allowed number of memory slots: 32767 # Adding slots 0..32766, each memory region with 2048K size ok 10 selftests: kvm: set_memory_region_test Tianrui Zhao (4): KVM: selftests: Add KVM selftests header files for LoongArch KVM: selftests: Add core KVM selftests support for LoongArch KVM: selftests: Add ucall test support for LoongArch KVM: selftests: Add test cases for LoongArch tools/testing/selftests/kvm/Makefile | 15 + .../selftests/kvm/include/kvm_util_base.h | 5 + .../kvm/include/loongarch/processor.h | 133 +++++++ .../selftests/kvm/include/loongarch/ucall.h | 20 ++ .../testing/selftests/kvm/include/memstress.h | 10 + .../selftests/kvm/lib/loongarch/exception.S | 59 ++++ .../selftests/kvm/lib/loongarch/processor.c | 333 ++++++++++++++++++ .../selftests/kvm/lib/loongarch/ucall.c | 38 ++ 8 files changed, 613 insertions(+) create mode 100644 tools/testing/selftests/kvm/include/loongarch/processor.h create mode 100644 tools/testing/selftests/kvm/include/loongarch/ucall.h create mode 100644 tools/testing/selftests/kvm/lib/loongarch/exception.S create mode 100644 tools/testing/selftests/kvm/lib/loongarch/processor.c create mode 100644 tools/testing/selftests/kvm/lib/loongarch/ucall.c