From patchwork Mon Aug 7 06:51:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhaotianrui X-Patchwork-Id: 131704 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp1270917vqr; Mon, 7 Aug 2023 00:04:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGD2I9a5Mzu45x9Ker7Vv9Ac0aGt9ZTiEfdqQ8M2cmO2yaedr7MHLmdwAzejyR53obxNOdt X-Received: by 2002:a05:6a00:1347:b0:668:99aa:3f17 with SMTP id k7-20020a056a00134700b0066899aa3f17mr8981210pfu.16.1691391896048; Mon, 07 Aug 2023 00:04:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691391896; cv=none; d=google.com; s=arc-20160816; b=hGP4tq2zhVTd3JBY6KrA1hIWTyXyKUC3FluM5wjJbqwACTCu5Mvd6H4MbkpyFr21Ry LmIW2jJL3vs9PIUy+NQkw+mEwEfDU6VxiOHnbkrIYDsPbD5aVv9NRK7Byd83iSjRWqB/ VcK/wzhXwpEdGWRDfImXhbZRHrMbnQZeO9kidkb1hTrCQ1uK+cC321PSJ1FW62GeXRGX wxBzjGWR62PQwDDngkfOSFAyorDMZ3vQQvYHRg04kao3PD2Rqq1723PvsAd70auBhR2b 3LGPN4MW5zt/f9GEIVZDLD8I3RBFV48Jo/cEOJDthHQo0xGLcMFIyKaEVFXwKL15r4Tu 5sXw== 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; bh=+qSIx0I+NpQcuS2j6e5wKfYa5/Wcaz1zoFI6CaxhEws=; fh=gsUmtxbMqK36mL5NFoC4xZ5sX9WhDudI+8elbmlEVgg=; b=gxQJzNbPgFDHSDD4zdzcdbISXjtLwwG8tZjQ//LgUBnq3Rk7hMwBU/T3yXfkSzXHu3 4wiL2mVPzbcJWe7dmco1iOAJ/j9ocS0YZn2FB9YVUnirHEeKQIO1RqkmChfx579ak9ET lOtGu2IG6CjP1PmvjCMo40GUTtFmxlwuM87k905+HNzKnmc2VHMfHEoXKy+wEQwdEwx6 Tr33kWPN1UYG6T8NHPdrcp8dzF6npuUHq/ufRHEuX5cp3nZYQMNadOwMJRukWU4cM4M9 9zWR5yFAS3CPH1W16Tg/n5Defr8LrQI7zobh3ezVvIXcYrBv+rSZtVOS8ejsXGQ4kGqF nd0g== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id by4-20020a056a00400400b0067de347ee12si5158252pfb.164.2023.08.07.00.04.43; Mon, 07 Aug 2023 00:04: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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231325AbjHGGvt (ORCPT + 99 others); Mon, 7 Aug 2023 02:51:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231320AbjHGGvp (ORCPT ); Mon, 7 Aug 2023 02:51:45 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B6E541738; Sun, 6 Aug 2023 23:51:40 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8AxEvB7lNBk6dwRAA--.39118S3; Mon, 07 Aug 2023 14:51:39 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxJ8x5lNBkwspMAA--.23544S3; Mon, 07 Aug 2023 14:51:38 +0800 (CST) From: Tianrui Zhao To: Shuah Khan , Paolo Bonzini , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Sean Christopherson Cc: Vishal Annapurve , Huacai Chen , WANG Xuerui , loongarch@lists.linux.dev, Peter Xu , Vipin Sharma , maobibo@loongson.cn, zhaotianrui@loongson.cn Subject: [PATCH v2 1/4] KVM: selftests: Add KVM selftests header files for LoongArch Date: Mon, 7 Aug 2023 14:51:34 +0800 Message-Id: <20230807065137.3408970-2-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230807065137.3408970-1-zhaotianrui@loongson.cn> References: <20230807065137.3408970-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8DxJ8x5lNBkwspMAA--.23544S3 X-CM-SenderInfo: p2kd03xldq233l6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS 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: INBOX X-GMAIL-THRID: 1773552948466944903 X-GMAIL-MSGID: 1773552948466944903 Add KVM selftests header files for LoongArch, including processor.h and kvm_util_base.h. Those mainly contain LoongArch CSR register defines and page table information. Based-on: <20230803022138.2736430-1-zhaotianrui@loongson.cn> Signed-off-by: Tianrui Zhao --- .../selftests/kvm/include/kvm_util_base.h | 5 + .../kvm/include/loongarch/processor.h | 107 ++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 tools/testing/selftests/kvm/include/loongarch/processor.h diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h index eb1ff597bcca..adb20ab0345f 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -197,6 +197,11 @@ extern enum vm_guest_mode vm_mode_default; #define MIN_PAGE_SHIFT 12U #define ptes_per_page(page_size) ((page_size) / 8) +#elif defined(__loongarch__) +#define VM_MODE_DEFAULT VM_MODE_P36V47_16K +#define MIN_PAGE_SHIFT 14U +#define ptes_per_page(page_size) ((page_size) / 8) + #endif #define MIN_PAGE_SIZE (1U << MIN_PAGE_SHIFT) diff --git a/tools/testing/selftests/kvm/include/loongarch/processor.h b/tools/testing/selftests/kvm/include/loongarch/processor.h new file mode 100644 index 000000000000..9486130325a9 --- /dev/null +++ b/tools/testing/selftests/kvm/include/loongarch/processor.h @@ -0,0 +1,107 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef SELFTEST_KVM_PROCESSOR_H +#define SELFTEST_KVM_PROCESSOR_H + +#define _PAGE_VALID_SHIFT 0 +#define _PAGE_DIRTY_SHIFT 1 +#define _PAGE_PLV_SHIFT 2 /* 2~3, two bits */ +#define _CACHE_SHIFT 4 /* 4~5, two bits */ +#define _PAGE_PRESENT_SHIFT 7 +#define _PAGE_WRITE_SHIFT 8 + +#define PLV_KERN 0 +#define PLV_USER 3 +#define PLV_MASK 0x3 + +#define _PAGE_VALID (0x1UL << _PAGE_VALID_SHIFT) +#define _PAGE_PRESENT (0x1UL << _PAGE_PRESENT_SHIFT) +#define _PAGE_WRITE (0x1UL << _PAGE_WRITE_SHIFT) +#define _PAGE_DIRTY (0x1UL << _PAGE_DIRTY_SHIFT) +#define _PAGE_USER (PLV_USER << _PAGE_PLV_SHIFT) +#define __READABLE (_PAGE_VALID) +#define __WRITEABLE (_PAGE_DIRTY | _PAGE_WRITE) +#define _CACHE_CC (0x1UL << _CACHE_SHIFT) /* Coherent Cached */ + +/* general registers */ +#define zero $r0 +#define ra $r1 +#define tp $r2 +#define sp $r3 +#define a0 $r4 +#define a1 $r5 +#define a2 $r6 +#define a3 $r7 +#define a4 $r8 +#define a5 $r9 +#define a6 $r10 +#define a7 $r11 +#define t0 $r12 +#define t1 $r13 +#define t2 $r14 +#define t3 $r15 +#define t4 $r16 +#define t5 $r17 +#define t6 $r18 +#define t7 $r19 +#define t8 $r20 +#define u0 $r21 +#define fp $r22 +#define s0 $r23 +#define s1 $r24 +#define s2 $r25 +#define s3 $r26 +#define s4 $r27 +#define s5 $r28 +#define s6 $r29 +#define s7 $r30 +#define s8 $r31 + +#define PS_4K 0x0000000c +#define PS_8K 0x0000000d +#define PS_16K 0x0000000e +#define PS_DEFAULT_SIZE PS_16K + +/* Basic CSR registers */ +#define LOONGARCH_CSR_CRMD 0x0 /* Current mode info */ +#define CSR_CRMD_PG_SHIFT 4 +#define CSR_CRMD_PG (0x1UL << CSR_CRMD_PG_SHIFT) +#define CSR_CRMD_IE_SHIFT 2 +#define CSR_CRMD_IE (0x1UL << CSR_CRMD_IE_SHIFT) +#define CSR_CRMD_PLV_SHIFT 0 +#define CSR_CRMD_PLV_WIDTH 2 +#define CSR_CRMD_PLV (0x3UL << CSR_CRMD_PLV_SHIFT) +#define PLV_MASK 0x3 + +#define LOONGARCH_CSR_PRMD 0x1 +#define LOONGARCH_CSR_EUEN 0x2 +#define LOONGARCH_CSR_ECFG 0x4 +#define LOONGARCH_CSR_EENTRY 0xc +#define LOONGARCH_CSR_TLBIDX 0x10 /* TLB Index, EHINV, PageSize, NP */ +#define CSR_TLBIDX_PS_SHIFT 24 +#define CSR_TLBIDX_PS_WIDTH 6 +#define CSR_TLBIDX_PS (0x3fUL << CSR_TLBIDX_PS_SHIFT) +#define CSR_TLBIDX_SIZEM 0x3f000000 +#define CSR_TLBIDX_SIZE CSR_TLBIDX_PS_SHIFT + +#define LOONGARCH_CSR_ASID 0x18 /* ASID */ +/* Page table base address when VA[VALEN-1] = 0 */ +#define LOONGARCH_CSR_PGDL 0x19 +/* Page table base address when VA[VALEN-1] = 1 */ +#define LOONGARCH_CSR_PGDH 0x1a +/* Page table base */ +#define LOONGARCH_CSR_PGD 0x1b +#define LOONGARCH_CSR_PWCTL0 0x1c +#define LOONGARCH_CSR_PWCTL1 0x1d +#define LOONGARCH_CSR_STLBPGSIZE 0x1e +#define LOONGARCH_CSR_CPUID 0x20 +#define LOONGARCH_CSR_TMID 0x40 +#define LOONGARCH_CSR_TCFG 0x41 +#define LOONGARCH_CSR_TLBRENTRY 0x88 /* TLB refill exception entry */ +/* KSave for TLB refill exception */ +#define LOONGARCH_CSR_TLBRSAVE 0x8b +#define LOONGARCH_CSR_TLBREHI 0x8e +#define CSR_TLBREHI_PS_SHIFT 0 +#define CSR_TLBREHI_PS (0x3fUL << CSR_TLBREHI_PS_SHIFT) + +#endif From patchwork Mon Aug 7 06:51:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhaotianrui X-Patchwork-Id: 131705 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp1271040vqr; Mon, 7 Aug 2023 00:05:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHMLGpNM0jbFS+zHDlYqgVqGj7OLS1ZVwomS/emn3UFUZ7itMGZb/Nh4tiAxklY+EjneHZq X-Received: by 2002:a17:902:e5c2:b0:1bc:5e50:9345 with SMTP id u2-20020a170902e5c200b001bc5e509345mr3666546plf.50.1691391915437; Mon, 07 Aug 2023 00:05:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691391915; cv=none; d=google.com; s=arc-20160816; b=Hjcjx/q7qtlJbUnOzL7NHDZFSVDXoc+139eq9FM2RM8d2cFS7JNUVF5639O5VFNXZC BL0JHv543frivREi+8FXmgTboL2V0dv/Nw6dk/GkC27a16NH3/ROiTIEz5b32TPiugJl Gi0Fs0n7f/yv4gfGoK/4wKVMn/+gzhife+CSg56lvtzYcSV9KxR7PL/eybEfgMWXFlFC w7EyiTtP13NB81zcCyYPZ/71WhBFqKo6ohO1qz0Xg/Z9KYC6QTSPYh4xDqrS2WAJn8go v913pRFFXL8p5xUaJB+NZ8EE8sZaNvc3sCOPFXaDz8tiVh98yagJnSeQ4or1B0gtxb+s 6yDA== 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; bh=HPnD0bViSx76HHOmK35i7ngGpHzyg2jCJBzmtyXDzpc=; fh=gsUmtxbMqK36mL5NFoC4xZ5sX9WhDudI+8elbmlEVgg=; b=MkF9yeQm5I0wsbxrDjsTpsj5MN+7sqWEYnP2C2m8Kk6DFAdBe5bOP9RD6DeS5XKHic bVMoBLF07OZ1nrIvFC/WL3TWPnTapZJ6s/VfVpiSu8y//nx2yh88dnr9BKsQwRU8bI8Y +nlMJHC0kvGCY1UMXM2KYPMpWxLArjp8BKpHVaHQh1T9tHgDJMZ08JrzOJVsSx3nw96U fvHHLD+S8g2RhN0gBsGGkvHyEK8WN+SYbarwVZkCfAUuUENFAOTD0P17EeMY2cnT789s o2I7jI3113hjgRQZISZeQKT+trphui/hKnj2ekZ1e1YXUDu8dV+A3Oa5pn7/VzosmIYa nyPQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z1-20020a170903018100b001bbebf5b0dbsi5462016plg.354.2023.08.07.00.05.02; Mon, 07 Aug 2023 00:05:15 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231361AbjHGGv6 (ORCPT + 99 others); Mon, 7 Aug 2023 02:51:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231153AbjHGGvr (ORCPT ); Mon, 7 Aug 2023 02:51:47 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 74B9310EB; Sun, 6 Aug 2023 23:51:41 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8DxVuh8lNBk89wRAA--.4332S3; Mon, 07 Aug 2023 14:51:40 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxJ8x5lNBkwspMAA--.23544S4; Mon, 07 Aug 2023 14:51:39 +0800 (CST) From: Tianrui Zhao To: Shuah Khan , Paolo Bonzini , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Sean Christopherson Cc: Vishal Annapurve , Huacai Chen , WANG Xuerui , loongarch@lists.linux.dev, Peter Xu , Vipin Sharma , maobibo@loongson.cn, zhaotianrui@loongson.cn Subject: [PATCH v2 2/4] KVM: selftests: Add core KVM selftests support for LoongArch Date: Mon, 7 Aug 2023 14:51:35 +0800 Message-Id: <20230807065137.3408970-3-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230807065137.3408970-1-zhaotianrui@loongson.cn> References: <20230807065137.3408970-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8DxJ8x5lNBkwspMAA--.23544S4 X-CM-SenderInfo: p2kd03xldq233l6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS 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: INBOX X-GMAIL-THRID: 1773552968937081165 X-GMAIL-MSGID: 1773552968937081165 Add core KVM selftests support for LoongArch. Based-on: <20230803022138.2736430-1-zhaotianrui@loongson.cn> Signed-off-by: Tianrui Zhao --- .../selftests/kvm/lib/loongarch/exception.S | 27 ++ .../selftests/kvm/lib/loongarch/processor.c | 356 ++++++++++++++++++ 2 files changed, 383 insertions(+) create mode 100644 tools/testing/selftests/kvm/lib/loongarch/exception.S create mode 100644 tools/testing/selftests/kvm/lib/loongarch/processor.c diff --git a/tools/testing/selftests/kvm/lib/loongarch/exception.S b/tools/testing/selftests/kvm/lib/loongarch/exception.S new file mode 100644 index 000000000000..aa1b69fe52cf --- /dev/null +++ b/tools/testing/selftests/kvm/lib/loongarch/exception.S @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include "processor.h" + +/* address of refill exception should be 4K aligned */ +.balign 4096 +.global handle_tlb_refill +handle_tlb_refill: + csrwr t0, LOONGARCH_CSR_TLBRSAVE + csrrd t0, LOONGARCH_CSR_PGD + lddir t0, t0, 3 + lddir t0, t0, 1 + ldpte t0, 0 + ldpte t0, 1 + tlbfill + csrrd t0, LOONGARCH_CSR_TLBRSAVE + ertn + +/* address of general exception should be 4K aligned */ +.balign 4096 +.global handle_exception +handle_exception: +1: + nop + b 1b + nop + ertn diff --git a/tools/testing/selftests/kvm/lib/loongarch/processor.c b/tools/testing/selftests/kvm/lib/loongarch/processor.c new file mode 100644 index 000000000000..3419e5cfd5e1 --- /dev/null +++ b/tools/testing/selftests/kvm/lib/loongarch/processor.c @@ -0,0 +1,356 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include + +#include "kvm_util.h" +#include "processor.h" + +static uint64_t pgd_index(struct kvm_vm *vm, vm_vaddr_t gva) +{ + unsigned int shift; + uint64_t mask; + + shift = (vm->pgtable_levels - 1) * (vm->page_shift - 3) + vm->page_shift; + mask = (1UL << (vm->va_bits - shift)) - 1; + return (gva >> shift) & mask; +} + +static uint64_t pud_index(struct kvm_vm *vm, vm_vaddr_t gva) +{ + unsigned int shift; + uint64_t mask; + + shift = 2 * (vm->page_shift - 3) + vm->page_shift; + mask = (1UL << (vm->page_shift - 3)) - 1; + TEST_ASSERT(vm->pgtable_levels == 4, + "Mode %d does not have 4 page table levels", vm->mode); + + return (gva >> shift) & mask; +} + +static uint64_t pmd_index(struct kvm_vm *vm, vm_vaddr_t gva) +{ + unsigned int shift; + uint64_t mask; + + shift = (vm->page_shift - 3) + vm->page_shift; + mask = (1UL << (vm->page_shift - 3)) - 1; + TEST_ASSERT(vm->pgtable_levels >= 3, + "Mode %d does not have >= 3 page table levels", vm->mode); + + return (gva >> shift) & mask; +} + +static uint64_t pte_index(struct kvm_vm *vm, vm_vaddr_t gva) +{ + uint64_t mask; + + mask = (1UL << (vm->page_shift - 3)) - 1; + return (gva >> vm->page_shift) & mask; +} + +static uint64_t pte_addr(struct kvm_vm *vm, uint64_t entry) +{ + uint64_t mask; + + mask = ((1UL << (vm->va_bits - vm->page_shift)) - 1) << vm->page_shift; + return entry & mask; +} + +static uint64_t ptrs_per_pgd(struct kvm_vm *vm) +{ + unsigned int shift; + + shift = (vm->pgtable_levels - 1) * (vm->page_shift - 3) + vm->page_shift; + return 1 << (vm->va_bits - shift); +} + +static uint64_t __maybe_unused ptrs_per_pte(struct kvm_vm *vm) +{ + return 1 << (vm->page_shift - 3); +} + +void virt_arch_pgd_alloc(struct kvm_vm *vm) +{ + if (vm->pgd_created) + return; + + vm->pgd = vm_alloc_page_table(vm); + vm->pgd_created = true; +} + +uint64_t *virt_get_pte_hva(struct kvm_vm *vm, vm_vaddr_t gva) +{ + uint64_t *ptep; + + if (!vm->pgd_created) + goto unmapped_gva; + + ptep = addr_gpa2hva(vm, vm->pgd) + pgd_index(vm, gva) * 8; + if (!ptep) + goto unmapped_gva; + + switch (vm->pgtable_levels) { + case 4: + ptep = addr_gpa2hva(vm, pte_addr(vm, *ptep)) + pud_index(vm, gva) * 8; + if (!ptep) + goto unmapped_gva; + /* fall through */ + case 3: + ptep = addr_gpa2hva(vm, pte_addr(vm, *ptep)) + pmd_index(vm, gva) * 8; + if (!ptep) + goto unmapped_gva; + ptep = addr_gpa2hva(vm, pte_addr(vm, *ptep)) + pte_index(vm, gva) * 8; + if (!ptep) + goto unmapped_gva; + break; + default: + TEST_FAIL("Got %u page table levels, expected 3 or 4", vm->pgtable_levels); + } + + return ptep; + +unmapped_gva: + TEST_FAIL("No mapping for vm virtual address, gva: 0x%lx", gva); + exit(EXIT_FAILURE); +} + +vm_paddr_t addr_arch_gva2gpa(struct kvm_vm *vm, vm_vaddr_t gva) +{ + uint64_t *ptep; + + ptep = virt_get_pte_hva(vm, gva); + return pte_addr(vm, *ptep) + (gva & (vm->page_size - 1)); +} + +void virt_arch_pg_map(struct kvm_vm *vm, uint64_t vaddr, uint64_t paddr) +{ + uint32_t prot_bits; + uint64_t *ptep; + + TEST_ASSERT((vaddr % vm->page_size) == 0, + "Virtual address not on page boundary,\n" + "vaddr: 0x%lx vm->page_size: 0x%x", vaddr, vm->page_size); + TEST_ASSERT(sparsebit_is_set(vm->vpages_valid, + (vaddr >> vm->page_shift)), + "Invalid virtual address, vaddr: 0x%lx", vaddr); + TEST_ASSERT((paddr % vm->page_size) == 0, + "Physical address not on page boundary,\n" + "paddr: 0x%lx vm->page_size: 0x%x", paddr, vm->page_size); + TEST_ASSERT((paddr >> vm->page_shift) <= vm->max_gfn, + "Physical address beyond maximum supported,\n" + "paddr: 0x%lx vm->max_gfn: 0x%lx vm->page_size: 0x%x", + paddr, vm->max_gfn, vm->page_size); + + ptep = addr_gpa2hva(vm, vm->pgd) + pgd_index(vm, vaddr) * 8; + if (!*ptep) + *ptep = vm_alloc_page_table(vm); + + switch (vm->pgtable_levels) { + case 4: + ptep = addr_gpa2hva(vm, pte_addr(vm, *ptep)) + pud_index(vm, vaddr) * 8; + if (!*ptep) + *ptep = vm_alloc_page_table(vm); + /* fall through */ + case 3: + ptep = addr_gpa2hva(vm, pte_addr(vm, *ptep)) + pmd_index(vm, vaddr) * 8; + if (!*ptep) + *ptep = vm_alloc_page_table(vm); + ptep = addr_gpa2hva(vm, pte_addr(vm, *ptep)) + pte_index(vm, vaddr) * 8; + break; + default: + TEST_FAIL("Got %u page table levels, expected 3 or 4", vm->pgtable_levels); + } + + prot_bits = _PAGE_PRESENT | __READABLE | __WRITEABLE | _CACHE_CC; + prot_bits |= _PAGE_USER; + *ptep = paddr | prot_bits; +} + +static void pte_dump(FILE *stream, struct kvm_vm *vm, uint8_t indent, uint64_t page, int level) +{ +#ifdef DEBUG + static const char * const type[] = { "", "pud", "pmd", "pte" }; + uint64_t pte, *ptep; + + if (level == 4) + return; + + for (pte = page; pte < page + ptrs_per_pte(vm) * 8; pte += 8) { + ptep = addr_gpa2hva(vm, pte); + if (!*ptep) + continue; + fprintf(stream, "%*s%s: %lx: %lx at %p\n", + indent, "", type[level], pte, *ptep, ptep); + pte_dump(stream, vm, indent + 1, pte_addr(vm, *ptep), level + 1); + } +#endif +} + +void virt_arch_dump(FILE *stream, struct kvm_vm *vm, uint8_t indent) +{ + int level; + uint64_t pgd, *ptep; + + level = 4 - (vm->pgtable_levels - 1); + if (!vm->pgd_created) + return; + + for (pgd = vm->pgd; pgd < vm->pgd + ptrs_per_pgd(vm) * 8; pgd += 8) { + ptep = addr_gpa2hva(vm, pgd); + if (!*ptep) + continue; + fprintf(stream, "%*spgd: %lx: %lx at %p\n", indent, "", pgd, *ptep, ptep); + pte_dump(stream, vm, indent + 1, pte_addr(vm, *ptep), level); + } +} + +void vcpu_arch_dump(FILE *stream, struct kvm_vcpu *vcpu, uint8_t indent) +{ +} + +void assert_on_unhandled_exception(struct kvm_vcpu *vcpu) +{ +} + +void vcpu_args_set(struct kvm_vcpu *vcpu, unsigned int num, ...) +{ + va_list ap; + struct kvm_regs regs; + int i; + + TEST_ASSERT(num >= 1 && num <= 8, "Unsupported number of args,\n" + "num: %u\n", num); + + vcpu_regs_get(vcpu, ®s); + va_start(ap, num); + for (i = 0; i < num; i++) + regs.gpr[i + 4] = va_arg(ap, uint64_t); + va_end(ap); + vcpu_regs_set(vcpu, ®s); +} + +static void loongarch_get_csr(struct kvm_vcpu *vcpu, uint64_t id, void *addr) +{ + uint64_t csrid; + + csrid = KVM_REG_LOONGARCH_CSR | KVM_REG_SIZE_U64 | 8 * id; + vcpu_get_reg(vcpu, csrid, addr); +} + +static void loongarch_set_csr(struct kvm_vcpu *vcpu, uint64_t id, uint64_t val) +{ + uint64_t csrid; + + csrid = KVM_REG_LOONGARCH_CSR | KVM_REG_SIZE_U64 | 8 * id; + vcpu_set_reg(vcpu, csrid, val); +} + +extern void handle_tlb_refill(void); +extern void handle_exception(void); + +static void loongarch_vcpu_setup(struct kvm_vcpu *vcpu) +{ + unsigned long val; + int width; + struct kvm_vm *vm = vcpu->vm; + + switch (vm->mode) { + case VM_MODE_P48V48_16K: + case VM_MODE_P40V48_16K: + case VM_MODE_P36V48_16K: + case VM_MODE_P36V47_16K: + break; + + default: + TEST_FAIL("Unknown guest mode, mode: 0x%x", vm->mode); + } + + /* user mode and page enable mode */ + val = PLV_USER | CSR_CRMD_PG; + loongarch_set_csr(vcpu, LOONGARCH_CSR_CRMD, val); + loongarch_set_csr(vcpu, LOONGARCH_CSR_PRMD, val); + loongarch_set_csr(vcpu, LOONGARCH_CSR_EUEN, 1); + loongarch_set_csr(vcpu, LOONGARCH_CSR_ECFG, 0); + loongarch_set_csr(vcpu, LOONGARCH_CSR_TCFG, 0); + loongarch_set_csr(vcpu, LOONGARCH_CSR_ASID, 1); + + width = vm->page_shift - 3; + val = 0; + switch (vm->pgtable_levels) { + case 4: + /* pud page shift and width */ + val = (vm->page_shift + width * 2) << 20 | (width << 25); + /* fall throuth */ + case 3: + /* pmd page shift and width */ + val |= (vm->page_shift + width) << 10 | (width << 15); + /* pte page shift and width */ + val |= vm->page_shift | width << 5; + break; + default: + TEST_FAIL("Got %u page table levels, expected 3 or 4", vm->pgtable_levels); + } + loongarch_set_csr(vcpu, LOONGARCH_CSR_PWCTL0, val); + + /* pgd page shift and width */ + val = (vm->page_shift + width * (vm->pgtable_levels - 1)) | width << 6; + loongarch_set_csr(vcpu, LOONGARCH_CSR_PWCTL1, val); + + loongarch_set_csr(vcpu, LOONGARCH_CSR_PGDL, vm->pgd); + + /* + * refill exception runs on real mode, entry address should + * be physical address + */ + val = addr_gva2gpa(vm, (unsigned long)handle_tlb_refill); + loongarch_set_csr(vcpu, LOONGARCH_CSR_TLBRENTRY, val); + + /* + * general exception runs on page-enabled mode, entry address should + * be virtual address + */ + val = (unsigned long)handle_exception; + loongarch_set_csr(vcpu, LOONGARCH_CSR_EENTRY, val); + + loongarch_get_csr(vcpu, LOONGARCH_CSR_TLBIDX, &val); + val &= ~CSR_TLBIDX_SIZEM; + val |= PS_DEFAULT_SIZE << CSR_TLBIDX_SIZE; + loongarch_set_csr(vcpu, LOONGARCH_CSR_TLBIDX, val); + + loongarch_set_csr(vcpu, LOONGARCH_CSR_STLBPGSIZE, PS_DEFAULT_SIZE); + + loongarch_get_csr(vcpu, LOONGARCH_CSR_TLBREHI, &val); + val &= ~CSR_TLBREHI_PS; + val |= PS_DEFAULT_SIZE << CSR_TLBREHI_PS_SHIFT; + loongarch_set_csr(vcpu, LOONGARCH_CSR_TLBREHI, val); + + loongarch_set_csr(vcpu, LOONGARCH_CSR_CPUID, vcpu->id); + loongarch_set_csr(vcpu, LOONGARCH_CSR_TMID, vcpu->id); +} + +struct kvm_vcpu *vm_arch_vcpu_add(struct kvm_vm *vm, uint32_t vcpu_id, + void *guest_code) +{ + size_t stack_size; + uint64_t stack_vaddr; + struct kvm_regs regs; + struct kvm_vcpu *vcpu; + + vcpu = __vm_vcpu_add(vm, vcpu_id); + stack_size = vm->page_size; + stack_vaddr = __vm_vaddr_alloc(vm, stack_size, + DEFAULT_GUEST_STACK_VADDR_MIN, + MEM_REGION_DATA); + + loongarch_vcpu_setup(vcpu); + /* Setup guest general purpose registers */ + vcpu_regs_get(vcpu, ®s); + regs.gpr[3] = stack_vaddr + stack_size - 8; + regs.pc = (uint64_t)guest_code; + vcpu_regs_set(vcpu, ®s); + + return vcpu; +} From patchwork Mon Aug 7 06:51:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhaotianrui X-Patchwork-Id: 131707 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp1274583vqr; Mon, 7 Aug 2023 00:14:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFHj+MUrCm4FwV6JMj2pYrmFhRxO4i6iDkIyeZNRP7wcP4NkgOIdFNqRX3Mwz7m73aconUs X-Received: by 2002:a17:90b:3a8f:b0:262:f798:b60d with SMTP id om15-20020a17090b3a8f00b00262f798b60dmr6274923pjb.6.1691392453801; Mon, 07 Aug 2023 00:14:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691392453; cv=none; d=google.com; s=arc-20160816; b=zKeIqqQ8sCc3mxr6xd8sEhjiQUFQ4g0XhJvo8KlSJnWnCO9qec/PM2IPdx/GeC0+ka Pji/DBuaCob9H7dOnN4mTxZ29HrREGaunbRF7FVouhcPxK4vDRsCHXfQYQKYEr6mmctl /0+FMQ0N9uvqlDMNRJCLRh6hDEwO5Zg4HoF9xjPdAewYkxZomxJjNeKW9U/wg8JkuCJc NjalqdJpXh/yYTR9WStwimIIcvAFxvW6EAu2H+blQ8xNOK5dqr/digkeM5Nglbq8EwBl My33jazkvb4xarfxhn6V0u35/mQtrhTgQjFji5hJzeegzY0LXL0QUbWWBN1jajpDxM73 crVw== 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; bh=vdR8KVto+ZVhAXAaFq0Y4FBz/3rDyrUBsszrws7YbEs=; fh=gsUmtxbMqK36mL5NFoC4xZ5sX9WhDudI+8elbmlEVgg=; b=HeJBSaalDr7lThrEloDj/lvfe1gIajgp9Oy2SM/QdzrnKKkiz8FGx+uvVsj6t5cABo 7sdOiPLpgcmsC6PofdNbzGz1Lib9ABVix+yb4tpy7Imfhx8P2gmokFdDkPlIAXW4vXti xxdVOVbVAMRrmbYP/MMaozxJoOCQTNjPFPt9b7W8SVaEsQIpXtpibxxreRVhS0fY5uRr qg3Oe9zuoJr6JHtD5TQsnvTaz8mDJSvkS21LUPWglnTr79V3EG07kGK06kMI59yWberG HBGJ8pVLBz53NZBr3twckEr5+XcADbM5DCNDQrQnjpsaEGRwhlQjzBSeTPsy0xl5J8dw CDew== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mh5-20020a17090b4ac500b00263fc986e28si9052525pjb.24.2023.08.07.00.13.59; Mon, 07 Aug 2023 00:14: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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229998AbjHGGwD (ORCPT + 99 others); Mon, 7 Aug 2023 02:52:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231328AbjHGGvs (ORCPT ); Mon, 7 Aug 2023 02:51:48 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8138F198D; Sun, 6 Aug 2023 23:51:42 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8AxCPJ8lNBk9dwRAA--.40000S3; Mon, 07 Aug 2023 14:51:40 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxJ8x5lNBkwspMAA--.23544S5; Mon, 07 Aug 2023 14:51:39 +0800 (CST) From: Tianrui Zhao To: Shuah Khan , Paolo Bonzini , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Sean Christopherson Cc: Vishal Annapurve , Huacai Chen , WANG Xuerui , loongarch@lists.linux.dev, Peter Xu , Vipin Sharma , maobibo@loongson.cn, zhaotianrui@loongson.cn Subject: [PATCH v2 3/4] KVM: selftests: Add ucall test support for LoongArch Date: Mon, 7 Aug 2023 14:51:36 +0800 Message-Id: <20230807065137.3408970-4-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230807065137.3408970-1-zhaotianrui@loongson.cn> References: <20230807065137.3408970-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8DxJ8x5lNBkwspMAA--.23544S5 X-CM-SenderInfo: p2kd03xldq233l6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS 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: INBOX X-GMAIL-THRID: 1773553533986550451 X-GMAIL-MSGID: 1773553533986550451 Add ucall test support for LoongArch. A ucall is a "hypercall to userspace". Based-on: <20230803022138.2736430-1-zhaotianrui@loongson.cn> Signed-off-by: Tianrui Zhao --- .../selftests/kvm/lib/loongarch/ucall.c | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 tools/testing/selftests/kvm/lib/loongarch/ucall.c diff --git a/tools/testing/selftests/kvm/lib/loongarch/ucall.c b/tools/testing/selftests/kvm/lib/loongarch/ucall.c new file mode 100644 index 000000000000..72868ddec313 --- /dev/null +++ b/tools/testing/selftests/kvm/lib/loongarch/ucall.c @@ -0,0 +1,43 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * ucall support. A ucall is a "hypercall to userspace". + * + */ +#include "kvm_util.h" + +/* + * ucall_exit_mmio_addr holds per-VM values (global data is duplicated by each + * VM), it must not be accessed from host code. + */ +static vm_vaddr_t *ucall_exit_mmio_addr; + +void ucall_arch_init(struct kvm_vm *vm, vm_paddr_t mmio_gpa) +{ + vm_vaddr_t mmio_gva = vm_vaddr_unused_gap(vm, vm->page_size, KVM_UTIL_MIN_VADDR); + + virt_map(vm, mmio_gva, mmio_gpa, 1); + + vm->ucall_mmio_addr = mmio_gpa; + + write_guest_global(vm, ucall_exit_mmio_addr, (vm_vaddr_t *)mmio_gva); +} + +void ucall_arch_do_ucall(vm_vaddr_t uc) +{ + WRITE_ONCE(*ucall_exit_mmio_addr, uc); +} + +void *ucall_arch_get_ucall(struct kvm_vcpu *vcpu) +{ + struct kvm_run *run = vcpu->run; + + if (run->exit_reason == KVM_EXIT_MMIO && + run->mmio.phys_addr == vcpu->vm->ucall_mmio_addr) { + TEST_ASSERT(run->mmio.is_write && run->mmio.len == sizeof(uint64_t), + "Unexpected ucall exit mmio address access"); + + return (void *)(*((uint64_t *)run->mmio.data)); + } + + return NULL; +} From patchwork Mon Aug 7 06:51:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhaotianrui X-Patchwork-Id: 131709 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp1275420vqr; Mon, 7 Aug 2023 00:16:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGVmzLHz0fqTMgUFh4g6ttoGei1RBXb/Ks/ubJ8yE++mNFw97RR3a4UfdYZ4A6AL0IQLeLt X-Received: by 2002:aa7:dc07:0:b0:51b:d567:cfed with SMTP id b7-20020aa7dc07000000b0051bd567cfedmr7212179edu.5.1691392605519; Mon, 07 Aug 2023 00:16:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691392605; cv=none; d=google.com; s=arc-20160816; b=jUecofylWKjBLNSIMRl4cA/rZwM5qMeNxRC/auGU56pMsWEg+8e4EfgONkHYDPAHvn TBjTB69F72NXoJf4Ez+Zu+G7g1tuqnfZsPO/RnkYEHRCo64WLgcaGjWXbbXxDyJbZuUX 86O3YumUP0l8kR2yLAe+Kup3AiNja3JxMwnsYoa37MyBysTCvFWyfwkBe2WhCFAn4wA9 OZ5bq2m7QjXuJ7WdXAptAXvSyjRIMtQ2p2bhktaHiyDpt0mbyL8x9J4uZugfj5CEePBF S8xVA1siHFW4j3vildAVVmO0nvByFdkqOjkntXIlNkFgNBiVcQThx6Hcv91gLzecUmTq +bbA== 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; bh=6lv1TwVZa1dIlxe8j3wrPkNoQnxNiTKa4kdBuS60Djg=; fh=gsUmtxbMqK36mL5NFoC4xZ5sX9WhDudI+8elbmlEVgg=; b=jwHYlrD2sDw8xfWIjoS/YFfUcqT/9SGx0XG1tK602t2Goq/Gd8shg7K6jgNf5r1Y2D x/h0IDLcShEPns4jgQ2EPLVIODmuaOKmmkAc37Ij7v4aVnPnHIfCfD1wvfVMsPa3zjoY sSL0/pcz3argpIzRKD6oSKsIvBjai+t5PK9+iNQB4aCnmUvxrxTSpVnsdmtlx6xdfEaZ /hTtGIQ/EGIVrG8MDUuNrI9RCIGDAJXJmmLlHfv1WWb9iHSFnJPr0FPZnbM0pYOMBN+c 8sw2O3vKNXjSgW5iTDPvXj+UzYUN9NTvMQ1DGVqmSbDgt1L/9kj69joLLz6ceARYwVXS pWQQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dy17-20020a05640231f100b005224c7ad5afsi26093edb.99.2023.08.07.00.16.20; Mon, 07 Aug 2023 00:16:45 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231417AbjHGGwI (ORCPT + 99 others); Mon, 7 Aug 2023 02:52:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231326AbjHGGvt (ORCPT ); Mon, 7 Aug 2023 02:51:49 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B673E199C; Sun, 6 Aug 2023 23:51:42 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8AxZ+h9lNBk+9wRAA--.4219S3; Mon, 07 Aug 2023 14:51:41 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxJ8x5lNBkwspMAA--.23544S6; Mon, 07 Aug 2023 14:51:39 +0800 (CST) From: Tianrui Zhao To: Shuah Khan , Paolo Bonzini , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Sean Christopherson Cc: Vishal Annapurve , Huacai Chen , WANG Xuerui , loongarch@lists.linux.dev, Peter Xu , Vipin Sharma , maobibo@loongson.cn, zhaotianrui@loongson.cn Subject: [PATCH v2 4/4] KVM: selftests: Add test cases supported by LoongArch into makefile Date: Mon, 7 Aug 2023 14:51:37 +0800 Message-Id: <20230807065137.3408970-5-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230807065137.3408970-1-zhaotianrui@loongson.cn> References: <20230807065137.3408970-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8DxJ8x5lNBkwspMAA--.23544S6 X-CM-SenderInfo: p2kd03xldq233l6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS 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: INBOX X-GMAIL-THRID: 1773553692608263188 X-GMAIL-MSGID: 1773553692608263188 Add test cases supported by LoongArch into makefile. LoongArch supports some KVM common tests, such as: kvm_create_max_vcpus demand_paging_test kvm_page_table_test set_memory_region_test memslot_modification_stress_test memslot_perf_test kvm_binary_stats_test And some test cases are not supported by LoongArch. for example, we do not support the rseq_test, as the glibc do not support it. Based-on: <20230803022138.2736430-1-zhaotianrui@loongson.cn> Signed-off-by: Tianrui Zhao --- tools/testing/selftests/kvm/Makefile | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile index c692cc86e7da..96bf53565a32 100644 --- a/tools/testing/selftests/kvm/Makefile +++ b/tools/testing/selftests/kvm/Makefile @@ -55,6 +55,10 @@ LIBKVM_s390x += lib/s390x/ucall.c LIBKVM_riscv += lib/riscv/processor.c LIBKVM_riscv += lib/riscv/ucall.c +LIBKVM_loongarch += lib/loongarch/processor.c +LIBKVM_loongarch += lib/loongarch/ucall.c +LIBKVM_loongarch += lib/loongarch/exception.S + # Non-compiled test targets TEST_PROGS_x86_64 += x86_64/nx_huge_pages_test.sh @@ -181,6 +185,14 @@ TEST_GEN_PROGS_riscv += kvm_page_table_test TEST_GEN_PROGS_riscv += set_memory_region_test TEST_GEN_PROGS_riscv += kvm_binary_stats_test +TEST_GEN_PROGS_loongarch += kvm_create_max_vcpus +TEST_GEN_PROGS_loongarch += demand_paging_test +TEST_GEN_PROGS_loongarch += kvm_page_table_test +TEST_GEN_PROGS_loongarch += set_memory_region_test +TEST_GEN_PROGS_loongarch += memslot_modification_stress_test +TEST_GEN_PROGS_loongarch += memslot_perf_test +TEST_GEN_PROGS_loongarch += kvm_binary_stats_test + TEST_PROGS += $(TEST_PROGS_$(ARCH_DIR)) TEST_GEN_PROGS += $(TEST_GEN_PROGS_$(ARCH_DIR)) TEST_GEN_PROGS_EXTENDED += $(TEST_GEN_PROGS_EXTENDED_$(ARCH_DIR))